xref: /aosp_15_r20/build/soong/filesystem/android_device.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker// Copyright (C) 2024 The Android Open Source Project
2*333d2b36SAndroid Build Coastguard Worker//
3*333d2b36SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*333d2b36SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*333d2b36SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*333d2b36SAndroid Build Coastguard Worker//
7*333d2b36SAndroid Build Coastguard Worker//     http://www.apache.org/licenses/LICENSE-2.0
8*333d2b36SAndroid Build Coastguard Worker//
9*333d2b36SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*333d2b36SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*333d2b36SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*333d2b36SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*333d2b36SAndroid Build Coastguard Worker// limitations under the License.
14*333d2b36SAndroid Build Coastguard Worker
15*333d2b36SAndroid Build Coastguard Workerpackage filesystem
16*333d2b36SAndroid Build Coastguard Worker
17*333d2b36SAndroid Build Coastguard Workerimport (
18*333d2b36SAndroid Build Coastguard Worker	"android/soong/android"
19*333d2b36SAndroid Build Coastguard Worker
20*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint"
21*333d2b36SAndroid Build Coastguard Worker	"github.com/google/blueprint/proptools"
22*333d2b36SAndroid Build Coastguard Worker)
23*333d2b36SAndroid Build Coastguard Worker
24*333d2b36SAndroid Build Coastguard Workertype PartitionNameProperties struct {
25*333d2b36SAndroid Build Coastguard Worker	// Name of the Boot_partition_name partition filesystem module
26*333d2b36SAndroid Build Coastguard Worker	Boot_partition_name *string
27*333d2b36SAndroid Build Coastguard Worker	// Name of the System partition filesystem module
28*333d2b36SAndroid Build Coastguard Worker	System_partition_name *string
29*333d2b36SAndroid Build Coastguard Worker	// Name of the System_ext partition filesystem module
30*333d2b36SAndroid Build Coastguard Worker	System_ext_partition_name *string
31*333d2b36SAndroid Build Coastguard Worker	// Name of the Product partition filesystem module
32*333d2b36SAndroid Build Coastguard Worker	Product_partition_name *string
33*333d2b36SAndroid Build Coastguard Worker	// Name of the Vendor partition filesystem module
34*333d2b36SAndroid Build Coastguard Worker	Vendor_partition_name *string
35*333d2b36SAndroid Build Coastguard Worker	// Name of the Odm partition filesystem module
36*333d2b36SAndroid Build Coastguard Worker	Odm_partition_name *string
37*333d2b36SAndroid Build Coastguard Worker	// The vbmeta partition and its "chained" partitions
38*333d2b36SAndroid Build Coastguard Worker	Vbmeta_partitions []string
39*333d2b36SAndroid Build Coastguard Worker	// Name of the Userdata partition filesystem module
40*333d2b36SAndroid Build Coastguard Worker	Userdata_partition_name *string
41*333d2b36SAndroid Build Coastguard Worker}
42*333d2b36SAndroid Build Coastguard Worker
43*333d2b36SAndroid Build Coastguard Workertype androidDevice struct {
44*333d2b36SAndroid Build Coastguard Worker	android.ModuleBase
45*333d2b36SAndroid Build Coastguard Worker
46*333d2b36SAndroid Build Coastguard Worker	partitionProps PartitionNameProperties
47*333d2b36SAndroid Build Coastguard Worker}
48*333d2b36SAndroid Build Coastguard Worker
49*333d2b36SAndroid Build Coastguard Workerfunc AndroidDeviceFactory() android.Module {
50*333d2b36SAndroid Build Coastguard Worker	module := &androidDevice{}
51*333d2b36SAndroid Build Coastguard Worker	module.AddProperties(&module.partitionProps)
52*333d2b36SAndroid Build Coastguard Worker	android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
53*333d2b36SAndroid Build Coastguard Worker	return module
54*333d2b36SAndroid Build Coastguard Worker}
55*333d2b36SAndroid Build Coastguard Worker
56*333d2b36SAndroid Build Coastguard Workertype partitionDepTagType struct {
57*333d2b36SAndroid Build Coastguard Worker	blueprint.BaseDependencyTag
58*333d2b36SAndroid Build Coastguard Worker}
59*333d2b36SAndroid Build Coastguard Worker
60*333d2b36SAndroid Build Coastguard Workervar filesystemDepTag partitionDepTagType
61*333d2b36SAndroid Build Coastguard Worker
62*333d2b36SAndroid Build Coastguard Workerfunc (a *androidDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
63*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined := func(dep *string) {
64*333d2b36SAndroid Build Coastguard Worker		if dep != nil {
65*333d2b36SAndroid Build Coastguard Worker			ctx.AddDependency(ctx.Module(), filesystemDepTag, proptools.String(dep))
66*333d2b36SAndroid Build Coastguard Worker		}
67*333d2b36SAndroid Build Coastguard Worker	}
68*333d2b36SAndroid Build Coastguard Worker
69*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined(a.partitionProps.Boot_partition_name)
70*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined(a.partitionProps.System_partition_name)
71*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined(a.partitionProps.System_ext_partition_name)
72*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined(a.partitionProps.Product_partition_name)
73*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined(a.partitionProps.Vendor_partition_name)
74*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined(a.partitionProps.Odm_partition_name)
75*333d2b36SAndroid Build Coastguard Worker	addDependencyIfDefined(a.partitionProps.Userdata_partition_name)
76*333d2b36SAndroid Build Coastguard Worker	for _, vbmetaPartition := range a.partitionProps.Vbmeta_partitions {
77*333d2b36SAndroid Build Coastguard Worker		ctx.AddDependency(ctx.Module(), filesystemDepTag, vbmetaPartition)
78*333d2b36SAndroid Build Coastguard Worker	}
79*333d2b36SAndroid Build Coastguard Worker}
80*333d2b36SAndroid Build Coastguard Worker
81*333d2b36SAndroid Build Coastguard Workerfunc (a *androidDevice) GenerateAndroidBuildActions(ctx android.ModuleContext) {
82*333d2b36SAndroid Build Coastguard Worker
83*333d2b36SAndroid Build Coastguard Worker}
84