From 5b91c24c1192b3e435894c5cb59c6f1b4d4f47f0 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Mon, 17 Jun 2024 12:32:40 -0700 Subject: [PATCH] Make required a configurable property So that users can use select statements with it. Fixes: 347605145 Bug: 342006386 Test: m nothing --no-skip-soong-tests Change-Id: Ica0ca6d1725b000b3748c0293e5a9f9b38ed87f9 --- android/androidmk.go | 3 ++- android/module.go | 14 +++++++------- android/module_context.go | 6 +++--- android/soongconfig/modules.go | 13 +++++++++---- android/testing.go | 4 ++++ apex/androidmk.go | 2 +- apex/apex.go | 7 ++++++- cc/cc.go | 4 ++-- java/java.go | 2 +- phony/phony.go | 2 +- snapshot/host_fake_snapshot.go | 4 ++-- snapshot/host_snapshot.go | 6 +++--- 12 files changed, 41 insertions(+), 26 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index 66f42f97c..9699ce5b8 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -499,6 +499,7 @@ type fillInEntriesContext interface { Config() Config moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) ModuleType(module blueprint.Module) string + OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) } func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint.Module) { @@ -514,7 +515,7 @@ func (a *AndroidMkEntries) fillInEntries(ctx fillInEntriesContext, mod blueprint if a.Include == "" { a.Include = "$(BUILD_PREBUILT)" } - a.Required = append(a.Required, amod.RequiredModuleNames()...) + a.Required = append(a.Required, amod.RequiredModuleNames(ctx)...) a.Host_required = append(a.Host_required, amod.HostRequiredModuleNames()...) a.Target_required = append(a.Target_required, amod.TargetRequiredModuleNames()...) diff --git a/android/module.go b/android/module.go index dc585d295..d629aa5a6 100644 --- a/android/module.go +++ b/android/module.go @@ -113,7 +113,7 @@ type Module interface { // Get information about the properties that can contain visibility rules. visibilityProperties() []visibilityProperty - RequiredModuleNames() []string + RequiredModuleNames(ctx ConfigAndErrorContext) []string HostRequiredModuleNames() []string TargetRequiredModuleNames() []string @@ -422,7 +422,7 @@ type commonProperties struct { Vintf_fragments []string `android:"path"` // names of other modules to install if this module is installed - Required []string `android:"arch_variant"` + Required proptools.Configurable[[]string] `android:"arch_variant"` // names of other modules to install on host if this module is installed Host_required []string `android:"arch_variant"` @@ -1101,7 +1101,7 @@ func addRequiredDeps(ctx BottomUpMutatorContext) { hostTargets = append(hostTargets, ctx.Config().BuildOSCommonTarget) if ctx.Device() { - for _, depName := range ctx.Module().RequiredModuleNames() { + for _, depName := range ctx.Module().RequiredModuleNames(ctx) { for _, target := range deviceTargets { addDep(target, depName) } @@ -1114,7 +1114,7 @@ func addRequiredDeps(ctx BottomUpMutatorContext) { } if ctx.Host() { - for _, depName := range ctx.Module().RequiredModuleNames() { + for _, depName := range ctx.Module().RequiredModuleNames(ctx) { for _, target := range hostTargets { // When a host module requires another host module, don't make a // dependency if they have different OSes (i.e. hostcross). @@ -1619,8 +1619,8 @@ func (m *ModuleBase) InRecovery() bool { return m.base().commonProperties.ImageVariation == RecoveryVariation } -func (m *ModuleBase) RequiredModuleNames() []string { - return m.base().commonProperties.Required +func (m *ModuleBase) RequiredModuleNames(ctx ConfigAndErrorContext) []string { + return m.base().commonProperties.Required.GetOrDefault(m.ConfigurableEvaluator(ctx), nil) } func (m *ModuleBase) HostRequiredModuleNames() []string { @@ -1992,7 +1992,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext) TargetDependencies: targetRequired, HostDependencies: hostRequired, Data: data, - Required: m.RequiredModuleNames(), + Required: m.RequiredModuleNames(ctx), } SetProvider(ctx, ModuleInfoJSONProvider, m.moduleInfoJSON) } diff --git a/android/module_context.go b/android/module_context.go index 591e270f0..e2677a4f6 100644 --- a/android/module_context.go +++ b/android/module_context.go @@ -183,7 +183,7 @@ type ModuleContext interface { InstallInVendor() bool InstallForceOS() (*OsType, *ArchType) - RequiredModuleNames() []string + RequiredModuleNames(ctx ConfigAndErrorContext) []string HostRequiredModuleNames() []string TargetRequiredModuleNames() []string @@ -755,8 +755,8 @@ func (m *moduleContext) ExpandOptionalSource(srcFile *string, _ string) Optional return OptionalPath{} } -func (m *moduleContext) RequiredModuleNames() []string { - return m.module.RequiredModuleNames() +func (m *moduleContext) RequiredModuleNames(ctx ConfigAndErrorContext) []string { + return m.module.RequiredModuleNames(ctx) } func (m *moduleContext) HostRequiredModuleNames() []string { diff --git a/android/soongconfig/modules.go b/android/soongconfig/modules.go index 87af774fd..f6046d00c 100644 --- a/android/soongconfig/modules.go +++ b/android/soongconfig/modules.go @@ -824,11 +824,16 @@ func (s *listVariable) printfIntoPropertyRecursive(fieldName []string, propStruc } field.Set(newField) case reflect.Struct: - fieldName = append(fieldName, propStruct.Type().Field(i).Name) - if err := s.printfIntoPropertyRecursive(fieldName, field, configValues); err != nil { - return err + if proptools.IsConfigurable(field.Type()) { + fieldName = append(fieldName, propStruct.Type().Field(i).Name) + return fmt.Errorf("soong_config_variables.%s.%s: list variables are not supported on configurable properties", s.variable, strings.Join(fieldName, ".")) + } else { + fieldName = append(fieldName, propStruct.Type().Field(i).Name) + if err := s.printfIntoPropertyRecursive(fieldName, field, configValues); err != nil { + return err + } + fieldName = fieldName[:len(fieldName)-1] } - fieldName = fieldName[:len(fieldName)-1] default: fieldName = append(fieldName, propStruct.Type().Field(i).Name) return fmt.Errorf("soong_config_variables.%s.%s: unsupported property type %q", s.variable, strings.Join(fieldName, "."), kind) diff --git a/android/testing.go b/android/testing.go index 6fb2997cb..8dd467dce 100644 --- a/android/testing.go +++ b/android/testing.go @@ -224,6 +224,10 @@ func (ctx *TestContext) OtherModuleProviderAdaptor() OtherModuleProviderContext }) } +func (ctx *TestContext) OtherModulePropertyErrorf(module Module, property string, fmt_ string, args ...interface{}) { + panic(fmt.Sprintf(fmt_, args...)) +} + // registeredComponentOrder defines the order in which a sortableComponent type is registered at // runtime and provides support for reordering the components registered for a test in the same // way. diff --git a/apex/androidmk.go b/apex/androidmk.go index 619be8dc4..4112108dd 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -218,7 +218,7 @@ func (a *apexBundle) writeRequiredModules(w io.Writer, moduleNames []string) { var required []string var targetRequired []string var hostRequired []string - required = append(required, a.RequiredModuleNames()...) + required = append(required, a.required...) targetRequired = append(targetRequired, a.TargetRequiredModuleNames()...) hostRequired = append(hostRequired, a.HostRequiredModuleNames()...) for _, fi := range a.filesInfo { diff --git a/apex/apex.go b/apex/apex.go index c19732eb1..caeeb5bfc 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -489,6 +489,9 @@ type apexBundle struct { javaApisUsedByModuleFile android.ModuleOutPath aconfigFiles []android.Path + + // Required modules, filled out during GenerateAndroidBuildActions and used in AndroidMk + required []string } // apexFileClass represents a type of file that can be included in APEX. @@ -567,7 +570,7 @@ func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, androidM if module != nil { ret.moduleDir = ctx.OtherModuleDir(module) ret.partition = module.PartitionTag(ctx.DeviceConfig()) - ret.requiredModuleNames = module.RequiredModuleNames() + ret.requiredModuleNames = module.RequiredModuleNames(ctx) ret.targetRequiredModuleNames = module.TargetRequiredModuleNames() ret.hostRequiredModuleNames = module.HostRequiredModuleNames() ret.multilib = module.Target().Arch.ArchType.Multilib @@ -2426,6 +2429,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.provideApexExportsInfo(ctx) a.providePrebuiltInfo(ctx) + + a.required = a.RequiredModuleNames(ctx) } // Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file diff --git a/cc/cc.go b/cc/cc.go index 7ea726e06..a2645ea01 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -981,8 +981,8 @@ func (c *Module) HiddenFromMake() bool { return c.Properties.HideFromMake } -func (c *Module) RequiredModuleNames() []string { - required := android.CopyOf(c.ModuleBase.RequiredModuleNames()) +func (c *Module) RequiredModuleNames(ctx android.ConfigAndErrorContext) []string { + required := android.CopyOf(c.ModuleBase.RequiredModuleNames(ctx)) if c.ImageVariation().Variation == android.CoreVariation { required = append(required, c.Properties.Target.Platform.Required...) required = removeListFromList(required, c.Properties.Target.Platform.Exclude_required) diff --git a/java/java.go b/java/java.go index 08fb6782c..95eaa20cb 100644 --- a/java/java.go +++ b/java/java.go @@ -1501,7 +1501,7 @@ func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) { InstalledFiles: j.data, OutputFile: j.outputFile, TestConfig: j.testConfig, - RequiredModuleNames: j.RequiredModuleNames(), + RequiredModuleNames: j.RequiredModuleNames(ctx), TestSuites: j.testProperties.Test_suites, IsHost: true, LocalSdkVersion: j.sdkVersion.String(), diff --git a/phony/phony.go b/phony/phony.go index 54692386a..b421176be 100644 --- a/phony/phony.go +++ b/phony/phony.go @@ -49,7 +49,7 @@ func PhonyFactory() android.Module { } func (p *phony) GenerateAndroidBuildActions(ctx android.ModuleContext) { - p.requiredModuleNames = ctx.RequiredModuleNames() + p.requiredModuleNames = ctx.RequiredModuleNames(ctx) p.hostRequiredModuleNames = ctx.HostRequiredModuleNames() p.targetRequiredModuleNames = ctx.TargetRequiredModuleNames() } diff --git a/snapshot/host_fake_snapshot.go b/snapshot/host_fake_snapshot.go index b416ebdd4..278247e10 100644 --- a/snapshot/host_fake_snapshot.go +++ b/snapshot/host_fake_snapshot.go @@ -129,12 +129,12 @@ func (c *hostFakeSingleton) GenerateBuildActions(ctx android.SingletonContext) { if !seen[outFile] { seen[outFile] = true outputs = append(outputs, WriteStringToFileRule(ctx, "", outFile)) - jsonData = append(jsonData, hostSnapshotFakeJsonFlags{*hostJsonDesc(module), false}) + jsonData = append(jsonData, hostSnapshotFakeJsonFlags{*hostJsonDesc(ctx, module), false}) } } }) // Update any module prebuilt information - for idx, _ := range jsonData { + for idx := range jsonData { if _, ok := prebuilts[jsonData[idx].ModuleName]; ok { // Prebuilt exists for this module jsonData[idx].Prebuilt = true diff --git a/snapshot/host_snapshot.go b/snapshot/host_snapshot.go index edcc16348..1ecab7ddc 100644 --- a/snapshot/host_snapshot.go +++ b/snapshot/host_snapshot.go @@ -101,7 +101,7 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string // Create JSON file based on the direct dependencies ctx.VisitDirectDeps(func(dep android.Module) { - desc := hostJsonDesc(dep) + desc := hostJsonDesc(ctx, dep) if desc != nil { jsonData = append(jsonData, *desc) } @@ -209,7 +209,7 @@ func hostRelativePathString(m android.Module) string { // Create JSON description for given module, only create descriptions for binary modules // and rust_proc_macro modules which provide a valid HostToolPath -func hostJsonDesc(m android.Module) *SnapshotJsonFlags { +func hostJsonDesc(ctx android.ConfigAndErrorContext, m android.Module) *SnapshotJsonFlags { path := hostToolPath(m) relPath := hostRelativePathString(m) procMacro := false @@ -226,7 +226,7 @@ func hostJsonDesc(m android.Module) *SnapshotJsonFlags { props := &SnapshotJsonFlags{ ModuleStemName: moduleStem, Filename: path.String(), - Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...), + Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames(ctx)...), RelativeInstallPath: relPath, RustProcMacro: procMacro, CrateName: crateName,