summaryrefslogtreecommitdiff
path: root/android/module_context.go
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2024-02-07 09:43:59 -0800
committer Cole Faust <colefaust@google.com> 2024-03-06 16:03:01 -0800
commit5a231bd8191082f374beb35abd5715989635a562 (patch)
tree0232f1be804fe96516b26665ab10fc3c8ddb13bd /android/module_context.go
parenteefca7373c1cefc2ee14a3b6a86db7eeefcddfbe (diff)
Select statements
See the blueprint cl for more information. Things still to do: - Support selecting on product variables and variants - Test/Support property struct reflection tags like arch_variant, path, and variant_prepend - Test that selects combine well with existing configurability mechanisms like arch:, target:, multilib:, python's version:, etc. Bug: 323382414 Test: go tests Change-Id: If5d1ea1ad0c4ebabffaea91d62e1a1c6f926a793
Diffstat (limited to 'android/module_context.go')
-rw-r--r--android/module_context.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/android/module_context.go b/android/module_context.go
index 1cab63022..3fc5d0158 100644
--- a/android/module_context.go
+++ b/android/module_context.go
@@ -21,6 +21,7 @@ import (
"strings"
"github.com/google/blueprint"
+ "github.com/google/blueprint/parser"
"github.com/google/blueprint/proptools"
)
@@ -212,6 +213,10 @@ type ModuleContext interface {
// GenerateAndroidBuildActions. If it is called then the struct will be written out and included in
// the module-info.json generated by Make, and Make will not generate its own data for this module.
ModuleInfoJSON() *ModuleInfoJSON
+
+ // EvaluateConfiguration makes ModuleContext a valid proptools.ConfigurableEvaluator, so this context
+ // can be used to evaluate the final value of Configurable properties.
+ EvaluateConfiguration(parser.SelectType, string) (string, bool)
}
type moduleContext struct {
@@ -714,3 +719,32 @@ func (m *moduleContext) HostRequiredModuleNames() []string {
func (m *moduleContext) TargetRequiredModuleNames() []string {
return m.module.TargetRequiredModuleNames()
}
+
+func (m *moduleContext) EvaluateConfiguration(ty parser.SelectType, condition string) (string, bool) {
+ switch ty {
+ case parser.SelectTypeReleaseVariable:
+ if v, ok := m.Config().productVariables.BuildFlags[condition]; ok {
+ return v, true
+ }
+ return "", false
+ case parser.SelectTypeProductVariable:
+ // TODO: Might add these on a case-by-case basis
+ m.ModuleErrorf("TODO(b/323382414): Product variables are not yet supported in selects")
+ return "", false
+ case parser.SelectTypeSoongConfigVariable:
+ parts := strings.Split(condition, ":")
+ namespace := parts[0]
+ variable := parts[1]
+ if n, ok := m.Config().productVariables.VendorVars[namespace]; ok {
+ if v, ok := n[variable]; ok {
+ return v, true
+ }
+ }
+ return "", false
+ case parser.SelectTypeVariant:
+ m.ModuleErrorf("TODO(b/323382414): Variants are not yet supported in selects")
+ return "", false
+ default:
+ panic("Should be unreachable")
+ }
+}