Make prefer32 a lambda

prefer32 needs to be set differently for app and native modules.
Make it use lambda provided by the module type instead of trying
to make archMutator figure it out.

Test: m checkbuild
Change-Id: Ibf8af35fdd3e1721725539d1f5452f4439d2125c
This commit is contained in:
Colin Cross
2018-10-02 13:59:46 -07:00
parent 5eca7cb229
commit a9d8bee9f3
4 changed files with 26 additions and 7 deletions

View File

@@ -329,14 +329,12 @@ func archMutator(mctx BottomUpMutatorContext) {
if multilib == "" {
multilib = base.commonProperties.Default_multilib
}
var prefer32 bool
switch class {
case Device:
prefer32 = mctx.Config().DevicePrefer32BitExecutables()
case HostCross:
// Windows builds always prefer 32-bit
prefer32 = true
prefer32 := false
if base.prefer32 != nil {
prefer32 = base.prefer32(mctx, base, class)
}
targets, err := decodeMultilib(multilib, classTargets, prefer32)
if err != nil {
mctx.ModuleErrorf("%s", err.Error())

View File

@@ -442,6 +442,8 @@ type ModuleBase struct {
// For tests
buildParams []BuildParams
prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool
}
func (a *ModuleBase) AddProperties(props ...interface{}) {
@@ -456,6 +458,10 @@ func (a *ModuleBase) BuildParamsForTests() []BuildParams {
return a.buildParams
}
func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) {
a.prefer32 = prefer32
}
// Name returns the name of the module. It may be overridden by individual module types, for
// example prebuilts will prepend prebuilt_ to the name.
func (a *ModuleBase) Name() string {

View File

@@ -406,6 +406,17 @@ func (c *Module) Init() android.Module {
c.AddProperties(feature.props()...)
}
c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
switch class {
case android.Device:
return ctx.Config().DevicePrefer32BitExecutables()
case android.HostCross:
// Windows builds always prefer 32-bit
return true
default:
return false
}
})
android.InitAndroidArchModule(c, c.hod, c.multilib)
android.InitDefaultableModule(c)

View File

@@ -208,6 +208,10 @@ func AndroidAppFactory() android.Module {
&module.aaptProperties,
&module.appProperties)
module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
return class == android.Device && ctx.Config().DevicePrefer32BitApps()
})
InitJavaModule(module, android.DeviceSupported)
return module
}