aboutsummaryrefslogtreecommitdiff
path: root/android/selects_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/selects_test.go')
-rw-r--r--android/selects_test.go96
1 files changed, 89 insertions, 7 deletions
diff --git a/android/selects_test.go b/android/selects_test.go
index d9499a500..8089fbc5c 100644
--- a/android/selects_test.go
+++ b/android/selects_test.go
@@ -546,6 +546,24 @@ func TestSelects(t *testing.T) {
},
},
{
+ name: "Unhandled string value",
+ bp: `
+ my_module_type {
+ name: "foo",
+ my_string: select(soong_config_variable("my_namespace", "my_variable"), {
+ "foo": "a",
+ "bar": "b",
+ }),
+ }
+ `,
+ vendorVars: map[string]map[string]string{
+ "my_namespace": {
+ "my_variable": "baz",
+ },
+ },
+ expectedError: `my_string: soong_config_variable\("my_namespace", "my_variable"\) had value "baz", which was not handled by the select statement`,
+ },
+ {
name: "Select on boolean",
bp: `
my_module_type {
@@ -596,7 +614,7 @@ func TestSelects(t *testing.T) {
}),
}
`,
- expectedError: "foo",
+ expectedError: `my_string: boolean_var_for_testing\(\) had value undefined, which was not handled by the select statement`,
},
{
name: "Select on boolean undefined with default",
@@ -688,6 +706,61 @@ func TestSelects(t *testing.T) {
`,
expectedError: `can't assign select statement to non-configurable property "my_nonconfigurable_string_list"`,
},
+ {
+ name: "Select in variable",
+ bp: `
+ my_second_variable = ["after.cpp"]
+ my_variable = select(soong_config_variable("my_namespace", "my_variable"), {
+ "a": ["a.cpp"],
+ "b": ["b.cpp"],
+ default: ["c.cpp"],
+ }) + my_second_variable
+ my_module_type {
+ name: "foo",
+ my_string_list: ["before.cpp"] + my_variable,
+ }
+ `,
+ provider: selectsTestProvider{
+ my_string_list: &[]string{"before.cpp", "a.cpp", "after.cpp"},
+ },
+ vendorVars: map[string]map[string]string{
+ "my_namespace": {
+ "my_variable": "a",
+ },
+ },
+ },
+ {
+ name: "Soong config value variable on configurable property",
+ bp: `
+ soong_config_module_type {
+ name: "soong_config_my_module_type",
+ module_type: "my_module_type",
+ config_namespace: "my_namespace",
+ value_variables: ["my_variable"],
+ properties: ["my_string", "my_string_list"],
+ }
+
+ soong_config_my_module_type {
+ name: "foo",
+ my_string_list: ["before.cpp"],
+ soong_config_variables: {
+ my_variable: {
+ my_string_list: ["after_%s.cpp"],
+ my_string: "%s.cpp",
+ },
+ },
+ }
+ `,
+ provider: selectsTestProvider{
+ my_string: proptools.StringPtr("foo.cpp"),
+ my_string_list: &[]string{"before.cpp", "after_foo.cpp"},
+ },
+ vendorVars: map[string]map[string]string{
+ "my_namespace": {
+ "my_variable": "foo",
+ },
+ },
+ },
}
for _, tc := range testCases {
@@ -695,6 +768,7 @@ func TestSelects(t *testing.T) {
fixtures := GroupFixturePreparers(
PrepareForTestWithDefaults,
PrepareForTestWithArchMutator,
+ PrepareForTestWithSoongConfigModuleBuildComponents,
FixtureRegisterWithContext(func(ctx RegistrationContext) {
ctx.RegisterModuleType("my_module_type", newSelectsMockModule)
ctx.RegisterModuleType("my_defaults", newSelectsMockModuleDefaults)
@@ -749,7 +823,7 @@ func (p *selectsTestProvider) String() string {
myStringStr = *p.my_string
}
myNonconfigurableStringStr := "nil"
- if p.my_string != nil {
+ if p.my_nonconfigurable_string != nil {
myNonconfigurableStringStr = *p.my_nonconfigurable_string
}
return fmt.Sprintf(`selectsTestProvider {
@@ -792,13 +866,21 @@ type selectsMockModule struct {
properties selectsMockModuleProperties
}
+func optionalToPtr[T any](o proptools.ConfigurableOptional[T]) *T {
+ if o.IsEmpty() {
+ return nil
+ }
+ x := o.Get()
+ return &x
+}
+
func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) {
SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{
- my_bool: p.properties.My_bool.Get(ctx),
- my_string: p.properties.My_string.Get(ctx),
- my_string_list: p.properties.My_string_list.Get(ctx),
- my_paths: p.properties.My_paths.Get(ctx),
- replacing_string_list: p.properties.Replacing_string_list.Get(ctx),
+ my_bool: optionalToPtr(p.properties.My_bool.Get(ctx)),
+ my_string: optionalToPtr(p.properties.My_string.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)),
my_nonconfigurable_bool: p.properties.My_nonconfigurable_bool,
my_nonconfigurable_string: p.properties.My_nonconfigurable_string,
my_nonconfigurable_string_list: p.properties.My_nonconfigurable_string_list,