Add tests for configurable PostProcessors

Bug: 362579941
Test: m nothing --no-skip-soong-tests
Change-Id: Iaaff66844ebe0b2fb19148bd07562785b12cd7e9
This commit is contained in:
Cole Faust 2024-08-29 15:36:15 -07:00 committed by Bartłomiej Rudecki
parent 77b84c1f56
commit 1d86a7f5e8
Signed by: przekichane
GPG key ID: 751F23C6F014EF76

View file

@ -1009,6 +1009,28 @@ my_module_type {
},
expectedError: `variable already set in inherited scope, previous assignment:`,
},
{
name: "Basic string list postprocessor",
bp: `
my_defaults {
name: "defaults_a",
my_string_list: ["a", "b", "c"],
string_list_postprocessor_add_to_elements: "1",
}
my_defaults {
name: "defaults_b",
my_string_list: ["d", "e", "f"],
string_list_postprocessor_add_to_elements: "2",
}
my_module_type {
name: "foo",
defaults: ["defaults_a", "defaults_b"],
}
`,
provider: selectsTestProvider{
my_string_list: &[]string{"d2", "e2", "f2", "a1", "b1", "c1"},
},
},
}
for _, tc := range testCases {
@ -1161,9 +1183,15 @@ func newSelectsMockModule() Module {
return m
}
type selectsMockDefaultsProperties struct {
String_list_postprocessor_add_to_elements string
}
type selectsMockModuleDefaults struct {
ModuleBase
DefaultsModuleBase
myProperties selectsMockModuleProperties
defaultsProperties selectsMockDefaultsProperties
}
func (d *selectsMockModuleDefaults) GenerateAndroidBuildActions(ctx ModuleContext) {
@ -1173,10 +1201,22 @@ func newSelectsMockModuleDefaults() Module {
module := &selectsMockModuleDefaults{}
module.AddProperties(
&selectsMockModuleProperties{},
&module.myProperties,
&module.defaultsProperties,
)
InitDefaultsModule(module)
AddLoadHook(module, func(lhc LoadHookContext) {
if module.defaultsProperties.String_list_postprocessor_add_to_elements != "" {
module.myProperties.My_string_list.AddPostProcessor(func(x []string) []string {
for i := range x {
x[i] = x[i] + module.defaultsProperties.String_list_postprocessor_add_to_elements
}
return x
})
}
})
return module
}