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
This commit is contained in:
Cole Faust 2024-06-17 12:32:40 -07:00 committed by Bartłomiej Rudecki
parent 8b82c0d750
commit 5b91c24c11
Signed by: przekichane
GPG key ID: 751F23C6F014EF76
12 changed files with 41 additions and 26 deletions

View file

@ -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()...)

View file

@ -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)
}

View file

@ -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 {

View file

@ -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)

View file

@ -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.

View file

@ -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 {

View file

@ -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

View file

@ -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)

View file

@ -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(),

View file

@ -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()
}

View file

@ -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

View file

@ -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,