Merge changes from topics "replace_instead_of_append", "selects_get_and_get_default" into main
* changes: Rename Evaluate() to Get() and add GetDefault() Add tests for android:replace_instead_of_append
This commit is contained in:
@@ -980,7 +980,7 @@ func filterArchStruct(field reflect.StructField, prefix string) (bool, reflect.S
|
|||||||
panic(fmt.Errorf("unexpected tag format %q", field.Tag))
|
panic(fmt.Errorf("unexpected tag format %q", field.Tag))
|
||||||
}
|
}
|
||||||
// these tags don't need to be present in the runtime generated struct type.
|
// 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 {
|
if len(values) > 0 {
|
||||||
panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name))
|
panic(fmt.Errorf("unknown tags %q in field %q", values, prefix+field.Name))
|
||||||
}
|
}
|
||||||
|
@@ -109,9 +109,9 @@ func pathPropertiesForPropertyStruct(ctx BottomUpMutatorContext, ps interface{})
|
|||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
intf := sv.Interface()
|
intf := sv.Interface()
|
||||||
if configurable, ok := intf.(proptools.Configurable[string]); ok {
|
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 {
|
} 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 {
|
} 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`,
|
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()))
|
v.Type().FieldByIndex(i).Name, v.Type(), sv.Type()))
|
||||||
|
@@ -368,14 +368,62 @@ func TestSelects(t *testing.T) {
|
|||||||
my_bool: proptools.BoolPtr(true),
|
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 {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
fixtures := GroupFixturePreparers(
|
fixtures := GroupFixturePreparers(
|
||||||
|
PrepareForTestWithDefaults,
|
||||||
PrepareForTestWithArchMutator,
|
PrepareForTestWithArchMutator,
|
||||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||||
ctx.RegisterModuleType("my_module_type", newSelectsMockModule)
|
ctx.RegisterModuleType("my_module_type", newSelectsMockModule)
|
||||||
|
ctx.RegisterModuleType("my_defaults", newSelectsMockModuleDefaults)
|
||||||
}),
|
}),
|
||||||
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
FixtureModifyProductVariables(func(variables FixtureProductVariables) {
|
||||||
variables.VendorVars = tc.vendorVars
|
variables.VendorVars = tc.vendorVars
|
||||||
@@ -398,10 +446,11 @@ func TestSelects(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type selectsTestProvider struct {
|
type selectsTestProvider struct {
|
||||||
my_bool *bool
|
my_bool *bool
|
||||||
my_string *string
|
my_string *string
|
||||||
my_string_list *[]string
|
my_string_list *[]string
|
||||||
my_paths *[]string
|
my_paths *[]string
|
||||||
|
replacing_string_list *[]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *selectsTestProvider) String() string {
|
func (p *selectsTestProvider) String() string {
|
||||||
@@ -418,16 +467,18 @@ func (p *selectsTestProvider) String() string {
|
|||||||
my_string: %s,
|
my_string: %s,
|
||||||
my_string_list: %s,
|
my_string_list: %s,
|
||||||
my_paths: %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]()
|
var selectsTestProviderKey = blueprint.NewProvider[selectsTestProvider]()
|
||||||
|
|
||||||
type selectsMockModuleProperties struct {
|
type selectsMockModuleProperties struct {
|
||||||
My_bool proptools.Configurable[bool]
|
My_bool proptools.Configurable[bool]
|
||||||
My_string proptools.Configurable[string]
|
My_string proptools.Configurable[string]
|
||||||
My_string_list proptools.Configurable[[]string]
|
My_string_list proptools.Configurable[[]string]
|
||||||
My_paths proptools.Configurable[[]string] `android:"path"`
|
My_paths proptools.Configurable[[]string] `android:"path"`
|
||||||
|
Replacing_string_list proptools.Configurable[[]string] `android:"replace_instead_of_append,arch_variant"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type selectsMockModule struct {
|
type selectsMockModule struct {
|
||||||
@@ -438,10 +489,11 @@ type selectsMockModule struct {
|
|||||||
|
|
||||||
func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
||||||
SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{
|
SetProvider(ctx, selectsTestProviderKey, selectsTestProvider{
|
||||||
my_bool: p.properties.My_bool.Evaluate(ctx),
|
my_bool: p.properties.My_bool.Get(ctx),
|
||||||
my_string: p.properties.My_string.Evaluate(ctx),
|
my_string: p.properties.My_string.Get(ctx),
|
||||||
my_string_list: p.properties.My_string_list.Evaluate(ctx),
|
my_string_list: p.properties.My_string_list.Get(ctx),
|
||||||
my_paths: p.properties.My_paths.Evaluate(ctx),
|
my_paths: p.properties.My_paths.Get(ctx),
|
||||||
|
replacing_string_list: p.properties.Replacing_string_list.Get(ctx),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,3 +504,23 @@ func newSelectsMockModule() Module {
|
|||||||
InitDefaultableModule(m)
|
InitDefaultableModule(m)
|
||||||
return 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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user