Set the appropriate deps property for the soong generated fs modules
This change:
- Adds a pre-deps bottom-up mutator that sets the appropriate deps
properties for the soong generate filesystem partition modules
- Makes `installInSysem` more genenric, so that it can be used for other
partitions
- Introduces `AppendDepsEntries` method in `android.PackagingBase` to
utilize it in the aforementioned mutator
- Modifies `fsDeps` from a 1D slice to a map (of partition to deps slice)
Test: m nothing --no-skip-soong-tests
Bug: 372771060
Change-Id: Ic251993d1d4c1caca544c5cebcaf29afd749da9e
diff --git a/fsgen/filesystem_creator.go b/fsgen/filesystem_creator.go
index ed0c390..8acc74c 100644
--- a/fsgen/filesystem_creator.go
+++ b/fsgen/filesystem_creator.go
@@ -43,36 +43,52 @@
func RegisterCollectFileSystemDepsMutators(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("fs_collect_deps", collectDepsMutator).MutatesGlobalState()
+ ctx.BottomUp("fs_set_deps", setDepsMutator)
}
var fsDepsMutex = sync.Mutex{}
var collectFsDepsOnceKey = android.NewOnceKey("CollectFsDeps")
var depCandidatesOnceKey = android.NewOnceKey("DepCandidates")
+// List of partitions that the filesystem_creator module currently generates the partition
+var soongGeneratedPartitions = []string{"system"}
+
+// Map of partition module name to its partition that may be generated by Soong.
+// Note that it is not guaranteed that all modules returned by this function are successfully
+// created.
+func getAllSoongGeneratedPartitionNames(config android.Config) map[string]string {
+ ret := map[string]string{}
+ for _, partition := range soongGeneratedPartitions {
+ ret[generatedModuleNameForPartition(config, partition)] = partition
+ }
+ return ret
+}
+
func collectDepsMutator(mctx android.BottomUpMutatorContext) {
// These additional deps are added according to the cuttlefish system image bp.
fsDeps := mctx.Config().Once(collectFsDepsOnceKey, func() interface{} {
- deps := []string{
- "android_vintf_manifest",
- "com.android.apex.cts.shim.v1_prebuilt",
- "dex_bootjars",
- "framework_compatibility_matrix.device.xml",
- "idc_data",
- "init.environ.rc-soong",
- "keychars_data",
- "keylayout_data",
- "libclang_rt.asan",
- "libcompiler_rt",
- "libdmabufheap",
- "libgsi",
- "llndk.libraries.txt",
- "logpersist.start",
- "preloaded-classes",
- "public.libraries.android.txt",
- "update_engine_sideload",
+ deps := map[string][]string{
+ "system": {
+ "com.android.apex.cts.shim.v1_prebuilt",
+ "dex_bootjars",
+ "framework_compatibility_matrix.device.xml",
+ "idc_data",
+ "init.environ.rc-soong",
+ "keychars_data",
+ "keylayout_data",
+ "libclang_rt.asan",
+ "libcompiler_rt",
+ "libdmabufheap",
+ "libgsi",
+ "llndk.libraries.txt",
+ "logpersist.start",
+ "preloaded-classes",
+ "public.libraries.android.txt",
+ "update_engine_sideload",
+ },
}
return &deps
- }).(*[]string)
+ }).(*map[string][]string)
depCandidates := mctx.Config().Once(depCandidatesOnceKey, func() interface{} {
partitionVars := mctx.Config().ProductVariables().PartitionVarsForSoongMigrationOnlyDoNotUse
@@ -82,10 +98,30 @@
m := mctx.Module()
if slices.Contains(*depCandidates, m.Name()) {
- if installInSystem(mctx, m) {
- fsDepsMutex.Lock()
- *fsDeps = append(*fsDeps, m.Name())
- fsDepsMutex.Unlock()
+ installPartition := getInstallPartition(m, mctx.DeviceConfig())
+ fsDepsMutex.Lock()
+ if _, ok := (*fsDeps)[installPartition]; !ok {
+ (*fsDeps)[installPartition] = make([]string, 0)
+ }
+ if m.Enabled(mctx) {
+ (*fsDeps)[installPartition] = append((*fsDeps)[installPartition], m.Name())
+ }
+ fsDepsMutex.Unlock()
+ }
+}
+
+type depsStruct struct {
+ Deps []string
+}
+
+func setDepsMutator(mctx android.BottomUpMutatorContext) {
+ fsDeps := mctx.Config().Get(collectFsDepsOnceKey).(*map[string][]string)
+ soongGeneratedPartitionMap := getAllSoongGeneratedPartitionNames(mctx.Config())
+ m := mctx.Module()
+ if partition, ok := soongGeneratedPartitionMap[m.Name()]; ok {
+ deps := (*fsDeps)[partition]
+ if err := proptools.AppendMatchingProperties(m.GetProperties(), &depsStruct{Deps: deps}, nil); err != nil {
+ mctx.ModuleErrorf(err.Error())
}
}
}
@@ -114,7 +150,7 @@
}
func (f *filesystemCreator) createInternalModules(ctx android.LoadHookContext) {
- for _, partitionType := range []string{"system"} {
+ for _, partitionType := range soongGeneratedPartitions {
if f.createPartition(ctx, partitionType) {
f.properties.Generated_partition_types = append(f.properties.Generated_partition_types, partitionType)
} else {
@@ -124,7 +160,7 @@
f.createDeviceModule(ctx)
}
-func (f *filesystemCreator) generatedModuleName(cfg android.Config, suffix string) string {
+func generatedModuleName(cfg android.Config, suffix string) string {
prefix := "soong"
if cfg.HasDeviceProduct() {
prefix = cfg.DeviceProduct()
@@ -132,21 +168,21 @@
return fmt.Sprintf("%s_generated_%s", prefix, suffix)
}
-func (f *filesystemCreator) generatedModuleNameForPartition(cfg android.Config, partitionType string) string {
- return f.generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType))
+func generatedModuleNameForPartition(cfg android.Config, partitionType string) string {
+ return generatedModuleName(cfg, fmt.Sprintf("%s_image", partitionType))
}
func (f *filesystemCreator) createDeviceModule(ctx android.LoadHookContext) {
baseProps := &struct {
Name *string
}{
- Name: proptools.StringPtr(f.generatedModuleName(ctx.Config(), "device")),
+ Name: proptools.StringPtr(generatedModuleName(ctx.Config(), "device")),
}
// Currently, only the system partition module is created.
partitionProps := &filesystem.PartitionNameProperties{}
if android.InList("system", f.properties.Generated_partition_types) {
- partitionProps.System_partition_name = proptools.StringPtr(f.generatedModuleNameForPartition(ctx.Config(), "system"))
+ partitionProps.System_partition_name = proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), "system"))
}
ctx.CreateModule(filesystem.AndroidDeviceFactory, baseProps, partitionProps)
@@ -158,7 +194,7 @@
baseProps := &struct {
Name *string
}{
- Name: proptools.StringPtr(f.generatedModuleNameForPartition(ctx.Config(), partitionType)),
+ Name: proptools.StringPtr(generatedModuleNameForPartition(ctx.Config(), partitionType)),
}
fsProps := &filesystem.FilesystemProperties{}
@@ -195,6 +231,8 @@
fsProps.Gen_aconfig_flags_pb = proptools.BoolPtr(true)
+ fsProps.Is_auto_generated = proptools.BoolPtr(true)
+
// Identical to that of the generic_system_image
fsProps.Fsverity.Inputs = []string{
"etc/boot-image.prof",
@@ -229,7 +267,7 @@
}
func (f *filesystemCreator) createDiffTest(ctx android.ModuleContext, partitionType string) android.Path {
- partitionModuleName := f.generatedModuleNameForPartition(ctx.Config(), partitionType)
+ partitionModuleName := generatedModuleNameForPartition(ctx.Config(), partitionType)
systemImage := ctx.GetDirectDepWithTag(partitionModuleName, generatedFilesystemDepTag)
filesystemInfo, ok := android.OtherModuleProvider(ctx, systemImage, filesystem.FilesystemProvider)
if !ok {
@@ -273,7 +311,7 @@
func (f *filesystemCreator) DepsMutator(ctx android.BottomUpMutatorContext) {
for _, partitionType := range f.properties.Generated_partition_types {
- ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, f.generatedModuleNameForPartition(ctx.Config(), partitionType))
+ ctx.AddDependency(ctx.Module(), generatedFilesystemDepTag, generatedModuleNameForPartition(ctx.Config(), partitionType))
}
}
@@ -298,11 +336,8 @@
ctx.Phony("soong_generated_filesystem_tests", diffTestFiles...)
}
-func installInSystem(ctx android.BottomUpMutatorContext, m android.Module) bool {
- return m.PartitionTag(ctx.DeviceConfig()) == "system" && !m.InstallInData() &&
- !m.InstallInTestcases() && !m.InstallInSanitizerDir() && !m.InstallInVendorRamdisk() &&
- !m.InstallInDebugRamdisk() && !m.InstallInRecovery() && !m.InstallInOdm() &&
- !m.InstallInVendor()
+func getInstallPartition(m android.Module, config android.DeviceConfig) string {
+ return m.PartitionTag(config)
}
// TODO: assemble baseProps and fsProps here
@@ -312,9 +347,9 @@
return ""
}
- deps := ctx.Config().Get(collectFsDepsOnceKey).(*[]string)
+ deps := ctx.Config().Get(collectFsDepsOnceKey).(*map[string][]string)
depProps := &android.PackagingProperties{
- Deps: android.NewSimpleConfigurable(android.SortedUniqueStrings(*deps)),
+ Deps: android.NewSimpleConfigurable(android.SortedUniqueStrings((*deps)[partitionType])),
}
result, err := proptools.RepackProperties([]interface{}{depProps})