Merge "Fix binaries and symlinks for prefer32"

am: 9fdbbb3c54

Change-Id: Id8ae0404be8a3ce3dfde2f20ecd0404de16146e7
This commit is contained in:
Colin Cross
2016-09-13 19:56:07 +00:00
committed by android-build-merger
3 changed files with 52 additions and 19 deletions

View File

@@ -274,6 +274,7 @@ func ArchMutator(mctx BottomUpMutatorContext) {
} }
var moduleTargets []Target var moduleTargets []Target
primaryModules := make(map[int]bool)
for _, class := range osClasses { for _, class := range osClasses {
targets := mctx.AConfig().Targets[class] targets := mctx.AConfig().Targets[class]
@@ -293,12 +294,19 @@ func ArchMutator(mctx BottomUpMutatorContext) {
if multilib == "" { if multilib == "" {
multilib = module.base().commonProperties.Default_multilib multilib = module.base().commonProperties.Default_multilib
} }
targets, err := decodeMultilib(multilib, targets) prefer32 := false
if class == Device {
prefer32 = mctx.AConfig().DevicePrefer32BitExecutables()
}
targets, err := decodeMultilib(multilib, targets, prefer32)
if err != nil { if err != nil {
mctx.ModuleErrorf("%s", err.Error()) mctx.ModuleErrorf("%s", err.Error())
} }
if len(targets) > 0 {
primaryModules[len(moduleTargets)] = true
moduleTargets = append(moduleTargets, targets...) moduleTargets = append(moduleTargets, targets...)
} }
}
if len(moduleTargets) == 0 { if len(moduleTargets) == 0 {
module.base().commonProperties.Enabled = boolPtr(false) module.base().commonProperties.Enabled = boolPtr(false)
@@ -313,7 +321,7 @@ func ArchMutator(mctx BottomUpMutatorContext) {
modules := mctx.CreateVariations(targetNames...) modules := mctx.CreateVariations(targetNames...)
for i, m := range modules { for i, m := range modules {
m.(Module).base().SetTarget(moduleTargets[i]) m.(Module).base().SetTarget(moduleTargets[i], primaryModules[i])
m.(Module).base().setArchProperties(mctx) m.(Module).base().setArchProperties(mctx)
} }
} }
@@ -915,15 +923,26 @@ func filterMultilibTargets(targets []Target, multilib string) []Target {
} }
// Use the module multilib setting to select one or more targets from a target list // Use the module multilib setting to select one or more targets from a target list
func decodeMultilib(multilib string, targets []Target) ([]Target, error) { func decodeMultilib(multilib string, targets []Target, prefer32 bool) ([]Target, error) {
buildTargets := []Target{} buildTargets := []Target{}
if multilib == "first" {
if prefer32 {
multilib = "prefer32"
} else {
multilib = "prefer64"
}
}
switch multilib { switch multilib {
case "common": case "common":
buildTargets = append(buildTargets, commonTarget) buildTargets = append(buildTargets, commonTarget)
case "both": case "both":
buildTargets = append(buildTargets, targets...) if prefer32 {
case "first": buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
buildTargets = append(buildTargets, targets[0]) buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
} else {
buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib64")...)
buildTargets = append(buildTargets, filterMultilibTargets(targets, "lib32")...)
}
case "32": case "32":
buildTargets = filterMultilibTargets(targets, "lib32") buildTargets = filterMultilibTargets(targets, "lib32")
case "64": case "64":
@@ -933,6 +952,11 @@ func decodeMultilib(multilib string, targets []Target) ([]Target, error) {
if len(buildTargets) == 0 { if len(buildTargets) == 0 {
buildTargets = filterMultilibTargets(targets, "lib64") buildTargets = filterMultilibTargets(targets, "lib64")
} }
case "prefer64":
buildTargets = filterMultilibTargets(targets, "lib64")
if len(buildTargets) == 0 {
buildTargets = filterMultilibTargets(targets, "lib32")
}
default: default:
return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`, return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", "64", or "prefer32" found %q`,
multilib) multilib)

View File

@@ -57,6 +57,7 @@ type ModuleBuildParams struct {
type androidBaseContext interface { type androidBaseContext interface {
Target() Target Target() Target
TargetPrimary() bool
Arch() Arch Arch() Arch
Os() OsType Os() OsType
Host() bool Host() bool
@@ -146,6 +147,7 @@ type commonProperties struct {
// Set by TargetMutator // Set by TargetMutator
CompileTarget Target `blueprint:"mutated"` CompileTarget Target `blueprint:"mutated"`
CompilePrimary bool `blueprint:"mutated"`
// Set by InitAndroidModule // Set by InitAndroidModule
HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
@@ -282,14 +284,19 @@ func (a *ModuleBase) base() *ModuleBase {
return a return a
} }
func (a *ModuleBase) SetTarget(target Target) { func (a *ModuleBase) SetTarget(target Target, primary bool) {
a.commonProperties.CompileTarget = target a.commonProperties.CompileTarget = target
a.commonProperties.CompilePrimary = primary
} }
func (a *ModuleBase) Target() Target { func (a *ModuleBase) Target() Target {
return a.commonProperties.CompileTarget return a.commonProperties.CompileTarget
} }
func (a *ModuleBase) TargetPrimary() bool {
return a.commonProperties.CompilePrimary
}
func (a *ModuleBase) Os() OsType { func (a *ModuleBase) Os() OsType {
return a.Target().Os return a.Target().Os
} }
@@ -421,6 +428,7 @@ func (a *ModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl { func (a *ModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
return androidBaseContextImpl{ return androidBaseContextImpl{
target: a.commonProperties.CompileTarget, target: a.commonProperties.CompileTarget,
targetPrimary: a.commonProperties.CompilePrimary,
config: ctx.Config().(Config), config: ctx.Config().(Config),
} }
} }
@@ -455,6 +463,7 @@ func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
type androidBaseContextImpl struct { type androidBaseContextImpl struct {
target Target target Target
targetPrimary bool
debug bool debug bool
config Config config Config
} }
@@ -536,6 +545,10 @@ func (a *androidBaseContextImpl) Target() Target {
return a.target return a.target
} }
func (a *androidBaseContextImpl) TargetPrimary() bool {
return a.targetPrimary
}
func (a *androidBaseContextImpl) Arch() Arch { func (a *androidBaseContextImpl) Arch() Arch {
return a.target.Arch return a.target.Arch
} }

View File

@@ -170,11 +170,7 @@ func (binary *binaryDecorator) linkerInit(ctx BaseModuleContext) {
if binary.Properties.Stem == "" && binary.Properties.Suffix == "" { if binary.Properties.Stem == "" && binary.Properties.Suffix == "" {
ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix") ctx.PropertyErrorf("symlink_preferred_arch", "must also specify stem or suffix")
} }
prefer32 := false if ctx.TargetPrimary() {
if ctx.Device() {
prefer32 = ctx.AConfig().DevicePrefer32BitExecutables()
}
if ctx.PrimaryArch() != prefer32 {
binary.baseInstaller.Properties.Symlinks = append(binary.baseInstaller.Properties.Symlinks, binary.baseInstaller.Properties.Symlinks = append(binary.baseInstaller.Properties.Symlinks,
ctx.ModuleName()) ctx.ModuleName())
} }