From f4889dbc886e145f74e5ac0475660a037520ee96 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 23 Jul 2024 13:29:48 +0900 Subject: [PATCH 1/5] Make the defaults property configurable This allows using select statements with it. Bug: 354824866 Test: m Change-Id: I673df0869a68c2e79b19c577d0ae1ff2249388db --- android/defaults.go | 9 +++++---- android/module_test.go | 2 -- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/android/defaults.go b/android/defaults.go index ff7900232..ba26e00c3 100644 --- a/android/defaults.go +++ b/android/defaults.go @@ -28,7 +28,7 @@ type defaultsDependencyTag struct { var DefaultsDepTag defaultsDependencyTag type defaultsProperties struct { - Defaults []string + Defaults proptools.Configurable[[]string] } type DefaultableModuleBase struct { @@ -278,13 +278,14 @@ func RegisterDefaultsPreArchMutators(ctx RegisterMutatorsContext) { func defaultsDepsMutator(ctx BottomUpMutatorContext) { if defaultable, ok := ctx.Module().(Defaultable); ok { - ctx.AddDependency(ctx.Module(), DefaultsDepTag, defaultable.defaults().Defaults...) + ctx.AddDependency(ctx.Module(), DefaultsDepTag, defaultable.defaults().Defaults.GetOrDefault(ctx.Module().ConfigurableEvaluator(ctx), nil)...) } } func defaultsMutator(ctx TopDownMutatorContext) { if defaultable, ok := ctx.Module().(Defaultable); ok { - if len(defaultable.defaults().Defaults) > 0 { + defaults := defaultable.defaults().Defaults.GetOrDefault(ctx.Module().ConfigurableEvaluator(ctx), nil) + if len(defaults) > 0 { var defaultsList []Defaults seen := make(map[Defaults]bool) @@ -294,7 +295,7 @@ func defaultsMutator(ctx TopDownMutatorContext) { if !seen[defaults] { seen[defaults] = true defaultsList = append(defaultsList, defaults) - return len(defaults.defaults().Defaults) > 0 + return len(defaults.defaults().Defaults.GetOrDefault(ctx.Module().ConfigurableEvaluator(ctx), nil)) > 0 } } else { ctx.PropertyErrorf("defaults", "module %s is not an defaults module", diff --git a/android/module_test.go b/android/module_test.go index 922ea21fe..829c07987 100644 --- a/android/module_test.go +++ b/android/module_test.go @@ -722,7 +722,6 @@ test { propInfo{Name: "Arch.X86_64.A", Type: "string", Value: "x86_64 a"}, propInfo{Name: "B", Type: "bool", Value: "true"}, propInfo{Name: "C", Type: "string slice", Values: []string{"default_c", "c"}}, - propInfo{Name: "Defaults", Type: "string slice", Values: []string{"foo_defaults"}}, propInfo{Name: "Embedded_prop", Type: "string", Value: "a"}, propInfo{Name: "Name", Type: "string", Value: "foo"}, propInfo{Name: "Nested.E", Type: "string", Value: "nested e"}, @@ -746,7 +745,6 @@ test { foo := result.ModuleForTests("foo", "").Module().base() AssertDeepEquals(t, "foo ", tc.expectedProps, foo.propertiesWithValues()) - }) } } From f223702f3fb924b11f0692cf510494cefb1c3946 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 23 Jul 2024 13:36:31 +0900 Subject: [PATCH 2/5] Make the vintf_fragments property configurable This allows using select statements with it. Bug: 354824866 Test: m Change-Id: I9080c14b8342868d842670c65386582552b32d46 --- android/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/module.go b/android/module.go index 37e26f9b8..39c257c2a 100644 --- a/android/module.go +++ b/android/module.go @@ -389,7 +389,7 @@ type commonProperties struct { Init_rc []string `android:"arch_variant,path"` // VINTF manifest fragments to be installed if this module is installed - Vintf_fragments []string `android:"path"` + Vintf_fragments proptools.Configurable[[]string] `android:"path"` // names of other modules to install if this module is installed Required proptools.Configurable[[]string] `android:"arch_variant"` @@ -1853,7 +1853,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) } } - m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments) + m.vintfFragmentsPaths = PathsForModuleSrc(ctx, m.commonProperties.Vintf_fragments.GetOrDefault(m.ConfigurableEvaluator(ctx), nil)) vintfDir := PathForModuleInstall(ctx, "etc", "vintf", "manifest") for _, src := range m.vintfFragmentsPaths { installedVintfFragment := vintfDir.Join(ctx, src.Base()) From b114234f6b00ba00ad7cac5f172a2e54f36a8ca6 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 23 Jul 2024 13:39:54 +0900 Subject: [PATCH 3/5] Make some apex properties configurable This allows using select statements with these. * androidManifest * canned_fs_config * systemserverclasspath_fragments Bug: 354824866 Test: m Change-Id: I4c2182944ec14d99332f437c39a19ba0dc6b7731 --- apex/apex.go | 13 ++++++++----- apex/builder.go | 10 ++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index c1a9d7430..61bd8d02d 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -86,7 +86,7 @@ type apexBundleProperties struct { // AndroidManifest.xml file used for the zip container of this APEX bundle. If unspecified, // a default one is automatically generated. - AndroidManifest *string `android:"path"` + AndroidManifest proptools.Configurable[string] `android:"path,replace_instead_of_append"` // Determines the file contexts file for setting the security contexts to files in this APEX // bundle. For platform APEXes, this should points to a file under /system/sepolicy Default: @@ -104,7 +104,7 @@ type apexBundleProperties struct { // path_or_glob is a path or glob pattern for a file or set of files, // uid/gid are numerial values of user ID and group ID, mode is octal value // for the file mode, and cap is hexadecimal value for the capability. - Canned_fs_config *string `android:"path"` + Canned_fs_config proptools.Configurable[string] `android:"path,replace_instead_of_append"` ApexNativeDependencies @@ -117,7 +117,8 @@ type apexBundleProperties struct { Bootclasspath_fragments []string // List of systemserverclasspath fragments that are embedded inside this APEX bundle. - Systemserverclasspath_fragments []string + Systemserverclasspath_fragments proptools.Configurable[[]string] + ResolvedSystemserverclasspathFragments []string `blueprint:"mutated"` // List of java libraries that are embedded inside this APEX bundle. Java_libs []string @@ -840,11 +841,13 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { } } + a.properties.ResolvedSystemserverclasspathFragments = a.properties.Systemserverclasspath_fragments.GetOrDefault(a.ConfigurableEvaluator(ctx), nil) + // Common-arch dependencies come next commonVariation := ctx.Config().AndroidCommonTarget.Variations() ctx.AddFarVariationDependencies(commonVariation, rroTag, a.properties.Rros...) ctx.AddFarVariationDependencies(commonVariation, bcpfTag, a.properties.Bootclasspath_fragments...) - ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.Systemserverclasspath_fragments...) + ctx.AddFarVariationDependencies(commonVariation, sscpfTag, a.properties.ResolvedSystemserverclasspathFragments...) ctx.AddFarVariationDependencies(commonVariation, javaLibTag, a.properties.Java_libs...) ctx.AddFarVariationDependencies(commonVariation, fsTag, a.properties.Filesystems...) ctx.AddFarVariationDependencies(commonVariation, compatConfigTag, a.properties.Compat_configs...) @@ -2806,7 +2809,7 @@ func isStaticExecutableAllowed(apex string, exec string) bool { func (a *apexBundle) IDEInfo(dpInfo *android.IdeInfo) { dpInfo.Deps = append(dpInfo.Deps, a.properties.Java_libs...) dpInfo.Deps = append(dpInfo.Deps, a.properties.Bootclasspath_fragments...) - dpInfo.Deps = append(dpInfo.Deps, a.properties.Systemserverclasspath_fragments...) + dpInfo.Deps = append(dpInfo.Deps, a.properties.ResolvedSystemserverclasspathFragments...) } var ( diff --git a/apex/builder.go b/apex/builder.go index 763ce4d20..6f645ab04 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -704,8 +704,9 @@ func (a *apexBundle) buildApex(ctx android.ModuleContext) { optFlags = append(optFlags, "--override_apk_package_name "+manifestPackageName) } - if a.properties.AndroidManifest != nil { - androidManifestFile := android.PathForModuleSrc(ctx, proptools.String(a.properties.AndroidManifest)) + androidManifest := a.properties.AndroidManifest.GetOrDefault(a.ConfigurableEvaluator(ctx), "") + if androidManifest != "" { + androidManifestFile := android.PathForModuleSrc(ctx, androidManifest) if a.testApex { androidManifestFile = markManifestTestOnly(ctx, androidManifestFile) @@ -1195,8 +1196,9 @@ func (a *apexBundle) buildCannedFsConfig(ctx android.ModuleContext, defaultReadO } // Custom fs_config is "appended" to the last so that entries from the file are preferred // over default ones set above. - if a.properties.Canned_fs_config != nil { - cmd.Text("cat").Input(android.PathForModuleSrc(ctx, *a.properties.Canned_fs_config)) + customFsConfig := a.properties.Canned_fs_config.GetOrDefault(a.ConfigurableEvaluator(ctx), "") + if customFsConfig != "" { + cmd.Text("cat").Input(android.PathForModuleSrc(ctx, customFsConfig)) } cmd.Text(")").FlagWithOutput("> ", cannedFsConfig) builder.Build("generateFsConfig", fmt.Sprintf("Generating canned fs config for %s", a.BaseModuleName())) From 2f73062d47d179d43a72fdb5b8e089786abb4fd9 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 23 Jul 2024 14:03:40 +0900 Subject: [PATCH 4/5] Make genrule's srcs property configurable This allows using select statements with it. Bug: 354824866 Test: m Change-Id: If1d71ac177618ad3eb628cdec57469886ee27c88 --- genrule/genrule.go | 8 +++++--- genrule/genrule_test.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/genrule/genrule.go b/genrule/genrule.go index 5b40768b4..08d857d05 100644 --- a/genrule/genrule.go +++ b/genrule/genrule.go @@ -139,7 +139,8 @@ type generatorProperties struct { Export_include_dirs []string // list of input files - Srcs []string `android:"path,arch_variant"` + Srcs proptools.Configurable[[]string] `android:"path,arch_variant"` + ResolvedSrcs []string `blueprint:"mutated"` // input files to exclude Exclude_srcs []string `android:"path,arch_variant"` @@ -382,7 +383,8 @@ func (g *Module) generateCommonBuildActions(ctx android.ModuleContext) { } return srcFiles } - srcFiles := addLabelsForInputs("srcs", g.properties.Srcs, g.properties.Exclude_srcs) + g.properties.ResolvedSrcs = g.properties.Srcs.GetOrDefault(g.ConfigurableEvaluator(ctx), nil) + srcFiles := addLabelsForInputs("srcs", g.properties.ResolvedSrcs, g.properties.Exclude_srcs) android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: srcFiles.Strings()}) var copyFrom android.Paths @@ -589,7 +591,7 @@ func (g *Module) setOutputFiles(ctx android.ModuleContext) { // Collect information for opening IDE project files in java/jdeps.go. func (g *Module) IDEInfo(dpInfo *android.IdeInfo) { dpInfo.Srcs = append(dpInfo.Srcs, g.Srcs().Strings()...) - for _, src := range g.properties.Srcs { + for _, src := range g.properties.ResolvedSrcs { if strings.HasPrefix(src, ":") { src = strings.Trim(src, ":") dpInfo.Deps = append(dpInfo.Deps, src) diff --git a/genrule/genrule_test.go b/genrule/genrule_test.go index fba9aec65..444aedb90 100644 --- a/genrule/genrule_test.go +++ b/genrule/genrule_test.go @@ -694,7 +694,7 @@ func TestGenruleDefaults(t *testing.T) { android.AssertStringEquals(t, "cmd", expectedCmd, gen.rawCommands[0]) expectedSrcs := []string{"in1"} - android.AssertDeepEquals(t, "srcs", expectedSrcs, gen.properties.Srcs) + android.AssertDeepEquals(t, "srcs", expectedSrcs, gen.properties.ResolvedSrcs) } func TestGenruleAllowMissingDependencies(t *testing.T) { From d23e0d3244e927c8fd6c2db9e18f6a31e1be54e6 Mon Sep 17 00:00:00 2001 From: Inseob Kim Date: Tue, 23 Jul 2024 16:12:33 +0900 Subject: [PATCH 5/5] Make more apex properties configurable This allows using select statements with these. * apps * binaries * prebuilts Bug: 354824866 Test: m --no-skip-soong-tests Change-Id: I8e28937d2fa6514b41bd189f56f9f584a60d2c80 --- apex/apex.go | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index 61bd8d02d..4c36458ea 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -222,7 +222,8 @@ type ApexNativeDependencies struct { Rust_dyn_libs []string // List of native executables that are embedded inside this APEX. - Binaries []string + Binaries proptools.Configurable[[]string] + ResolvedBinaries []string `blueprint:"mutated"` // List of native tests that are embedded inside this APEX. Tests []string @@ -231,7 +232,8 @@ type ApexNativeDependencies struct { Filesystems []string // List of prebuilt_etcs that are embedded inside this APEX bundle. - Prebuilts []string + Prebuilts proptools.Configurable[[]string] + ResolvedPrebuilts []string `blueprint:"mutated"` // List of native libraries to exclude from this APEX. Exclude_native_shared_libs []string @@ -256,14 +258,14 @@ type ApexNativeDependencies struct { } // Merge combines another ApexNativeDependencies into this one -func (a *ApexNativeDependencies) Merge(b ApexNativeDependencies) { +func (a *ApexNativeDependencies) Merge(ctx android.BaseMutatorContext, b ApexNativeDependencies) { a.Native_shared_libs = append(a.Native_shared_libs, b.Native_shared_libs...) a.Jni_libs = append(a.Jni_libs, b.Jni_libs...) a.Rust_dyn_libs = append(a.Rust_dyn_libs, b.Rust_dyn_libs...) - a.Binaries = append(a.Binaries, b.Binaries...) + a.ResolvedBinaries = append(a.ResolvedBinaries, b.Binaries.GetOrDefault(ctx.Module().ConfigurableEvaluator(ctx), nil)...) a.Tests = append(a.Tests, b.Tests...) a.Filesystems = append(a.Filesystems, b.Filesystems...) - a.Prebuilts = append(a.Prebuilts, b.Prebuilts...) + a.ResolvedPrebuilts = append(a.ResolvedPrebuilts, b.Prebuilts.GetOrDefault(ctx.Module().ConfigurableEvaluator(ctx), nil)...) a.Exclude_native_shared_libs = append(a.Exclude_native_shared_libs, b.Exclude_native_shared_libs...) a.Exclude_jni_libs = append(a.Exclude_jni_libs, b.Exclude_jni_libs...) @@ -339,10 +341,10 @@ type apexArchBundleProperties struct { // base apex. type overridableProperties struct { // List of APKs that are embedded inside this APEX. - Apps []string + Apps proptools.Configurable[[]string] // List of prebuilt files that are embedded inside this APEX bundle. - Prebuilts []string + Prebuilts proptools.Configurable[[]string] // List of BPF programs inside this APEX bundle. Bpfs []string @@ -716,7 +718,7 @@ func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeM // this module. This is required since arch variant of an APEX bundle is 'common' but it is // 'arm' or 'arm64' for native shared libs. ctx.AddFarVariationDependencies(binVariations, executableTag, - android.RemoveListFromList(nativeModules.Binaries, nativeModules.Exclude_binaries)...) + android.RemoveListFromList(nativeModules.ResolvedBinaries, nativeModules.Exclude_binaries)...) ctx.AddFarVariationDependencies(binVariations, testTag, android.RemoveListFromList(nativeModules.Tests, nativeModules.Exclude_tests)...) ctx.AddFarVariationDependencies(libVariations, jniLibTag, @@ -728,7 +730,7 @@ func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, nativeM ctx.AddFarVariationDependencies(target.Variations(), fsTag, android.RemoveListFromList(nativeModules.Filesystems, nativeModules.Exclude_filesystems)...) ctx.AddFarVariationDependencies(target.Variations(), prebuiltTag, - android.RemoveListFromList(nativeModules.Prebuilts, nativeModules.Exclude_prebuilts)...) + android.RemoveListFromList(nativeModules.ResolvedPrebuilts, nativeModules.Exclude_prebuilts)...) } func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) { @@ -783,20 +785,19 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { // Add native modules targeting both ABIs. When multilib.* is omitted for // native_shared_libs/jni_libs/tests, it implies multilib.both - deps.Merge(a.properties.Multilib.Both) - deps.Merge(ApexNativeDependencies{ + deps.Merge(ctx, a.properties.Multilib.Both) + deps.Merge(ctx, ApexNativeDependencies{ Native_shared_libs: a.properties.Native_shared_libs, Tests: a.properties.Tests, Jni_libs: a.properties.Jni_libs, - Binaries: nil, }) // Add native modules targeting the first ABI When multilib.* is omitted for // binaries, it implies multilib.first isPrimaryAbi := i == 0 if isPrimaryAbi { - deps.Merge(a.properties.Multilib.First) - deps.Merge(ApexNativeDependencies{ + deps.Merge(ctx, a.properties.Multilib.First) + deps.Merge(ctx, ApexNativeDependencies{ Native_shared_libs: nil, Tests: nil, Jni_libs: nil, @@ -807,27 +808,27 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { // Add native modules targeting either 32-bit or 64-bit ABI switch target.Arch.ArchType.Multilib { case "lib32": - deps.Merge(a.properties.Multilib.Lib32) - deps.Merge(a.properties.Multilib.Prefer32) + deps.Merge(ctx, a.properties.Multilib.Lib32) + deps.Merge(ctx, a.properties.Multilib.Prefer32) case "lib64": - deps.Merge(a.properties.Multilib.Lib64) + deps.Merge(ctx, a.properties.Multilib.Lib64) if !has32BitTarget { - deps.Merge(a.properties.Multilib.Prefer32) + deps.Merge(ctx, a.properties.Multilib.Prefer32) } } // Add native modules targeting a specific arch variant switch target.Arch.ArchType { case android.Arm: - deps.Merge(a.archProperties.Arch.Arm.ApexNativeDependencies) + deps.Merge(ctx, a.archProperties.Arch.Arm.ApexNativeDependencies) case android.Arm64: - deps.Merge(a.archProperties.Arch.Arm64.ApexNativeDependencies) + deps.Merge(ctx, a.archProperties.Arch.Arm64.ApexNativeDependencies) case android.Riscv64: - deps.Merge(a.archProperties.Arch.Riscv64.ApexNativeDependencies) + deps.Merge(ctx, a.archProperties.Arch.Riscv64.ApexNativeDependencies) case android.X86: - deps.Merge(a.archProperties.Arch.X86.ApexNativeDependencies) + deps.Merge(ctx, a.archProperties.Arch.X86.ApexNativeDependencies) case android.X86_64: - deps.Merge(a.archProperties.Arch.X86_64.ApexNativeDependencies) + deps.Merge(ctx, a.archProperties.Arch.X86_64.ApexNativeDependencies) default: panic(fmt.Errorf("unsupported arch %v\n", ctx.Arch().ArchType)) } @@ -860,9 +861,9 @@ func (a *apexBundle) OverridablePropertiesDepsMutator(ctx android.BottomUpMutato } commonVariation := ctx.Config().AndroidCommonTarget.Variations() - ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps...) + ctx.AddFarVariationDependencies(commonVariation, androidAppTag, a.overridableProperties.Apps.GetOrDefault(a.ConfigurableEvaluator(ctx), nil)...) ctx.AddFarVariationDependencies(commonVariation, bpfTag, a.overridableProperties.Bpfs...) - if prebuilts := a.overridableProperties.Prebuilts; len(prebuilts) > 0 { + if prebuilts := a.overridableProperties.Prebuilts.GetOrDefault(a.ConfigurableEvaluator(ctx), nil); len(prebuilts) > 0 { // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device) // regardless of the TARGET_PREFER_* setting. See b/144532908 arches := ctx.DeviceConfig().Arches() @@ -1495,7 +1496,6 @@ func (a *apexBundle) AddSanitizerDependencies(ctx android.BottomUpMutatorContext Native_shared_libs: []string{"libclang_rt.hwasan"}, Tests: nil, Jni_libs: nil, - Binaries: nil, }, target, imageVariation) break }