summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cole Faust <colefaust@google.com> 2024-06-20 12:57:43 -0700
committer Cole Faust <colefaust@google.com> 2024-06-20 14:59:10 -0700
commit46f6e2f1aace226cee6677bddf0cf7367b665a2e (patch)
treee7c013358768a9ede5b57966d9bc3ae86998601e
parent26faf1b32188260d1728d57004a81a5cd55bfe6c (diff)
Allow soong config variables to be boolean-typed
So that you can use `true` instead of `"true"` in select expressions. Bug: 323382414 Test: m nothing --no-skip-soong-tests Change-Id: I950bd8e04f8fab5187ea5075514d476227943f33
-rw-r--r--android/module.go15
-rw-r--r--android/selects_test.go39
-rw-r--r--android/variable.go3
3 files changed, 49 insertions, 8 deletions
diff --git a/android/module.go b/android/module.go
index b43815063..9c7410c87 100644
--- a/android/module.go
+++ b/android/module.go
@@ -2253,7 +2253,20 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
variable := condition.Arg(1)
if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
if v, ok := n[variable]; ok {
- return proptools.ConfigurableValueString(v)
+ ty := ""
+ if namespaces, ok := ctx.Config().productVariables.VendorVarTypes[namespace]; ok {
+ ty = namespaces[variable]
+ }
+ switch ty {
+ case "":
+ // strings are the default, we don't bother writing them to the soong variables json file
+ return proptools.ConfigurableValueString(v)
+ case "bool":
+ return proptools.ConfigurableValueBool(v == "true")
+ default:
+ panic("unhandled soong config variable type: " + ty)
+ }
+
}
}
return proptools.ConfigurableValueUndefined()
diff --git a/android/selects_test.go b/android/selects_test.go
index 3093deb11..e2dc4035d 100644
--- a/android/selects_test.go
+++ b/android/selects_test.go
@@ -25,12 +25,13 @@ import (
func TestSelects(t *testing.T) {
testCases := []struct {
- name string
- bp string
- provider selectsTestProvider
- providers map[string]selectsTestProvider
- vendorVars map[string]map[string]string
- expectedError string
+ name string
+ bp string
+ provider selectsTestProvider
+ providers map[string]selectsTestProvider
+ vendorVars map[string]map[string]string
+ vendorVarTypes map[string]map[string]string
+ expectedError string
}{
{
name: "basic string list",
@@ -584,6 +585,31 @@ func TestSelects(t *testing.T) {
},
},
{
+ name: "Select on boolean soong config variable",
+ bp: `
+ my_module_type {
+ name: "foo",
+ my_string: select(soong_config_variable("my_namespace", "my_variable"), {
+ true: "t",
+ false: "f",
+ }),
+ }
+ `,
+ vendorVars: map[string]map[string]string{
+ "my_namespace": {
+ "my_variable": "true",
+ },
+ },
+ vendorVarTypes: map[string]map[string]string{
+ "my_namespace": {
+ "my_variable": "bool",
+ },
+ },
+ provider: selectsTestProvider{
+ my_string: proptools.StringPtr("t"),
+ },
+ },
+ {
name: "Select on boolean false",
bp: `
my_module_type {
@@ -813,6 +839,7 @@ func TestSelects(t *testing.T) {
}),
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
variables.VendorVars = tc.vendorVars
+ variables.VendorVarTypes = tc.vendorVarTypes
}),
)
if tc.expectedError != "" {
diff --git a/android/variable.go b/android/variable.go
index 2cdcd5355..a331439f6 100644
--- a/android/variable.go
+++ b/android/variable.go
@@ -399,7 +399,8 @@ type ProductVariables struct {
PlatformSepolicyCompatVersions []string `json:",omitempty"`
- VendorVars map[string]map[string]string `json:",omitempty"`
+ VendorVars map[string]map[string]string `json:",omitempty"`
+ VendorVarTypes map[string]map[string]string `json:",omitempty"`
Ndk_abis *bool `json:",omitempty"`