Add the ability to select on arch
Bug: 323382414 Test: go test Change-Id: I0d4cf391a1a625c5160456db1f4f7fa424c2141e
This commit is contained in:
@@ -693,6 +693,7 @@ func addTargetProperties(m Module, target Target, multiTargets []Target, primary
|
|||||||
m.base().commonProperties.CompileTarget = target
|
m.base().commonProperties.CompileTarget = target
|
||||||
m.base().commonProperties.CompileMultiTargets = multiTargets
|
m.base().commonProperties.CompileMultiTargets = multiTargets
|
||||||
m.base().commonProperties.CompilePrimary = primaryTarget
|
m.base().commonProperties.CompilePrimary = primaryTarget
|
||||||
|
m.base().commonProperties.ArchReady = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// decodeMultilib returns the appropriate compile_multilib property for the module, or the default
|
// decodeMultilib returns the appropriate compile_multilib property for the module, or the default
|
||||||
|
@@ -35,6 +35,7 @@ type ArchModuleContext interface {
|
|||||||
type archModuleContext struct {
|
type archModuleContext struct {
|
||||||
// TODO: these should eventually go through a (possibly cached) provider like any other configuration instead
|
// TODO: these should eventually go through a (possibly cached) provider like any other configuration instead
|
||||||
// of being special cased.
|
// of being special cased.
|
||||||
|
ready bool
|
||||||
os OsType
|
os OsType
|
||||||
target Target
|
target Target
|
||||||
targetPrimary bool
|
targetPrimary bool
|
||||||
@@ -42,6 +43,13 @@ type archModuleContext struct {
|
|||||||
primaryArch bool
|
primaryArch bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArchReady returns true if the arch mutator has run on the module. Before this returns
|
||||||
|
// true, the module essentially doesn't have an arch and cannot make decisions based on
|
||||||
|
// architecture.
|
||||||
|
func (a *archModuleContext) ArchReady() bool {
|
||||||
|
return a.ready
|
||||||
|
}
|
||||||
|
|
||||||
func (a *archModuleContext) Target() Target {
|
func (a *archModuleContext) Target() Target {
|
||||||
return a.target
|
return a.target
|
||||||
}
|
}
|
||||||
|
@@ -599,7 +599,14 @@ func (m *baseModuleContext) EvaluateConfiguration(ty parser.SelectType, conditio
|
|||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
case parser.SelectTypeVariant:
|
case parser.SelectTypeVariant:
|
||||||
m.ModuleErrorf("TODO(b/323382414): Variants are not yet supported in selects")
|
if condition == "arch" {
|
||||||
|
if !m.ArchReady() {
|
||||||
|
m.ModuleErrorf("A select on arch was attempted before the arch mutator ran")
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return m.Arch().ArchType.Name, true
|
||||||
|
}
|
||||||
|
m.ModuleErrorf("Unknown variant " + condition)
|
||||||
return "", false
|
return "", false
|
||||||
default:
|
default:
|
||||||
panic("Should be unreachable")
|
panic("Should be unreachable")
|
||||||
|
@@ -433,6 +433,10 @@ type commonProperties struct {
|
|||||||
// Set by osMutator
|
// Set by osMutator
|
||||||
CompileOS OsType `blueprint:"mutated"`
|
CompileOS OsType `blueprint:"mutated"`
|
||||||
|
|
||||||
|
// Set to true after the arch mutator has run on this module and set CompileTarget,
|
||||||
|
// CompileMultiTargets, and CompilePrimary
|
||||||
|
ArchReady bool `blueprint:"mutated"`
|
||||||
|
|
||||||
// The Target of artifacts that this module variant is responsible for creating.
|
// The Target of artifacts that this module variant is responsible for creating.
|
||||||
//
|
//
|
||||||
// Set by archMutator
|
// Set by archMutator
|
||||||
@@ -1749,6 +1753,7 @@ func (m *ModuleBase) archModuleContextFactory(ctx blueprint.IncomingTransitionCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
return archModuleContext{
|
return archModuleContext{
|
||||||
|
ready: m.commonProperties.ArchReady,
|
||||||
os: m.commonProperties.CompileOS,
|
os: m.commonProperties.CompileOS,
|
||||||
target: m.commonProperties.CompileTarget,
|
target: m.commonProperties.CompileTarget,
|
||||||
targetPrimary: m.commonProperties.CompilePrimary,
|
targetPrimary: m.commonProperties.CompilePrimary,
|
||||||
|
@@ -231,11 +231,30 @@ func TestSelects(t *testing.T) {
|
|||||||
my_string: proptools.StringPtr("c.cpp"),
|
my_string: proptools.StringPtr("c.cpp"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Select on variant",
|
||||||
|
bp: `
|
||||||
|
my_module_type {
|
||||||
|
name: "foo",
|
||||||
|
my_string: select(variant("arch"), {
|
||||||
|
"x86": "my_x86",
|
||||||
|
"x86_64": "my_x86_64",
|
||||||
|
"arm": "my_arm",
|
||||||
|
"arm64": "my_arm64",
|
||||||
|
_: "my_default",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
provider: selectsTestProvider{
|
||||||
|
my_string: proptools.StringPtr("my_arm64"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
||||||
|
PrepareForTestWithArchMutator,
|
||||||
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
FixtureRegisterWithContext(func(ctx RegistrationContext) {
|
||||||
ctx.RegisterModuleType("my_module_type", newSelectsMockModule)
|
ctx.RegisterModuleType("my_module_type", newSelectsMockModule)
|
||||||
}),
|
}),
|
||||||
@@ -249,8 +268,8 @@ 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", "")
|
m := result.ModuleForTests("foo", "android_arm64_armv8-a")
|
||||||
p, _ := OtherModuleProvider[selectsTestProvider](result.testContext.OtherModuleProviderAdaptor(), m.Module(), selectsTestProviderKey)
|
p, _ := OtherModuleProvider(result.testContext.OtherModuleProviderAdaptor(), m.Module(), selectsTestProviderKey)
|
||||||
if !reflect.DeepEqual(p, tc.provider) {
|
if !reflect.DeepEqual(p, tc.provider) {
|
||||||
t.Errorf("Expected:\n %q\ngot:\n %q", tc.provider.String(), p.String())
|
t.Errorf("Expected:\n %q\ngot:\n %q", tc.provider.String(), p.String())
|
||||||
}
|
}
|
||||||
@@ -310,7 +329,7 @@ func (p *selectsMockModule) GenerateAndroidBuildActions(ctx ModuleContext) {
|
|||||||
func newSelectsMockModule() Module {
|
func newSelectsMockModule() Module {
|
||||||
m := &selectsMockModule{}
|
m := &selectsMockModule{}
|
||||||
m.AddProperties(&m.properties)
|
m.AddProperties(&m.properties)
|
||||||
InitAndroidArchModule(m, HostAndDeviceSupported, MultilibCommon)
|
InitAndroidArchModule(m, HostAndDeviceSupported, MultilibFirst)
|
||||||
InitDefaultableModule(m)
|
InitDefaultableModule(m)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user