diff options
author | 2025-03-18 11:24:39 -0700 | |
---|---|---|
committer | 2025-03-18 11:24:39 -0700 | |
commit | 764aaca0f6a57c182f2ecfd6ea6c1dce3ff715f0 (patch) | |
tree | 18d5df10d158d09d01c7226c1d6728c917e85bf8 | |
parent | 4caba62b51359be9baddb5c53e01b380999f4c31 (diff) |
Support ints in select() expressions
Both for the type of the condition, and the type of the property.
Bug: 355539748
Test: soong tests
Change-Id: Ia84ea9f9f43a4c44a96415aad06c9c3981bf217c
-rw-r--r-- | android/module.go | 8 | ||||
-rw-r--r-- | android/selects_test.go | 78 |
2 files changed, 86 insertions, 0 deletions
diff --git a/android/module.go b/android/module.go index a3fe837a5..45a20a061 100644 --- a/android/module.go +++ b/android/module.go @@ -22,6 +22,7 @@ import ( "reflect" "slices" "sort" + "strconv" "strings" "github.com/google/blueprint" @@ -2688,6 +2689,13 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu return proptools.ConfigurableValueString(v) case "bool": return proptools.ConfigurableValueBool(v == "true") + case "int": + i, err := strconv.ParseInt(v, 10, 64) + if err != nil { + ctx.OtherModulePropertyErrorf(m, property, "integer soong_config_variable was not an int: %q", v) + return proptools.ConfigurableValueUndefined() + } + return proptools.ConfigurableValueInt(i) case "string_list": return proptools.ConfigurableValueStringList(strings.Split(v, " ")) default: diff --git a/android/selects_test.go b/android/selects_test.go index 7f20a3d66..8e469f8e3 100644 --- a/android/selects_test.go +++ b/android/selects_test.go @@ -666,6 +666,81 @@ func TestSelects(t *testing.T) { }, }, { + name: "Select on integer soong config variable", + bp: ` + my_module_type { + name: "foo", + my_string: select(soong_config_variable("my_namespace", "my_variable"), { + 34: "34", + default: "other", + }), + } + `, + vendorVars: map[string]map[string]string{ + "my_namespace": { + "my_variable": "34", + }, + }, + vendorVarTypes: map[string]map[string]string{ + "my_namespace": { + "my_variable": "int", + }, + }, + provider: selectsTestProvider{ + my_string: proptools.StringPtr("34"), + }, + }, + { + name: "Select on integer soong config variable default", + bp: ` + my_module_type { + name: "foo", + my_string: select(soong_config_variable("my_namespace", "my_variable"), { + 34: "34", + default: "other", + }), + } + `, + vendorVars: map[string]map[string]string{ + "my_namespace": { + "my_variable": "5", + }, + }, + vendorVarTypes: map[string]map[string]string{ + "my_namespace": { + "my_variable": "int", + }, + }, + provider: selectsTestProvider{ + my_string: proptools.StringPtr("other"), + }, + }, + { + name: "Assign to integer property", + bp: ` + my_module_type { + name: "foo", + my_int64: select(soong_config_variable("my_namespace", "my_variable"), { + any @ val: val, + default: "other", + }), + } + `, + vendorVars: map[string]map[string]string{ + "my_namespace": { + "my_variable": "5", + }, + }, + vendorVarTypes: map[string]map[string]string{ + "my_namespace": { + "my_variable": "int", + }, + }, + provider: selectsTestProvider{ + my_int64: proptools.Int64Ptr(5), + }, + }, + { name: "Mismatched condition types", bp: ` my_module_type { @@ -1132,6 +1207,7 @@ my_module_type { type selectsTestProvider struct { my_bool *bool my_string *string + my_int64 *int64 my_string_list *[]string my_paths *[]string replacing_string_list *[]string @@ -1181,6 +1257,7 @@ var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]() type selectsMockModuleProperties struct { My_bool proptools.Configurable[bool] + My_int64 proptools.Configurable[int64] My_string proptools.Configurable[string] My_string_list proptools.Configurable[[]string] My_paths proptools.Configurable[[]string] `android:"path"` @@ -1213,6 +1290,7 @@ func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) { SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{ my_bool: optionalToPtr(p.properties.My_bool.Get(ctx)), my_string: optionalToPtr(p.properties.My_string.Get(ctx)), + my_int64: optionalToPtr(p.properties.My_int64.Get(ctx)), my_string_list: optionalToPtr(p.properties.My_string_list.Get(ctx)), my_paths: optionalToPtr(p.properties.My_paths.Get(ctx)), replacing_string_list: optionalToPtr(p.properties.Replacing_string_list.Get(ctx)), |