Make the enabled property configurable
This allows using select statements with it.
Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: I6f3efaaa3d82505e38a91ee4ba0e18e404360191
Merged-In: If355d24506e3f117d27b21442a6c02bca3402dc7
diff --git a/android/Android.bp b/android/Android.bp
index f130d3a..fa78e15 100644
--- a/android/Android.bp
+++ b/android/Android.bp
@@ -41,6 +41,7 @@
"buildinfo_prop.go",
"config.go",
"test_config.go",
+ "configurable_properties.go",
"configured_jars.go",
"csuite_config.go",
"deapexer.go",
diff --git a/android/androidmk.go b/android/androidmk.go
index 07f7c58..0a366e1 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -849,7 +849,7 @@
mod blueprint.Module, provider AndroidMkDataProvider) error {
amod := mod.(Module).base()
- if shouldSkipAndroidMkProcessing(amod) {
+ if shouldSkipAndroidMkProcessing(ctx, amod) {
return nil
}
@@ -939,7 +939,7 @@
func translateAndroidMkEntriesModule(ctx SingletonContext, w io.Writer, moduleInfoJSONs *[]*ModuleInfoJSON,
mod blueprint.Module, provider AndroidMkEntriesProvider) error {
- if shouldSkipAndroidMkProcessing(mod.(Module).base()) {
+ if shouldSkipAndroidMkProcessing(ctx, mod.(Module).base()) {
return nil
}
@@ -961,11 +961,11 @@
return nil
}
-func ShouldSkipAndroidMkProcessing(module Module) bool {
- return shouldSkipAndroidMkProcessing(module.base())
+func ShouldSkipAndroidMkProcessing(ctx ConfigAndErrorContext, module Module) bool {
+ return shouldSkipAndroidMkProcessing(ctx, module.base())
}
-func shouldSkipAndroidMkProcessing(module *ModuleBase) bool {
+func shouldSkipAndroidMkProcessing(ctx ConfigAndErrorContext, module *ModuleBase) bool {
if !module.commonProperties.NamespaceExportedToMake {
// TODO(jeffrygaston) do we want to validate that there are no modules being
// exported to Kati that depend on this module?
@@ -984,7 +984,7 @@
return true
}
- return !module.Enabled() ||
+ return !module.Enabled(ctx) ||
module.commonProperties.HideFromMake ||
// Make does not understand LinuxBionic
module.Os() == LinuxBionic ||
diff --git a/android/arch.go b/android/arch.go
index cd8882b..e0c6908 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -486,7 +486,7 @@
// dependencies on OsType variants that are explicitly disabled in their
// properties. The CommonOS variant will still depend on disabled variants
// if they are disabled afterwards, e.g. in archMutator if
- if module.Enabled() {
+ if module.Enabled(mctx) {
mctx.AddInterVariantDependency(commonOsToOsSpecificVariantTag, commonOSVariant, module)
}
}
@@ -511,7 +511,7 @@
var variants []Module
mctx.VisitDirectDeps(func(m Module) {
if mctx.OtherModuleDependencyTag(m) == commonOsToOsSpecificVariantTag {
- if m.Enabled() {
+ if m.Enabled(mctx) {
variants = append(variants, m)
}
}
diff --git a/android/arch_test.go b/android/arch_test.go
index 5021a67..f0a58a9 100644
--- a/android/arch_test.go
+++ b/android/arch_test.go
@@ -423,7 +423,7 @@
variants := ctx.ModuleVariantsForTests(name)
for _, variant := range variants {
m := ctx.ModuleForTests(name, variant)
- if m.Module().Enabled() {
+ if m.Module().Enabled(PanickingConfigAndErrorContext(ctx)) {
ret = append(ret, variant)
}
}
@@ -533,7 +533,7 @@
variants := ctx.ModuleVariantsForTests(name)
for _, variant := range variants {
m := ctx.ModuleForTests(name, variant)
- if m.Module().Enabled() {
+ if m.Module().Enabled(PanickingConfigAndErrorContext(ctx)) {
ret = append(ret, variant)
}
}
diff --git a/android/base_module_context.go b/android/base_module_context.go
index c5fe585..2963520 100644
--- a/android/base_module_context.go
+++ b/android/base_module_context.go
@@ -325,7 +325,7 @@
return nil
}
- if !aModule.Enabled() {
+ if !aModule.Enabled(b) {
if t, ok := tag.(AllowDisabledModuleDependency); !ok || !t.AllowDisabledModuleDependency(aModule) {
if b.Config().AllowMissingDependencies() {
b.AddMissingDependencies([]string{b.OtherModuleName(aModule)})
diff --git a/android/configurable_properties.go b/android/configurable_properties.go
new file mode 100644
index 0000000..dad42fa
--- /dev/null
+++ b/android/configurable_properties.go
@@ -0,0 +1,28 @@
+package android
+
+import "github.com/google/blueprint/proptools"
+
+// CreateSelectOsToBool is a utility function that makes it easy to create a
+// Configurable property value that maps from os to a bool. Use an empty string
+// to indicate a "default" case.
+func CreateSelectOsToBool(cases map[string]*bool) proptools.Configurable[bool] {
+ var resultCases []proptools.ConfigurableCase[bool]
+ for pattern, value := range cases {
+ if pattern == "" {
+ resultCases = append(resultCases, proptools.NewConfigurableCase(
+ []proptools.ConfigurablePattern{proptools.NewDefaultConfigurablePattern()},
+ value,
+ ))
+ } else {
+ resultCases = append(resultCases, proptools.NewConfigurableCase(
+ []proptools.ConfigurablePattern{proptools.NewStringConfigurablePattern(pattern)},
+ value,
+ ))
+ }
+ }
+
+ return proptools.NewConfigurable(
+ []proptools.ConfigurableCondition{proptools.NewConfigurableCondition("os", nil)},
+ resultCases,
+ )
+}
diff --git a/android/early_module_context.go b/android/early_module_context.go
index cf1b5fc..23f4c90 100644
--- a/android/early_module_context.go
+++ b/android/early_module_context.go
@@ -173,5 +173,5 @@
}
func (e *earlyModuleContext) OtherModulePropertyErrorf(module Module, property string, fmt string, args ...interface{}) {
- e.EarlyModuleContext.OtherModulePropertyErrorf(module, property, fmt, args)
+ e.EarlyModuleContext.OtherModulePropertyErrorf(module, property, fmt, args...)
}
diff --git a/android/gen_notice.go b/android/gen_notice.go
index 1acc638..6815f64 100644
--- a/android/gen_notice.go
+++ b/android/gen_notice.go
@@ -62,7 +62,7 @@
if mod == nil {
continue
}
- if !mod.Enabled() { // don't depend on variants without build rules
+ if !mod.Enabled(ctx) { // don't depend on variants without build rules
continue
}
modules = append(modules, mod)
diff --git a/android/license_metadata.go b/android/license_metadata.go
index eabb1b1..d515cdd 100644
--- a/android/license_metadata.go
+++ b/android/license_metadata.go
@@ -36,7 +36,7 @@
func buildLicenseMetadata(ctx ModuleContext, licenseMetadataFile WritablePath) {
base := ctx.Module().base()
- if !base.Enabled() {
+ if !base.Enabled(ctx) {
return
}
@@ -69,7 +69,7 @@
if dep == nil {
return
}
- if !dep.Enabled() {
+ if !dep.Enabled(ctx) {
return
}
diff --git a/android/makevars.go b/android/makevars.go
index 4039e7e..e73645f 100644
--- a/android/makevars.go
+++ b/android/makevars.go
@@ -98,6 +98,7 @@
BlueprintFile(module blueprint.Module) string
ModuleErrorf(module blueprint.Module, format string, args ...interface{})
+ OtherModulePropertyErrorf(module Module, property, format string, args ...interface{})
Errorf(format string, args ...interface{})
VisitAllModules(visit func(Module))
@@ -265,7 +266,7 @@
}
ctx.VisitAllModules(func(m Module) {
- if provider, ok := m.(ModuleMakeVarsProvider); ok && m.Enabled() {
+ if provider, ok := m.(ModuleMakeVarsProvider); ok && m.Enabled(ctx) {
mctx := &makeVarsContext{
SingletonContext: ctx,
}
diff --git a/android/module.go b/android/module.go
index effca03..5d69ba1 100644
--- a/android/module.go
+++ b/android/module.go
@@ -60,7 +60,7 @@
base() *ModuleBase
Disable()
- Enabled() bool
+ Enabled(ctx ConfigAndErrorContext) bool
Target() Target
MultiTargets() []Target
@@ -287,7 +287,7 @@
// but are not usually required (e.g. superceded by a prebuilt) should not be
// disabled as that will prevent them from being built by the checkbuild target
// and so prevent early detection of changes that have broken those modules.
- Enabled *bool `android:"arch_variant"`
+ Enabled proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
// Controls the visibility of this module to other modules. Allowable values are one or more of
// these formats:
@@ -1392,14 +1392,11 @@
return partition
}
-func (m *ModuleBase) Enabled() bool {
+func (m *ModuleBase) Enabled(ctx ConfigAndErrorContext) bool {
if m.commonProperties.ForcedDisabled {
return false
}
- if m.commonProperties.Enabled == nil {
- return !m.Os().DefaultDisabled
- }
- return *m.commonProperties.Enabled
+ return m.commonProperties.Enabled.GetOrDefault(m.ConfigurableEvaluator(ctx), !m.Os().DefaultDisabled)
}
func (m *ModuleBase) Disable() {
@@ -1643,7 +1640,7 @@
// not be created if the module is not exported to make.
// Those could depend on the build target and fail to compile
// for the current build target.
- if !ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(a) {
+ if !ctx.Config().KatiEnabled() || !shouldSkipAndroidMkProcessing(ctx, a) {
allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
}
})
@@ -1835,7 +1832,7 @@
checkDistProperties(ctx, fmt.Sprintf("dists[%d]", i), &m.distProperties.Dists[i])
}
- if m.Enabled() {
+ if m.Enabled(ctx) {
// ensure all direct android.Module deps are enabled
ctx.VisitDirectDepsBlueprint(func(bm blueprint.Module) {
if m, ok := bm.(Module); ok {
@@ -2136,7 +2133,7 @@
}
func (e configurationEvalutor) PropertyErrorf(property string, fmt string, args ...interface{}) {
- e.ctx.OtherModulePropertyErrorf(e.m, property, fmt, args)
+ e.ctx.OtherModulePropertyErrorf(e.m, property, fmt, args...)
}
func (e configurationEvalutor) EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue {
@@ -2535,7 +2532,7 @@
}
osDeps := map[osAndCross]Paths{}
ctx.VisitAllModules(func(module Module) {
- if module.Enabled() {
+ if module.Enabled(ctx) {
key := osAndCross{os: module.Target().Os, hostCross: module.Target().HostCross}
osDeps[key] = append(osDeps[key], module.base().checkbuildFiles...)
}
diff --git a/android/mutator.go b/android/mutator.go
index 75ba650..5abb05d 100644
--- a/android/mutator.go
+++ b/android/mutator.go
@@ -674,13 +674,11 @@
// on component modules to be added so that they can depend directly on a prebuilt
// module.
func componentDepsMutator(ctx BottomUpMutatorContext) {
- if m := ctx.Module(); m.Enabled() {
- m.ComponentDepsMutator(ctx)
- }
+ ctx.Module().ComponentDepsMutator(ctx)
}
func depsMutator(ctx BottomUpMutatorContext) {
- if m := ctx.Module(); m.Enabled() {
+ if m := ctx.Module(); m.Enabled(ctx) {
m.base().baseDepsMutator(ctx)
m.DepsMutator(ctx)
}
diff --git a/android/override_module.go b/android/override_module.go
index 1341f53..21cf381 100644
--- a/android/override_module.go
+++ b/android/override_module.go
@@ -322,7 +322,7 @@
}
func overridableModuleDepsMutator(ctx BottomUpMutatorContext) {
- if b, ok := ctx.Module().(OverridableModule); ok && b.Enabled() {
+ if b, ok := ctx.Module().(OverridableModule); ok && b.Enabled(ctx) {
b.OverridablePropertiesDepsMutator(ctx)
}
}
diff --git a/android/paths.go b/android/paths.go
index 39b660c..8d92aa4 100644
--- a/android/paths.go
+++ b/android/paths.go
@@ -60,6 +60,7 @@
ModuleDir() string
ModuleErrorf(fmt string, args ...interface{})
+ OtherModulePropertyErrorf(module Module, property, fmt string, args ...interface{})
}
var _ EarlyModulePathContext = ModuleContext(nil)
@@ -561,7 +562,7 @@
if module == nil {
return nil, missingDependencyError{[]string{moduleName}}
}
- if aModule, ok := module.(Module); ok && !aModule.Enabled() {
+ if aModule, ok := module.(Module); ok && !aModule.Enabled(ctx) {
return nil, missingDependencyError{[]string{moduleName}}
}
if outProducer, ok := module.(OutputFileProducer); ok {
diff --git a/android/prebuilt.go b/android/prebuilt.go
index 2b7b55b..1f9b331 100644
--- a/android/prebuilt.go
+++ b/android/prebuilt.go
@@ -275,7 +275,7 @@
srcPropertyName := proptools.PropertyNameForField(srcField)
srcsSupplier := func(ctx BaseModuleContext, _ Module) []string {
- if !module.Enabled() {
+ if !module.Enabled(ctx) {
return nil
}
value := srcPropsValue.FieldByIndex(srcFieldIndex)
@@ -425,7 +425,7 @@
m := ctx.Module()
// If this module is a prebuilt, is enabled and has not been renamed to source then add a
// dependency onto the source if it is present.
- if p := GetEmbeddedPrebuilt(m); p != nil && m.Enabled() && !p.properties.PrebuiltRenamedToSource {
+ if p := GetEmbeddedPrebuilt(m); p != nil && m.Enabled(ctx) && !p.properties.PrebuiltRenamedToSource {
bmn, _ := m.(baseModuleName)
name := bmn.BaseModuleName()
if ctx.OtherModuleReverseDependencyVariantExists(name) {
@@ -702,7 +702,7 @@
}
// If source is not available or is disabled then always use the prebuilt.
- if source == nil || !source.Enabled() {
+ if source == nil || !source.Enabled(ctx) {
return true
}
diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go
index 575b926..d775ac3 100644
--- a/android/prebuilt_test.go
+++ b/android/prebuilt_test.go
@@ -351,7 +351,7 @@
}
})
- moduleIsDisabled := !foo.Module().Enabled()
+ moduleIsDisabled := !foo.Module().Enabled(PanickingConfigAndErrorContext(result.TestContext))
deps := foo.Module().(*sourceModule).deps
if moduleIsDisabled {
if len(deps) > 0 {
diff --git a/android/register.go b/android/register.go
index d00c15f..aeb3b4c 100644
--- a/android/register.go
+++ b/android/register.go
@@ -16,8 +16,9 @@
import (
"fmt"
- "github.com/google/blueprint"
"reflect"
+
+ "github.com/google/blueprint"
)
// A sortable component is one whose registration order affects the order in which it is executed
diff --git a/android/singleton.go b/android/singleton.go
index 76df1eb..d364384 100644
--- a/android/singleton.go
+++ b/android/singleton.go
@@ -284,5 +284,5 @@
}
func (s *singletonContextAdaptor) OtherModulePropertyErrorf(module Module, property string, format string, args ...interface{}) {
- s.blueprintSingletonContext().OtherModulePropertyErrorf(module, property, format, args)
+ s.blueprintSingletonContext().OtherModulePropertyErrorf(module, property, format, args...)
}
diff --git a/android/testing.go b/android/testing.go
index 7b4411e..c692c72 100644
--- a/android/testing.go
+++ b/android/testing.go
@@ -1287,3 +1287,21 @@
t.Errorf("%q is not found in %v", expected, result)
}
}
+
+type panickingConfigAndErrorContext struct {
+ ctx *TestContext
+}
+
+func (ctx *panickingConfigAndErrorContext) OtherModulePropertyErrorf(module Module, property, fmt string, args ...interface{}) {
+ panic(ctx.ctx.PropertyErrorf(module, property, fmt, args...).Error())
+}
+
+func (ctx *panickingConfigAndErrorContext) Config() Config {
+ return ctx.ctx.Config()
+}
+
+func PanickingConfigAndErrorContext(ctx *TestContext) ConfigAndErrorContext {
+ return &panickingConfigAndErrorContext{
+ ctx: ctx,
+ }
+}
diff --git a/android/variable.go b/android/variable.go
index 599f88e..309824f 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -58,13 +58,13 @@
// unbundled_build is a catch-all property to annotate modules that don't build in one or
// more unbundled branches, usually due to dependencies missing from the manifest.
Unbundled_build struct {
- Enabled *bool `android:"arch_variant"`
+ Enabled proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
} `android:"arch_variant"`
// similar to `Unbundled_build`, but `Always_use_prebuilt_sdks` means that it uses prebuilt
// sdk specifically.
Always_use_prebuilt_sdks struct {
- Enabled *bool `android:"arch_variant"`
+ Enabled proptools.Configurable[bool] `android:"arch_variant,replace_instead_of_append"`
} `android:"arch_variant"`
Malloc_not_svelte struct {