Change the syntax for arch selecting and add os selecting
This changes the syntax from select(variant("arch"), {...}) to select(arch(), {...}) to make it shorter and to make it clear that we can restrict what variants you can select on. Bug: 323382414 Test: m nothing --no-skip-soong-tests Change-Id: Iafe05b5f455895313a563ed6292f4016b58180b0
This commit is contained in:
parent
fdbf5d476b
commit
fc57d40bf1
2 changed files with 36 additions and 13 deletions
|
@ -2169,20 +2169,27 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
case "variant":
|
case "arch":
|
||||||
if len(condition.Args) != 1 {
|
if len(condition.Args) != 0 {
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "variant requires 1 argument, found %d", len(condition.Args))
|
ctx.OtherModulePropertyErrorf(m, property, "arch requires no arguments, found %d", len(condition.Args))
|
||||||
return proptools.ConfigurableValueUndefined()
|
return proptools.ConfigurableValueUndefined()
|
||||||
}
|
}
|
||||||
if condition.Args[0] == "arch" {
|
if !m.base().ArchReady() {
|
||||||
if !m.base().ArchReady() {
|
ctx.OtherModulePropertyErrorf(m, property, "A select on arch was attempted before the arch mutator ran")
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "A select on arch was attempted before the arch mutator ran")
|
return proptools.ConfigurableValueUndefined()
|
||||||
return proptools.ConfigurableValueUndefined()
|
|
||||||
}
|
|
||||||
return proptools.ConfigurableValueString(m.base().Arch().ArchType.Name)
|
|
||||||
}
|
}
|
||||||
ctx.OtherModulePropertyErrorf(m, property, "Unknown variant %s", condition.Args[0])
|
return proptools.ConfigurableValueString(m.base().Arch().ArchType.Name)
|
||||||
return proptools.ConfigurableValueUndefined()
|
case "os":
|
||||||
|
if len(condition.Args) != 0 {
|
||||||
|
ctx.OtherModulePropertyErrorf(m, property, "os requires no arguments, found %d", len(condition.Args))
|
||||||
|
return proptools.ConfigurableValueUndefined()
|
||||||
|
}
|
||||||
|
// the arch mutator runs after the os mutator, we can just use this to enforce that os is ready.
|
||||||
|
if !m.base().ArchReady() {
|
||||||
|
ctx.OtherModulePropertyErrorf(m, property, "A select on os was attempted before the arch mutator ran (arch runs after os, we use it to lazily detect that os is ready)")
|
||||||
|
return proptools.ConfigurableValueUndefined()
|
||||||
|
}
|
||||||
|
return proptools.ConfigurableValueString(m.base().Os().Name)
|
||||||
case "boolean_var_for_testing":
|
case "boolean_var_for_testing":
|
||||||
// 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
|
||||||
|
|
|
@ -269,11 +269,11 @@ func TestSelects(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Select on variant",
|
name: "Select on arch",
|
||||||
bp: `
|
bp: `
|
||||||
my_module_type {
|
my_module_type {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
my_string: select(variant("arch"), {
|
my_string: select(arch(), {
|
||||||
"x86": "my_x86",
|
"x86": "my_x86",
|
||||||
"x86_64": "my_x86_64",
|
"x86_64": "my_x86_64",
|
||||||
"arm": "my_arm",
|
"arm": "my_arm",
|
||||||
|
@ -286,6 +286,22 @@ func TestSelects(t *testing.T) {
|
||||||
my_string: proptools.StringPtr("my_arm64"),
|
my_string: proptools.StringPtr("my_arm64"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Select on os",
|
||||||
|
bp: `
|
||||||
|
my_module_type {
|
||||||
|
name: "foo",
|
||||||
|
my_string: select(os(), {
|
||||||
|
"android": "my_android",
|
||||||
|
"linux": "my_linux",
|
||||||
|
default: "my_default",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
provider: selectsTestProvider{
|
||||||
|
my_string: proptools.StringPtr("my_android"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "Unset value",
|
name: "Unset value",
|
||||||
bp: `
|
bp: `
|
||||||
|
|
Loading…
Reference in a new issue