Merge changes from topics "fix_selects_appending", "refactor_selects" into main
* changes: Update accesses to ConfigurableCondition Add test for configurable defaults applied to multiple modules
This commit is contained in:
@@ -2142,13 +2142,13 @@ func (e configurationEvalutor) PropertyErrorf(property string, fmt string, args
|
|||||||
func (e configurationEvalutor) EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue {
|
func (e configurationEvalutor) EvaluateConfiguration(condition proptools.ConfigurableCondition, property string) proptools.ConfigurableValue {
|
||||||
ctx := e.ctx
|
ctx := e.ctx
|
||||||
m := e.m
|
m := e.m
|
||||||
switch condition.FunctionName {
|
switch condition.FunctionName() {
|
||||||
case "release_variable":
|
case "release_variable":
|
||||||
if len(condition.Args) != 1 {
|
if condition.NumArgs() != 1 {
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "release_variable requires 1 argument, found %d", len(condition.Args))
|
ctx.OtherModulePropertyErrorf(m, property, "release_variable requires 1 argument, found %d", condition.NumArgs())
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
}
|
}
|
||||||
if v, ok := ctx.Config().productVariables.BuildFlags[condition.Args[0]]; ok {
|
if v, ok := ctx.Config().productVariables.BuildFlags[condition.Arg(0)]; ok {
|
||||||
return proptools.ConfigurableValueString(v)
|
return proptools.ConfigurableValueString(v)
|
||||||
}
|
}
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
@@ -2157,12 +2157,12 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
|
|||||||
ctx.OtherModulePropertyErrorf(m, property, "TODO(b/323382414): Product variables are not yet supported in selects")
|
ctx.OtherModulePropertyErrorf(m, property, "TODO(b/323382414): Product variables are not yet supported in selects")
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
case "soong_config_variable":
|
case "soong_config_variable":
|
||||||
if len(condition.Args) != 2 {
|
if condition.NumArgs() != 2 {
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "soong_config_variable requires 2 arguments, found %d", len(condition.Args))
|
ctx.OtherModulePropertyErrorf(m, property, "soong_config_variable requires 2 arguments, found %d", condition.NumArgs())
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
}
|
}
|
||||||
namespace := condition.Args[0]
|
namespace := condition.Arg(0)
|
||||||
variable := condition.Args[1]
|
variable := condition.Arg(1)
|
||||||
if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
|
if n, ok := ctx.Config().productVariables.VendorVars[namespace]; ok {
|
||||||
if v, ok := n[variable]; ok {
|
if v, ok := n[variable]; ok {
|
||||||
return proptools.ConfigurableValueString(v)
|
return proptools.ConfigurableValueString(v)
|
||||||
@@ -2170,8 +2170,8 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
|
|||||||
}
|
}
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
case "arch":
|
case "arch":
|
||||||
if len(condition.Args) != 0 {
|
if condition.NumArgs() != 0 {
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "arch requires no arguments, found %d", len(condition.Args))
|
ctx.OtherModulePropertyErrorf(m, property, "arch requires no arguments, found %d", condition.NumArgs())
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
}
|
}
|
||||||
if !m.base().ArchReady() {
|
if !m.base().ArchReady() {
|
||||||
@@ -2180,8 +2180,8 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
|
|||||||
}
|
}
|
||||||
return proptools.ConfigurableValueString(m.base().Arch().ArchType.Name)
|
return proptools.ConfigurableValueString(m.base().Arch().ArchType.Name)
|
||||||
case "os":
|
case "os":
|
||||||
if len(condition.Args) != 0 {
|
if condition.NumArgs() != 0 {
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "os requires no arguments, found %d", len(condition.Args))
|
ctx.OtherModulePropertyErrorf(m, property, "os requires no arguments, found %d", condition.NumArgs())
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
}
|
}
|
||||||
// the arch mutator runs after the os mutator, we can just use this to enforce that os is ready.
|
// the arch mutator runs after the os mutator, we can just use this to enforce that os is ready.
|
||||||
@@ -2194,8 +2194,8 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
|
|||||||
// We currently don't have any other boolean variables (we should add support for typing
|
// We currently don't have any other boolean variables (we should add support for typing
|
||||||
// the soong config variables), so add this fake one for testing the boolean select
|
// the soong config variables), so add this fake one for testing the boolean select
|
||||||
// functionality.
|
// functionality.
|
||||||
if len(condition.Args) != 0 {
|
if condition.NumArgs() != 0 {
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "boolean_var_for_testing requires 0 arguments, found %d", len(condition.Args))
|
ctx.OtherModulePropertyErrorf(m, property, "boolean_var_for_testing requires 0 arguments, found %d", condition.NumArgs())
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@ func TestSelects(t *testing.T) {
|
|||||||
name string
|
name string
|
||||||
bp string
|
bp string
|
||||||
provider selectsTestProvider
|
provider selectsTestProvider
|
||||||
|
providers map[string]selectsTestProvider
|
||||||
vendorVars map[string]map[string]string
|
vendorVars map[string]map[string]string
|
||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
@@ -410,6 +411,42 @@ func TestSelects(t *testing.T) {
|
|||||||
my_string_list: &[]string{"b2", "b1"},
|
my_string_list: &[]string{"b2", "b1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "defaults applied to multiple modules",
|
||||||
|
bp: `
|
||||||
|
my_module_type {
|
||||||
|
name: "foo2",
|
||||||
|
defaults: ["bar"],
|
||||||
|
my_string_list: select(soong_config_variable("my_namespace", "my_variable"), {
|
||||||
|
"a": ["a1"],
|
||||||
|
default: ["b1"],
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
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"],
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
providers: map[string]selectsTestProvider{
|
||||||
|
"foo": {
|
||||||
|
my_string_list: &[]string{"b2", "b1"},
|
||||||
|
},
|
||||||
|
"foo2": {
|
||||||
|
my_string_list: &[]string{"b2", "b1"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Replacing string list",
|
name: "Replacing string list",
|
||||||
bp: `
|
bp: `
|
||||||
@@ -617,10 +654,19 @@ func TestSelects(t *testing.T) {
|
|||||||
result := fixtures.RunTestWithBp(t, tc.bp)
|
result := fixtures.RunTestWithBp(t, tc.bp)
|
||||||
|
|
||||||
if tc.expectedError == "" {
|
if tc.expectedError == "" {
|
||||||
m := result.ModuleForTests("foo", "android_arm64_armv8-a")
|
if len(tc.providers) == 0 {
|
||||||
p, _ := OtherModuleProvider(result.testContext.OtherModuleProviderAdaptor(), m.Module(), selectsTestProviderKey)
|
tc.providers = map[string]selectsTestProvider{
|
||||||
if !reflect.DeepEqual(p, tc.provider) {
|
"foo": tc.provider,
|
||||||
t.Errorf("Expected:\n %q\ngot:\n %q", tc.provider.String(), p.String())
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for moduleName := range tc.providers {
|
||||||
|
expected := tc.providers[moduleName]
|
||||||
|
m := result.ModuleForTests(moduleName, "android_arm64_armv8-a")
|
||||||
|
p, _ := OtherModuleProvider(result.testContext.OtherModuleProviderAdaptor(), m.Module(), selectsTestProviderKey)
|
||||||
|
if !reflect.DeepEqual(p, expected) {
|
||||||
|
t.Errorf("Expected:\n %q\ngot:\n %q", expected.String(), p.String())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user