Loading android/arch.go +1 −1 Original line number Diff line number Diff line Loading @@ -980,7 +980,7 @@ func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.S panic(fmt.Errorf("unexpected tag format %q", field.Tag)) } // these tags don't need to be present in the runtime generated struct type. values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"}) values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path", "replace_instead_of_append"}) if len(values) > 0 { panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name)) } Loading android/path_properties.go +2 −2 Original line number Diff line number Diff line Loading @@ -109,9 +109,9 @@ func pathPropertiesForPropertyStruct(ctx BottomUpMutatorContext, ps interface{}) case reflect.Struct: intf := sv.Interface() if configurable, ok := intf.(proptools.Configurable[string]); ok { ret = append(ret, proptools.String(configurable.Evaluate(ctx))) ret = append(ret, configurable.GetOrDefault(ctx, "")) } else if configurable, ok := intf.(proptools.Configurable[[]string]); ok { ret = append(ret, proptools.Slice(configurable.Evaluate(ctx))...) ret = append(ret, configurable.GetOrDefault(ctx, nil)...) } else { panic(fmt.Errorf(`field %s in type %s has tag android:"path" but is not a string or slice of strings, it is a %s`, v.Type().FieldByIndex(i).Name, v.Type(), sv.Type())) Loading android/selects_test.go +85 −13 Original line number Diff line number Diff line Loading @@ -368,14 +368,62 @@ func TestSelects(t *testing.T) { my_bool: proptools.BoolPtr(true), }, }, { name: "defaults with lists are appended", bp: ` my_module_type { name: "foo", defaults: ["bar"], my_string_list: select(soong_config_variable("my_namespace", "my_variable"), { "a": ["a1"], default: ["b1"], }), } my_defaults { name: "bar", my_string_list: select(soong_config_variable("my_namespace", "my_variable2"), { "a": ["a2"], default: ["b2"], }), } `, provider: selectsTestProvider{ my_string_list: &[]string{"b2", "b1"}, }, }, { name: "Replacing string list", bp: ` my_module_type { name: "foo", defaults: ["bar"], replacing_string_list: select(soong_config_variable("my_namespace", "my_variable"), { "a": ["a1"], default: ["b1"], }), } my_defaults { name: "bar", replacing_string_list: select(soong_config_variable("my_namespace", "my_variable2"), { "a": ["a2"], default: ["b2"], }), } `, provider: selectsTestProvider{ replacing_string_list: &[]string{"b1"}, }, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { fixtures := GroupFixturePreparers( PrepareForTestWithDefaults, PrepareForTestWithArchMutator, FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.RegisterModuleType("my_module_type", newSelectsMockModule) ctx.RegisterModuleType("my_defaults", newSelectsMockModuleDefaults) }), FixtureModifyProductVariables(func(variables FixtureProductVariables) { variables.VendorVars = tc.vendorVars Loading @@ -402,6 +450,7 @@ type selectsTestProvider struct { my_string *string my_string_list *[]string my_paths *[]string replacing_string_list *[]string } func (p *selectsTestProvider) String() string { Loading @@ -418,7 +467,8 @@ func (p *selectsTestProvider) String() string { my_string: %s, my_string_list: %s, my_paths: %s, }`, myBoolStr, myStringStr, p.my_string_list, p.my_paths) replacing_string_list %s, }`, myBoolStr, myStringStr, p.my_string_list, p.my_paths, p.replacing_string_list) } var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]() Loading @@ -428,6 +478,7 @@ type selectsMockModuleProperties struct { My_string proptools.Configurable[string] My_string_list proptools.Configurable[[]string] My_paths proptools.Configurable[[]string] `android:"path"` Replacing_string_list proptools.Configurable[[]string] `android:"replace_instead_of_append,arch_variant"` } type selectsMockModule struct { Loading @@ -438,10 +489,11 @@ type selectsMockModule struct { func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) { SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{ my_bool: p.properties.My_bool.Evaluate(ctx), my_string: p.properties.My_string.Evaluate(ctx), my_string_list: p.properties.My_string_list.Evaluate(ctx), my_paths: p.properties.My_paths.Evaluate(ctx), 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), }) } Loading @@ -452,3 +504,23 @@ func newSelectsMockModule() Module { InitDefaultableModule(m) return m } type selectsMockModuleDefaults struct { ModuleBase DefaultsModuleBase } func (d *selectsMockModuleDefaults) GenerateAndroidBuildActions(ctx ModuleContext) { } func newSelectsMockModuleDefaults() Module { module := &selectsMockModuleDefaults{} module.AddProperties( &selectsMockModuleProperties{}, ) InitDefaultsModule(module) return module } Loading
android/arch.go +1 −1 Original line number Diff line number Diff line Loading @@ -980,7 +980,7 @@ func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.S panic(fmt.Errorf("unexpected tag format %q", field.Tag)) } // these tags don't need to be present in the runtime generated struct type. values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path"}) values = RemoveListFromList(values, []string{"arch_variant", "variant_prepend", "path", "replace_instead_of_append"}) if len(values) > 0 { panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name)) } Loading
android/path_properties.go +2 −2 Original line number Diff line number Diff line Loading @@ -109,9 +109,9 @@ func pathPropertiesForPropertyStruct(ctx BottomUpMutatorContext, ps interface{}) case reflect.Struct: intf := sv.Interface() if configurable, ok := intf.(proptools.Configurable[string]); ok { ret = append(ret, proptools.String(configurable.Evaluate(ctx))) ret = append(ret, configurable.GetOrDefault(ctx, "")) } else if configurable, ok := intf.(proptools.Configurable[[]string]); ok { ret = append(ret, proptools.Slice(configurable.Evaluate(ctx))...) ret = append(ret, configurable.GetOrDefault(ctx, nil)...) } else { panic(fmt.Errorf(`field %s in type %s has tag android:"path" but is not a string or slice of strings, it is a %s`, v.Type().FieldByIndex(i).Name, v.Type(), sv.Type())) Loading
android/selects_test.go +85 −13 Original line number Diff line number Diff line Loading @@ -368,14 +368,62 @@ func TestSelects(t *testing.T) { my_bool: proptools.BoolPtr(true), }, }, { name: "defaults with lists are appended", bp: ` my_module_type { name: "foo", defaults: ["bar"], my_string_list: select(soong_config_variable("my_namespace", "my_variable"), { "a": ["a1"], default: ["b1"], }), } my_defaults { name: "bar", my_string_list: select(soong_config_variable("my_namespace", "my_variable2"), { "a": ["a2"], default: ["b2"], }), } `, provider: selectsTestProvider{ my_string_list: &[]string{"b2", "b1"}, }, }, { name: "Replacing string list", bp: ` my_module_type { name: "foo", defaults: ["bar"], replacing_string_list: select(soong_config_variable("my_namespace", "my_variable"), { "a": ["a1"], default: ["b1"], }), } my_defaults { name: "bar", replacing_string_list: select(soong_config_variable("my_namespace", "my_variable2"), { "a": ["a2"], default: ["b2"], }), } `, provider: selectsTestProvider{ replacing_string_list: &[]string{"b1"}, }, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { fixtures := GroupFixturePreparers( PrepareForTestWithDefaults, PrepareForTestWithArchMutator, FixtureRegisterWithContext(func(ctx RegistrationContext) { ctx.RegisterModuleType("my_module_type", newSelectsMockModule) ctx.RegisterModuleType("my_defaults", newSelectsMockModuleDefaults) }), FixtureModifyProductVariables(func(variables FixtureProductVariables) { variables.VendorVars = tc.vendorVars Loading @@ -402,6 +450,7 @@ type selectsTestProvider struct { my_string *string my_string_list *[]string my_paths *[]string replacing_string_list *[]string } func (p *selectsTestProvider) String() string { Loading @@ -418,7 +467,8 @@ func (p *selectsTestProvider) String() string { my_string: %s, my_string_list: %s, my_paths: %s, }`, myBoolStr, myStringStr, p.my_string_list, p.my_paths) replacing_string_list %s, }`, myBoolStr, myStringStr, p.my_string_list, p.my_paths, p.replacing_string_list) } var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]() Loading @@ -428,6 +478,7 @@ type selectsMockModuleProperties struct { My_string proptools.Configurable[string] My_string_list proptools.Configurable[[]string] My_paths proptools.Configurable[[]string] `android:"path"` Replacing_string_list proptools.Configurable[[]string] `android:"replace_instead_of_append,arch_variant"` } type selectsMockModule struct { Loading @@ -438,10 +489,11 @@ type selectsMockModule struct { func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) { SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{ my_bool: p.properties.My_bool.Evaluate(ctx), my_string: p.properties.My_string.Evaluate(ctx), my_string_list: p.properties.My_string_list.Evaluate(ctx), my_paths: p.properties.My_paths.Evaluate(ctx), 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), }) } Loading @@ -452,3 +504,23 @@ func newSelectsMockModule() Module { InitDefaultableModule(m) return m } type selectsMockModuleDefaults struct { ModuleBase DefaultsModuleBase } func (d *selectsMockModuleDefaults) GenerateAndroidBuildActions(ctx ModuleContext) { } func newSelectsMockModuleDefaults() Module { module := &selectsMockModuleDefaults{} module.AddProperties( &selectsMockModuleProperties{}, ) InitDefaultsModule(module) return module }