Simplify arch target handling

am: a1ad8d1889

* commit 'a1ad8d1889e81be97b98f19969ed9147094f199c':
  Simplify arch target handling

Change-Id: I540ab5e038c5822ac705c620cc21c100f93544c8
This commit is contained in:
Colin Cross
2016-06-03 03:20:08 +00:00
committed by android-build-merger
19 changed files with 366 additions and 476 deletions

View File

@@ -149,27 +149,21 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
name += "_" + data.SubName name += "_" + data.SubName
} }
hostCross := false
if amod.Host() && amod.HostType() != CurrentHostType() {
hostCross = true
}
if data.Custom != nil { if data.Custom != nil {
prefix := "" prefix := ""
if amod.Host() { switch amod.Os().Class {
if hostCross { case Host:
prefix = "HOST_CROSS_" prefix = "HOST_"
} else { case HostCross:
prefix = "HOST_" prefix = "HOST_CROSS_"
} case Device:
if amod.Arch().ArchType != ctx.Config().(Config).HostArches[amod.HostType()][0].ArchType {
prefix = "2ND_" + prefix
}
} else {
prefix = "TARGET_" prefix = "TARGET_"
if amod.Arch().ArchType != ctx.Config().(Config).DeviceArches[0].ArchType {
prefix = "2ND_" + prefix }
}
config := ctx.Config().(Config)
if amod.Arch().ArchType != config.Targets[amod.Os().Class][0].Arch.ArchType {
prefix = "2ND_" + prefix
} }
return data.Custom(w, name, prefix) return data.Custom(w, name, prefix)
@@ -191,15 +185,15 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String()) fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", data.OutputFile.String())
archStr := amod.Arch().ArchType.String() archStr := amod.Arch().ArchType.String()
if amod.Host() { host := false
if hostCross { switch amod.Os().Class {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr) case Host:
} else { fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr) host = true
} case HostCross:
fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", amod.HostType().String()) fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") host = true
} else { case Device:
fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr) fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
if len(amod.commonProperties.Logtags) > 0 { if len(amod.commonProperties.Logtags) > 0 {
@@ -207,6 +201,11 @@ func translateAndroidMkModule(ctx blueprint.SingletonContext, w io.Writer, mod b
} }
} }
if host {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", amod.Os().String())
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
}
for _, extra := range data.Extra { for _, extra := range data.Extra {
err = extra(w, data.OutputFile.Path()) err = extra(w, data.OutputFile.Path())
if err != nil { if err != nil {

View File

@@ -28,8 +28,6 @@ func init() {
RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator) RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator)
RegisterTopDownMutator("defaults", defaultsMutator) RegisterTopDownMutator("defaults", defaultsMutator)
RegisterBottomUpMutator("host_or_device", HostOrDeviceMutator)
RegisterBottomUpMutator("host_type", HostTypeMutator)
RegisterBottomUpMutator("arch", ArchMutator) RegisterBottomUpMutator("arch", ArchMutator)
} }
@@ -333,75 +331,7 @@ func (a ArchType) String() string {
return a.Name return a.Name
} }
type HostOrDeviceSupported int var BuildOs = func() OsType {
const (
_ HostOrDeviceSupported = iota
HostSupported
DeviceSupported
HostAndDeviceSupported
HostAndDeviceDefault
)
type HostOrDevice int
const (
_ HostOrDevice = iota
Host
Device
)
func (hod HostOrDevice) String() string {
switch hod {
case Device:
return "device"
case Host:
return "host"
default:
panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
}
}
func (hod HostOrDevice) Property() string {
switch hod {
case Device:
return "android"
case Host:
return "host"
default:
panic(fmt.Sprintf("unexpected HostOrDevice value %d", hod))
}
}
func (hod HostOrDevice) Host() bool {
if hod == 0 {
panic("HostOrDevice unset")
}
return hod == Host
}
func (hod HostOrDevice) Device() bool {
if hod == 0 {
panic("HostOrDevice unset")
}
return hod == Device
}
var hostOrDeviceName = map[HostOrDevice]string{
Device: "device",
Host: "host",
}
type HostType int
const (
NoHostType HostType = iota
Linux
Darwin
Windows
)
func CurrentHostType() HostType {
switch runtime.GOOS { switch runtime.GOOS {
case "linux": case "linux":
return Linux return Linux
@@ -410,98 +340,71 @@ func CurrentHostType() HostType {
default: default:
panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS)) panic(fmt.Sprintf("unsupported OS: %s", runtime.GOOS))
} }
}()
var (
osTypeList []OsType
NoOsType OsType
Linux = NewOsType("linux", Host)
Darwin = NewOsType("darwin", Host)
Windows = NewOsType("windows", HostCross)
Android = NewOsType("android", Device)
)
type OsType struct {
Name, Field string
Class OsClass
} }
func (ht HostType) String() string { type OsClass int
switch ht {
case Linux: const (
return "linux" Device OsClass = iota
case Darwin: Host
return "darwin" HostCross
case Windows: )
return "windows"
default: func (os OsType) String() string {
panic(fmt.Sprintf("unexpected HostType value %d", ht)) return os.Name
}
} }
func (ht HostType) Field() string { func NewOsType(name string, class OsClass) OsType {
switch ht { os := OsType{
case Linux: Name: name,
return "Linux" Field: strings.Title(name),
case Darwin: Class: class,
return "Darwin"
case Windows:
return "Windows"
default:
panic(fmt.Sprintf("unexpected HostType value %d", ht))
} }
osTypeList = append(osTypeList, os)
return os
}
func osByName(name string) OsType {
for _, os := range osTypeList {
if os.Name == name {
return os
}
}
return NoOsType
} }
var ( var (
commonArch = Arch{ commonTarget = Target{
ArchType: Common, Os: Android,
Arch: Arch{
ArchType: Common,
},
} }
) )
func HostOrDeviceMutator(mctx BottomUpMutatorContext) { type Target struct {
var module Module Os OsType
var ok bool Arch Arch
if module, ok = mctx.Module().(Module); !ok {
return
}
hods := []HostOrDevice{}
if module.base().HostSupported() {
hods = append(hods, Host)
}
if module.base().DeviceSupported() {
hods = append(hods, Device)
}
if len(hods) == 0 {
return
}
hodNames := []string{}
for _, hod := range hods {
hodNames = append(hodNames, hod.String())
}
modules := mctx.CreateVariations(hodNames...)
for i, m := range modules {
m.(Module).base().SetHostOrDevice(hods[i])
}
} }
func HostTypeMutator(mctx BottomUpMutatorContext) { func (target Target) String() string {
var module Module return target.Os.String() + "_" + target.Arch.String()
var ok bool
if module, ok = mctx.Module().(Module); !ok {
return
}
if !module.base().HostSupported() || !module.base().HostOrDevice().Host() {
return
}
buildTypes, err := decodeHostTypesProductVariables(mctx.Config().(Config).ProductVariables)
if err != nil {
mctx.ModuleErrorf("%s", err.Error())
return
}
typeNames := []string{}
for _, ht := range buildTypes {
typeNames = append(typeNames, ht.String())
}
modules := mctx.CreateVariations(typeNames...)
for i, m := range modules {
m.(Module).base().SetHostType(buildTypes[i])
}
} }
func ArchMutator(mctx BottomUpMutatorContext) { func ArchMutator(mctx BottomUpMutatorContext) {
@@ -511,40 +414,36 @@ func ArchMutator(mctx BottomUpMutatorContext) {
return return
} }
moduleArches := []Arch{} osClasses := module.base().OsClassSupported()
multilib := module.base().commonProperties.Compile_multilib
if module.base().HostSupported() && module.base().HostOrDevice().Host() { if len(osClasses) == 0 {
hostModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).HostArches[module.base().HostType()])
if err != nil {
mctx.ModuleErrorf("%s", err.Error())
}
moduleArches = append(moduleArches, hostModuleArches...)
}
if module.base().DeviceSupported() && module.base().HostOrDevice().Device() {
deviceModuleArches, err := decodeMultilib(multilib, mctx.Config().(Config).DeviceArches)
if err != nil {
mctx.ModuleErrorf("%s", err.Error())
}
moduleArches = append(moduleArches, deviceModuleArches...)
}
if len(moduleArches) == 0 {
return return
} }
archNames := []string{} var moduleTargets []Target
for _, arch := range moduleArches {
archNames = append(archNames, arch.String()) for _, class := range osClasses {
targets := mctx.AConfig().Targets[class]
if len(targets) == 0 {
continue
}
multilib := module.base().commonProperties.Compile_multilib
targets, err := decodeMultilib(multilib, targets)
if err != nil {
mctx.ModuleErrorf("%s", err.Error())
}
moduleTargets = append(moduleTargets, targets...)
} }
modules := mctx.CreateVariations(archNames...) targetNames := make([]string, len(moduleTargets))
for i, target := range moduleTargets {
targetNames[i] = target.String()
}
modules := mctx.CreateVariations(targetNames...)
for i, m := range modules { for i, m := range modules {
m.(Module).base().SetArch(moduleArches[i]) m.(Module).base().SetTarget(moduleTargets[i])
m.(Module).base().setArchProperties(mctx) m.(Module).base().setArchProperties(mctx)
} }
} }
@@ -648,9 +547,8 @@ func (a *ModuleBase) appendProperties(ctx BottomUpMutatorContext,
// Rewrite the module's properties structs to contain arch-specific values. // Rewrite the module's properties structs to contain arch-specific values.
func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) { func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
arch := a.commonProperties.CompileArch arch := a.Arch()
hod := a.commonProperties.CompileHostOrDevice os := a.Os()
ht := a.commonProperties.CompileHostType
if arch.ArchType == Common { if arch.ArchType == Common {
return return
@@ -719,18 +617,19 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
prefix = "multilib." + t.Multilib prefix = "multilib." + t.Multilib
a.appendProperties(ctx, genProps, archProps.Multilib, field, prefix) a.appendProperties(ctx, genProps, archProps.Multilib, field, prefix)
// Handle host-or-device-specific properties in the form: // Handle host-specific properties in the form:
// target: { // target: {
// host: { // host: {
// key: value, // key: value,
// }, // },
// }, // },
hodProperty := hod.Property() if os.Class == Host || os.Class == HostCross {
field = proptools.FieldNameForProperty(hodProperty) field = "Host"
prefix = "target." + hodProperty prefix = "target.host"
a.appendProperties(ctx, genProps, archProps.Target, field, prefix) a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
}
// Handle host target properties in the form: // Handle target OS properties in the form:
// target: { // target: {
// linux: { // linux: {
// key: value, // key: value,
@@ -744,22 +643,29 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
// linux_arm: { // linux_arm: {
// key: value, // key: value,
// }, // },
// android {
// key: value,
// },
// android_arm {
// key: value,
// },
// android_x86 {
// key: value,
// },
// }, // },
if hod.Host() { // },
field := ht.Field() field = os.Field
prefix := "target." + ht.String() prefix = "target." + os.Name
a.appendProperties(ctx, genProps, archProps.Target, field, prefix) a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
t := arch.ArchType field = os.Field + "_" + t.Name
field = ht.Field() + "_" + t.Name prefix = "target." + os.Name + "_" + t.Name
prefix = "target." + ht.String() + "_" + t.Name a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
if ht != Windows { if (os.Class == Host || os.Class == HostCross) && os != Windows {
field := "Not_windows" field := "Not_windows"
prefix := "target.not_windows" prefix := "target.not_windows"
a.appendProperties(ctx, genProps, archProps.Target, field, prefix) a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
}
} }
// Handle 64-bit device properties in the form: // Handle 64-bit device properties in the form:
@@ -775,8 +681,8 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
// options for all targets on a device that supports 64-bit binaries, not just the targets // options for all targets on a device that supports 64-bit binaries, not just the targets
// that are being compiled for 64-bit. Its expected use case is binaries like linker and // that are being compiled for 64-bit. Its expected use case is binaries like linker and
// debuggerd that need to know when they are a 32-bit process running on a 64-bit device // debuggerd that need to know when they are a 32-bit process running on a 64-bit device
if hod.Device() { if os.Class == Device {
if true /* && target_is_64_bit */ { if ctx.AConfig().Android64() {
field := "Android64" field := "Android64"
prefix := "target.android64" prefix := "target.android64"
a.appendProperties(ctx, genProps, archProps.Target, field, prefix) a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
@@ -786,26 +692,6 @@ func (a *ModuleBase) setArchProperties(ctx BottomUpMutatorContext) {
a.appendProperties(ctx, genProps, archProps.Target, field, prefix) a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
} }
} }
// Handle device architecture properties in the form:
// target {
// android_arm {
// key: value,
// },
// android_x86 {
// key: value,
// },
// },
if hod.Device() {
t := arch.ArchType
field := "Android_" + t.Name
prefix := "target.android_" + t.Name
a.appendProperties(ctx, genProps, archProps.Target, field, prefix)
}
if ctx.Failed() {
return
}
} }
} }
@@ -824,104 +710,84 @@ func forEachInterface(v reflect.Value, f func(reflect.Value)) {
} }
} }
// Get a list of HostTypes from the product variables // Convert the arch product variables into a list of targets for each os class structs
func decodeHostTypesProductVariables(variables productVariables) ([]HostType, error) { func decodeTargetProductVariables(config Config) (map[OsClass][]Target, error) {
ret := []HostType{CurrentHostType()} variables := config.ProductVariables
if variables.CrossHost != nil && *variables.CrossHost != "" { targets := make(map[OsClass][]Target)
switch *variables.CrossHost { var targetErr error
case "windows":
ret = append(ret, Windows) addTarget := func(os OsType, archName string, archVariant, cpuVariant *string, abi *[]string) {
default: if targetErr != nil {
return nil, fmt.Errorf("Unsupported secondary host: %s", *variables.CrossHost) return
} }
arch, err := decodeArch(archName, archVariant, cpuVariant, abi)
if err != nil {
targetErr = err
return
}
targets[os.Class] = append(targets[os.Class],
Target{
Os: os,
Arch: arch,
})
} }
return ret, nil
}
// Convert the arch product variables into a list of host and device Arch structs
func decodeArchProductVariables(variables productVariables) (map[HostType][]Arch, []Arch, error) {
if variables.HostArch == nil { if variables.HostArch == nil {
return nil, nil, fmt.Errorf("No host primary architecture set") return nil, fmt.Errorf("No host primary architecture set")
} }
hostArch, err := decodeArch(*variables.HostArch, nil, nil, nil) addTarget(BuildOs, *variables.HostArch, nil, nil, nil)
if err != nil {
return nil, nil, err
}
hostArches := []Arch{hostArch}
if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" { if variables.HostSecondaryArch != nil && *variables.HostSecondaryArch != "" {
hostSecondaryArch, err := decodeArch(*variables.HostSecondaryArch, nil, nil, nil) addTarget(BuildOs, *variables.HostSecondaryArch, nil, nil, nil)
if err != nil {
return nil, nil, err
}
hostArches = append(hostArches, hostSecondaryArch)
}
hostTypeArches := map[HostType][]Arch{
CurrentHostType(): hostArches,
} }
if variables.CrossHost != nil && *variables.CrossHost != "" { if variables.CrossHost != nil && *variables.CrossHost != "" {
crossHostOs := osByName(*variables.CrossHost)
if crossHostOs == NoOsType {
return nil, fmt.Errorf("Unknown cross host OS %q", *variables.CrossHost)
}
if variables.CrossHostArch == nil || *variables.CrossHostArch == "" { if variables.CrossHostArch == nil || *variables.CrossHostArch == "" {
return nil, nil, fmt.Errorf("No cross-host primary architecture set") return nil, fmt.Errorf("No cross-host primary architecture set")
} }
crossHostArch, err := decodeArch(*variables.CrossHostArch, nil, nil, nil) addTarget(crossHostOs, *variables.CrossHostArch, nil, nil, nil)
if err != nil {
return nil, nil, err
}
crossHostArches := []Arch{crossHostArch}
if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" { if variables.CrossHostSecondaryArch != nil && *variables.CrossHostSecondaryArch != "" {
crossHostSecondaryArch, err := decodeArch(*variables.CrossHostSecondaryArch, nil, nil, nil) addTarget(crossHostOs, *variables.CrossHostSecondaryArch, nil, nil, nil)
if err != nil {
return nil, nil, err
}
crossHostArches = append(crossHostArches, crossHostSecondaryArch)
}
switch *variables.CrossHost {
case "windows":
hostTypeArches[Windows] = crossHostArches
default:
return nil, nil, fmt.Errorf("Unsupported cross-host: %s", *variables.CrossHost)
} }
} }
if variables.DeviceArch == nil { if variables.DeviceArch == nil {
return nil, nil, fmt.Errorf("No device primary architecture set") return nil, fmt.Errorf("No device primary architecture set")
} }
deviceArch, err := decodeArch(*variables.DeviceArch, variables.DeviceArchVariant, addTarget(Android, *variables.DeviceArch, variables.DeviceArchVariant,
variables.DeviceCpuVariant, variables.DeviceAbi) variables.DeviceCpuVariant, variables.DeviceAbi)
if err != nil {
return nil, nil, err
}
deviceArches := []Arch{deviceArch}
if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" { if variables.DeviceSecondaryArch != nil && *variables.DeviceSecondaryArch != "" {
deviceSecondaryArch, err := decodeArch(*variables.DeviceSecondaryArch, addTarget(Android, *variables.DeviceSecondaryArch,
variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant, variables.DeviceSecondaryArchVariant, variables.DeviceSecondaryCpuVariant,
variables.DeviceSecondaryAbi) variables.DeviceSecondaryAbi)
if err != nil {
return nil, nil, err deviceArches := targets[Device]
if deviceArches[0].Arch.ArchType.Multilib == deviceArches[1].Arch.ArchType.Multilib {
deviceArches[1].Arch.Native = false
} }
if deviceArch.ArchType.Multilib == deviceSecondaryArch.ArchType.Multilib {
deviceSecondaryArch.Native = false
}
deviceArches = append(deviceArches, deviceSecondaryArch)
} }
return hostTypeArches, deviceArches, nil if targetErr != nil {
return nil, targetErr
}
return targets, nil
} }
func decodeMegaDevice() ([]Arch, error) { func decodeMegaDevice() ([]Target, error) {
archSettings := []struct { archSettings := []struct {
arch string arch string
archVariant string archVariant string
@@ -969,7 +835,7 @@ func decodeMegaDevice() ([]Arch, error) {
{"x86_64", "silvermont", "", []string{"x86_64"}}, {"x86_64", "silvermont", "", []string{"x86_64"}},
} }
var ret []Arch var ret []Target
for _, config := range archSettings { for _, config := range archSettings {
arch, err := decodeArch(config.arch, &config.archVariant, arch, err := decodeArch(config.arch, &config.archVariant,
@@ -978,7 +844,10 @@ func decodeMegaDevice() ([]Arch, error) {
return nil, err return nil, err
} }
arch.Native = false arch.Native = false
ret = append(ret, arch) ret = append(ret, Target{
Os: Android,
Arch: arch,
})
} }
return ret, nil return ret, nil
@@ -1035,33 +904,32 @@ func decodeArch(arch string, archVariant, cpuVariant *string, abi *[]string) (Ar
return a, nil return a, nil
} }
// Use the module multilib setting to select one or more arches from an arch list // Use the module multilib setting to select one or more targets from a target list
func decodeMultilib(multilib string, arches []Arch) ([]Arch, error) { func decodeMultilib(multilib string, targets []Target) ([]Target, error) {
buildArches := []Arch{} buildTargets := []Target{}
switch multilib { switch multilib {
case "common": case "common":
buildArches = append(buildArches, commonArch) buildTargets = append(buildTargets, commonTarget)
case "both": case "both":
buildArches = append(buildArches, arches...) buildTargets = append(buildTargets, targets...)
case "first": case "first":
buildArches = append(buildArches, arches[0]) buildTargets = append(buildTargets, targets[0])
case "32": case "32":
for _, a := range arches { for _, t := range targets {
if a.ArchType.Multilib == "lib32" { if t.Arch.ArchType.Multilib == "lib32" {
buildArches = append(buildArches, a) buildTargets = append(buildTargets, t)
} }
} }
case "64": case "64":
for _, a := range arches { for _, t := range targets {
if a.ArchType.Multilib == "lib64" { if t.Arch.ArchType.Multilib == "lib64" {
buildArches = append(buildArches, a) buildTargets = append(buildTargets, t)
} }
} }
default: default:
return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", or "64", found %q`, return nil, fmt.Errorf(`compile_multilib must be "both", "first", "32", or "64", found %q`,
multilib) multilib)
//buildArches = append(buildArches, arches[0])
} }
return buildArches, nil return buildTargets, nil
} }

View File

@@ -54,8 +54,8 @@ type config struct {
ConfigFileName string ConfigFileName string
ProductVariablesFileName string ProductVariablesFileName string
DeviceArches []Arch Targets map[OsClass][]Target
HostArches map[HostType][]Arch BuildOsVariant string
srcDir string // the path of the root source directory srcDir string // the path of the root source directory
buildDir string // the path of the build output directory buildDir string // the path of the build output directory
@@ -175,20 +175,21 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
config.inMake = true config.inMake = true
} }
hostArches, deviceArches, err := decodeArchProductVariables(config.ProductVariables) targets, err := decodeTargetProductVariables(config)
if err != nil { if err != nil {
return Config{}, err return Config{}, err
} }
if Bool(config.Mega_device) { if Bool(config.Mega_device) {
deviceArches, err = decodeMegaDevice() deviceTargets, err := decodeMegaDevice()
if err != nil { if err != nil {
return Config{}, err return Config{}, err
} }
targets[Device] = deviceTargets
} }
config.HostArches = hostArches config.Targets = targets
config.DeviceArches = deviceArches config.BuildOsVariant = targets[Host][0].String()
return config, nil return config, nil
} }
@@ -325,3 +326,13 @@ func (c *config) SanitizeDevice() []string {
} }
return *c.ProductVariables.SanitizeDevice return *c.ProductVariables.SanitizeDevice
} }
func (c *config) Android64() bool {
for _, t := range c.Targets[Device] {
if t.Arch.ArchType.Multilib == "lib64" {
return true
}
}
return false
}

View File

@@ -48,9 +48,9 @@ type ModuleBuildParams struct {
} }
type androidBaseContext interface { type androidBaseContext interface {
Target() Target
Arch() Arch Arch() Arch
HostOrDevice() HostOrDevice Os() OsType
HostType() HostType
Host() bool Host() bool
Device() bool Device() bool
Darwin() bool Darwin() bool
@@ -90,7 +90,7 @@ type Module interface {
base() *ModuleBase base() *ModuleBase
Enabled() bool Enabled() bool
HostOrDevice() HostOrDevice Target() Target
InstallInData() bool InstallInData() bool
} }
@@ -115,14 +115,8 @@ type commonProperties struct {
// file // file
Logtags []string Logtags []string
// Set by HostOrDeviceMutator // Set by TargetMutator
CompileHostOrDevice HostOrDevice `blueprint:"mutated"` CompileTarget Target `blueprint:"mutated"`
// Set by HostTypeMutator
CompileHostType HostType `blueprint:"mutated"`
// Set by ArchMutator
CompileArch Arch `blueprint:"mutated"`
// Set by InitAndroidModule // Set by InitAndroidModule
HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"` HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
@@ -142,6 +136,16 @@ const (
MultilibDefault Multilib = "" MultilibDefault Multilib = ""
) )
type HostOrDeviceSupported int
const (
_ HostOrDeviceSupported = iota
HostSupported
DeviceSupported
HostAndDeviceSupported
HostAndDeviceDefault
)
func InitAndroidModule(m Module, func InitAndroidModule(m Module,
propertyStructs ...interface{}) (blueprint.Module, []interface{}) { propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
@@ -241,38 +245,45 @@ func (a *ModuleBase) base() *ModuleBase {
return a return a
} }
func (a *ModuleBase) SetHostOrDevice(hod HostOrDevice) { func (a *ModuleBase) SetTarget(target Target) {
a.commonProperties.CompileHostOrDevice = hod a.commonProperties.CompileTarget = target
} }
func (a *ModuleBase) SetHostType(ht HostType) { func (a *ModuleBase) Target() Target {
a.commonProperties.CompileHostType = ht return a.commonProperties.CompileTarget
} }
func (a *ModuleBase) SetArch(arch Arch) { func (a *ModuleBase) Os() OsType {
a.commonProperties.CompileArch = arch return a.Target().Os
}
func (a *ModuleBase) HostOrDevice() HostOrDevice {
return a.commonProperties.CompileHostOrDevice
}
func (a *ModuleBase) HostType() HostType {
return a.commonProperties.CompileHostType
} }
func (a *ModuleBase) Host() bool { func (a *ModuleBase) Host() bool {
return a.HostOrDevice().Host() return a.Os().Class == Host || a.Os().Class == HostCross
} }
func (a *ModuleBase) Arch() Arch { func (a *ModuleBase) Arch() Arch {
return a.commonProperties.CompileArch return a.Target().Arch
} }
func (a *ModuleBase) HostSupported() bool { func (a *ModuleBase) OsClassSupported() []OsClass {
return a.commonProperties.HostOrDeviceSupported == HostSupported || switch a.commonProperties.HostOrDeviceSupported {
a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported && case HostSupported:
a.hostAndDeviceProperties.Host_supported // TODO(ccross): explicitly mark host cross support
return []OsClass{Host, HostCross}
case DeviceSupported:
return []OsClass{Device}
case HostAndDeviceSupported:
var supported []OsClass
if a.hostAndDeviceProperties.Host_supported {
supported = append(supported, Host, HostCross)
}
if a.hostAndDeviceProperties.Device_supported {
supported = append(supported, Device)
}
return supported
default:
return nil
}
} }
func (a *ModuleBase) DeviceSupported() bool { func (a *ModuleBase) DeviceSupported() bool {
@@ -283,11 +294,7 @@ func (a *ModuleBase) DeviceSupported() bool {
func (a *ModuleBase) Enabled() bool { func (a *ModuleBase) Enabled() bool {
if a.commonProperties.Enabled == nil { if a.commonProperties.Enabled == nil {
if a.HostSupported() && a.HostOrDevice().Host() && a.HostType() == Windows { return a.Os().Class != HostCross
return false
} else {
return true
}
} }
return *a.commonProperties.Enabled return *a.commonProperties.Enabled
} }
@@ -376,9 +383,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{
arch: a.commonProperties.CompileArch, target: a.commonProperties.CompileTarget,
hod: a.commonProperties.CompileHostOrDevice,
ht: a.commonProperties.CompileHostType,
proprietary: a.commonProperties.Proprietary, proprietary: a.commonProperties.Proprietary,
config: ctx.Config().(Config), config: ctx.Config().(Config),
installInData: a.module.InstallInData(), installInData: a.module.InstallInData(),
@@ -413,9 +418,7 @@ func (a *ModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
} }
type androidBaseContextImpl struct { type androidBaseContextImpl struct {
arch Arch target Target
hod HostOrDevice
ht HostType
debug bool debug bool
config Config config Config
proprietary bool proprietary bool
@@ -494,28 +497,28 @@ func (a *androidModuleContext) AddMissingDependencies(deps []string) {
} }
} }
func (a *androidBaseContextImpl) Target() Target {
return a.target
}
func (a *androidBaseContextImpl) Arch() Arch { func (a *androidBaseContextImpl) Arch() Arch {
return a.arch return a.target.Arch
} }
func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice { func (a *androidBaseContextImpl) Os() OsType {
return a.hod return a.target.Os
}
func (a *androidBaseContextImpl) HostType() HostType {
return a.ht
} }
func (a *androidBaseContextImpl) Host() bool { func (a *androidBaseContextImpl) Host() bool {
return a.hod.Host() return a.target.Os.Class == Host || a.target.Os.Class == HostCross
} }
func (a *androidBaseContextImpl) Device() bool { func (a *androidBaseContextImpl) Device() bool {
return a.hod.Device() return a.target.Os.Class == Device
} }
func (a *androidBaseContextImpl) Darwin() bool { func (a *androidBaseContextImpl) Darwin() bool {
return a.hod.Host() && a.ht == Darwin return a.target.Os == Darwin
} }
func (a *androidBaseContextImpl) Debug() bool { func (a *androidBaseContextImpl) Debug() bool {

View File

@@ -629,7 +629,7 @@ func PathForModuleInstall(ctx ModuleContext, paths ...string) OutputPath {
} }
outPaths = []string{"target", "product", ctx.AConfig().DeviceName(), partition} outPaths = []string{"target", "product", ctx.AConfig().DeviceName(), partition}
} else { } else {
outPaths = []string{"host", ctx.HostType().String() + "-x86"} outPaths = []string{"host", ctx.Os().String() + "-x86"}
} }
if ctx.Debug() { if ctx.Debug() {
outPaths = append([]string{"debug"}, outPaths...) outPaths = append([]string{"debug"}, outPaths...)

View File

@@ -208,5 +208,5 @@ func arm64ToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerDeviceToolchainFactory(android.Arm64, arm64ToolchainFactory) registerToolchainFactory(android.Android, android.Arm64, arm64ToolchainFactory)
} }

View File

@@ -392,5 +392,5 @@ func armToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerDeviceToolchainFactory(android.Arm, armToolchainFactory) registerToolchainFactory(android.Android, android.Arm, armToolchainFactory)
} }

View File

@@ -118,7 +118,7 @@ var (
) )
func init() { func init() {
if android.CurrentHostType() == android.Linux { if android.BuildOs == android.Linux {
commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=") commonGlobalCflags = append(commonGlobalCflags, "-fdebug-prefix-map=/proc/self/cwd=")
} }
@@ -729,11 +729,10 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
func (c *Module) toolchain(ctx BaseModuleContext) Toolchain { func (c *Module) toolchain(ctx BaseModuleContext) Toolchain {
if c.cachedToolchain == nil { if c.cachedToolchain == nil {
arch := ctx.Arch() arch := ctx.Arch()
hod := ctx.HostOrDevice() os := ctx.Os()
ht := ctx.HostType() factory := toolchainFactories[os][arch.ArchType]
factory := toolchainFactories[hod][ht][arch.ArchType]
if factory == nil { if factory == nil {
ctx.ModuleErrorf("Toolchain not found for %s %s arch %q", hod.String(), ht.String(), arch.String()) ctx.ModuleErrorf("Toolchain not found for %s arch %q", os.String(), arch.String())
return nil return nil
} }
c.cachedToolchain = factory(arch) c.cachedToolchain = factory(arch)
@@ -905,8 +904,13 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return return
} }
if a.HostOrDevice() != ctx.HostOrDevice() { if a.Target().Os != ctx.Os() {
ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(), name) ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
return
}
if a.Target().Arch.ArchType != ctx.Arch().ArchType {
ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
return return
} }
@@ -1081,6 +1085,11 @@ func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
flags.LdFlags = append(flags.LdFlags, target, gccPrefix) flags.LdFlags = append(flags.LdFlags, target, gccPrefix)
} }
hod := "host"
if ctx.Os().Class == android.Device {
hod = "device"
}
if !ctx.noDefaultCompilerFlags() { if !ctx.noDefaultCompilerFlags() {
flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags) flags.GlobalFlags = append(flags.GlobalFlags, instructionSetFlags)
@@ -1090,7 +1099,7 @@ func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
flags.GlobalFlags = append(flags.GlobalFlags, flags.GlobalFlags = append(flags.GlobalFlags,
toolchain.ClangCflags(), toolchain.ClangCflags(),
"${commonClangGlobalCflags}", "${commonClangGlobalCflags}",
fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice())) fmt.Sprintf("${%sClangGlobalCflags}", hod))
flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}") flags.ConlyFlags = append(flags.ConlyFlags, "${clangExtraConlyflags}")
} else { } else {
@@ -1098,7 +1107,7 @@ func (compiler *baseCompiler) flags(ctx ModuleContext, flags Flags) Flags {
flags.GlobalFlags = append(flags.GlobalFlags, flags.GlobalFlags = append(flags.GlobalFlags,
toolchain.Cflags(), toolchain.Cflags(),
"${commonGlobalCflags}", "${commonGlobalCflags}",
fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice())) fmt.Sprintf("${%sGlobalCflags}", hod))
} }
if Bool(ctx.AConfig().ProductVariables.Brillo) { if Bool(ctx.AConfig().ProductVariables.Brillo) {
@@ -1410,7 +1419,7 @@ func (library *libraryCompiler) flags(ctx ModuleContext, flags Flags) Flags {
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
// all code is position independent, and then those warnings get promoted to // all code is position independent, and then those warnings get promoted to
// errors. // errors.
if ctx.HostType() != android.Windows { if ctx.Os() != android.Windows {
flags.CFlags = append(flags.CFlags, "-fPIC") flags.CFlags = append(flags.CFlags, "-fPIC")
} }
@@ -1863,7 +1872,7 @@ func (binary *binaryLinker) begin(ctx BaseModuleContext) {
static := Bool(binary.Properties.Static_executable) static := Bool(binary.Properties.Static_executable)
if ctx.Host() { if ctx.Host() {
if ctx.HostType() == android.Linux { if ctx.Os() == android.Linux {
if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) { if binary.Properties.Static_executable == nil && Bool(ctx.AConfig().ProductVariables.HostStaticBinaries) {
static = true static = true
} }
@@ -1883,7 +1892,7 @@ func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags {
if ctx.Host() && !binary.staticBinary() { if ctx.Host() && !binary.staticBinary() {
flags.LdFlags = append(flags.LdFlags, "-pie") flags.LdFlags = append(flags.LdFlags, "-pie")
if ctx.HostType() == android.Windows { if ctx.Os() == android.Windows {
flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup") flags.LdFlags = append(flags.LdFlags, "-Wl,-e_mainCRTStartup")
} }
} }
@@ -1891,7 +1900,7 @@ func (binary *binaryLinker) flags(ctx ModuleContext, flags Flags) Flags {
// MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because // MinGW spits out warnings about -fPIC even for -fpie?!) being ignored because
// all code is position independent, and then those warnings get promoted to // all code is position independent, and then those warnings get promoted to
// errors. // errors.
if ctx.HostType() != android.Windows { if ctx.Os() != android.Windows {
flags.CFlags = append(flags.CFlags, "-fpie") flags.CFlags = append(flags.CFlags, "-fpie")
} }
@@ -1945,7 +1954,7 @@ func (binary *binaryLinker) link(ctx ModuleContext,
fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix() fileName := binary.getStem(ctx) + flags.Toolchain.ExecutableSuffix()
outputFile := android.PathForModuleOut(ctx, fileName) outputFile := android.PathForModuleOut(ctx, fileName)
ret := outputFile ret := outputFile
if ctx.HostOrDevice().Host() { if ctx.Os().Class == android.Host {
binary.hostToolPath = android.OptionalPathForPath(outputFile) binary.hostToolPath = android.OptionalPathForPath(outputFile)
} }
@@ -2052,7 +2061,7 @@ func (test *testLinker) flags(ctx ModuleContext, flags Flags) Flags {
if ctx.Host() { if ctx.Host() {
flags.CFlags = append(flags.CFlags, "-O0", "-g") flags.CFlags = append(flags.CFlags, "-O0", "-g")
switch ctx.HostType() { switch ctx.Os() {
case android.Windows: case android.Windows:
flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS") flags.CFlags = append(flags.CFlags, "-DGTEST_OS_WINDOWS")
case android.Linux: case android.Linux:

View File

@@ -41,49 +41,54 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "") ctx.Strict("GLOBAL_CPPFLAGS_NO_OVERRIDE", "")
ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "")
hostType := android.CurrentHostType() hostTargets := ctx.Config().Targets[android.Host]
arches := ctx.Config().HostArches[hostType] makeVarsToolchain(ctx, "", hostTargets[0])
makeVarsToolchain(ctx, "", android.Host, hostType, arches[0]) if len(hostTargets) > 1 {
if len(arches) > 1 { makeVarsToolchain(ctx, "2ND_", hostTargets[1])
makeVarsToolchain(ctx, "2ND_", android.Host, hostType, arches[1])
} }
if winArches, ok := ctx.Config().HostArches[android.Windows]; ok { crossTargets := ctx.Config().Targets[android.HostCross]
makeVarsToolchain(ctx, "", android.Host, android.Windows, winArches[0]) if len(crossTargets) > 0 {
if len(winArches) > 1 { makeVarsToolchain(ctx, "", crossTargets[0])
makeVarsToolchain(ctx, "2ND_", android.Host, android.Windows, winArches[1]) if len(crossTargets) > 1 {
makeVarsToolchain(ctx, "2ND_", crossTargets[1])
} }
} }
arches = ctx.Config().DeviceArches deviceTargets := ctx.Config().Targets[android.Device]
makeVarsToolchain(ctx, "", android.Device, android.NoHostType, arches[0]) makeVarsToolchain(ctx, "", deviceTargets[0])
if len(arches) > 1 { if len(deviceTargets) > 1 {
makeVarsToolchain(ctx, "2ND_", android.Device, android.NoHostType, arches[1]) makeVarsToolchain(ctx, "2ND_", deviceTargets[1])
} }
} }
func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
hod android.HostOrDevice, ht android.HostType, arch android.Arch) { target android.Target) {
var typePrefix string var typePrefix string
if hod.Host() { switch target.Os.Class {
if ht == android.Windows { case android.Host:
typePrefix = "HOST_CROSS_" typePrefix = "HOST_"
} else { case android.HostCross:
typePrefix = "HOST_" typePrefix = "HOST_CROSS_"
} case android.Device:
} else {
typePrefix = "TARGET_" typePrefix = "TARGET_"
} }
makePrefix := secondPrefix + typePrefix makePrefix := secondPrefix + typePrefix
toolchain := toolchainFactories[hod][ht][arch.ArchType](arch) toolchain := toolchainFactories[target.Os][target.Arch.ArchType](target.Arch)
var productExtraCflags string var productExtraCflags string
var productExtraLdflags string var productExtraLdflags string
if hod.Device() && Bool(ctx.Config().ProductVariables.Brillo) {
hod := "host"
if target.Os.Class == android.Device {
hod = "device"
}
if target.Os.Class == android.Device && Bool(ctx.Config().ProductVariables.Brillo) {
productExtraCflags += "-D__BRILLO__" productExtraCflags += "-D__BRILLO__"
} }
if hod.Host() && Bool(ctx.Config().ProductVariables.HostStaticBinaries) { if target.Os.Class == android.Host && Bool(ctx.Config().ProductVariables.HostStaticBinaries) {
productExtraLdflags += "-static" productExtraLdflags += "-static"
} }
@@ -108,23 +113,29 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
ctx.Strict(makePrefix+"SYSTEMCPP_LDFLAGS", toolchain.SystemCppLdflags()) ctx.Strict(makePrefix+"SYSTEMCPP_LDFLAGS", toolchain.SystemCppLdflags())
includeFlags, err := ctx.Eval(toolchain.IncludeFlags()) includeFlags, err := ctx.Eval(toolchain.IncludeFlags())
if err != nil { panic(err) } if err != nil {
panic(err)
}
ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Replace(includeFlags, "-isystem ", "", -1)) ctx.StrictRaw(makePrefix+"C_INCLUDES", strings.Replace(includeFlags, "-isystem ", "", -1))
if arch.ArchType == android.Arm { if target.Arch.ArchType == android.Arm {
flags, err := toolchain.InstructionSetFlags("arm") flags, err := toolchain.InstructionSetFlags("arm")
if err != nil { panic(err) } if err != nil {
panic(err)
}
ctx.Strict(makePrefix+"arm_CFLAGS", flags) ctx.Strict(makePrefix+"arm_CFLAGS", flags)
flags, err = toolchain.InstructionSetFlags("thumb") flags, err = toolchain.InstructionSetFlags("thumb")
if err != nil { panic(err) } if err != nil {
panic(err)
}
ctx.Strict(makePrefix+"thumb_CFLAGS", flags) ctx.Strict(makePrefix+"thumb_CFLAGS", flags)
} }
if toolchain.ClangSupported() { if toolchain.ClangSupported() {
clangPrefix := secondPrefix + "CLANG_" + typePrefix clangPrefix := secondPrefix + "CLANG_" + typePrefix
clangExtras := "-target " + toolchain.ClangTriple() clangExtras := "-target " + toolchain.ClangTriple()
if ht != android.Darwin { if target.Os != android.Darwin {
clangExtras += " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin") clangExtras += " -B" + filepath.Join(toolchain.GccRoot(), toolchain.GccTriple(), "bin")
} }
@@ -148,19 +159,19 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
clangExtras, clangExtras,
}, " ")) }, " "))
if hod.Device() { if target.Os.Class == android.Device {
ctx.Strict(secondPrefix + "ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(toolchain.AddressSanitizerRuntimeLibrary(), ".so")) ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(toolchain.AddressSanitizerRuntimeLibrary(), ".so"))
} }
// This is used by external/gentoo/... // This is used by external/gentoo/...
ctx.Strict("CLANG_CONFIG_" + arch.ArchType.Name + "_" + typePrefix + "TRIPLE", ctx.Strict("CLANG_CONFIG_"+target.Arch.ArchType.Name+"_"+typePrefix+"TRIPLE",
toolchain.ClangTriple()) toolchain.ClangTriple())
} }
ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc")) ctx.Strict(makePrefix+"CC", gccCmd(toolchain, "gcc"))
ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++")) ctx.Strict(makePrefix+"CXX", gccCmd(toolchain, "g++"))
if ht == android.Darwin { if target.Os == android.Darwin {
ctx.Strict(makePrefix+"AR", "${macArPath}") ctx.Strict(makePrefix+"AR", "${macArPath}")
} else { } else {
ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar")) ctx.Strict(makePrefix+"AR", gccCmd(toolchain, "ar"))
@@ -168,11 +179,11 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string,
ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm")) ctx.Strict(makePrefix+"NM", gccCmd(toolchain, "nm"))
} }
if ht == android.Windows { if target.Os == android.Windows {
ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump")) ctx.Strict(makePrefix+"OBJDUMP", gccCmd(toolchain, "objdump"))
} }
if hod.Device() { if target.Os.Class == android.Device {
ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy")) ctx.Strict(makePrefix+"OBJCOPY", gccCmd(toolchain, "objcopy"))
ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld")) ctx.Strict(makePrefix+"LD", gccCmd(toolchain, "ld"))
ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip")) ctx.Strict(makePrefix+"STRIP", gccCmd(toolchain, "strip"))

View File

@@ -200,5 +200,5 @@ func mips64ToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerDeviceToolchainFactory(android.Mips64, mips64ToolchainFactory) registerToolchainFactory(android.Android, android.Mips64, mips64ToolchainFactory)
} }

View File

@@ -248,5 +248,5 @@ func mipsToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerDeviceToolchainFactory(android.Mips, mipsToolchainFactory) registerToolchainFactory(android.Android, android.Mips, mipsToolchainFactory)
} }

View File

@@ -52,7 +52,7 @@ func (stl *stl) begin(ctx BaseModuleContext) {
ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", stl.Properties.Stl) ctx.ModuleErrorf("stl: %q is not a supported STL with sdk_version set", stl.Properties.Stl)
return "" return ""
} }
} else if ctx.HostType() == android.Windows { } else if ctx.Os() == android.Windows {
switch stl.Properties.Stl { switch stl.Properties.Stl {
case "libc++", "libc++_static", "libstdc++", "": case "libc++", "libc++_static", "libstdc++", "":
// libc++ is not supported on mingw // libc++ is not supported on mingw
@@ -60,7 +60,7 @@ func (stl *stl) begin(ctx BaseModuleContext) {
case "none": case "none":
return "" return ""
default: default:
ctx.ModuleErrorf("stl: %q is not a supported STL", stl.Properties.Stl) ctx.ModuleErrorf("stl: %q is not a supported STL for windows", stl.Properties.Stl)
return "" return ""
} }
} else { } else {
@@ -133,9 +133,9 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs") flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
flags.LdFlags = append(flags.LdFlags, "-lpthread", "-lm") flags.LdFlags = append(flags.LdFlags, "-lpthread", "-lm")
if ctx.staticBinary() { if ctx.staticBinary() {
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.HostType()]...) flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
} else { } else {
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.HostType()]...) flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
} }
} else { } else {
if ctx.Arch().ArchType == android.Arm { if ctx.Arch().ArchType == android.Arm {
@@ -167,9 +167,9 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
flags.CppFlags = append(flags.CppFlags, "-nostdinc++") flags.CppFlags = append(flags.CppFlags, "-nostdinc++")
flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs") flags.LdFlags = append(flags.LdFlags, "-nodefaultlibs")
if ctx.staticBinary() { if ctx.staticBinary() {
flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.HostType()]...) flags.LdFlags = append(flags.LdFlags, hostStaticGccLibs[ctx.Os()]...)
} else { } else {
flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.HostType()]...) flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...)
} }
} }
default: default:
@@ -179,10 +179,10 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags {
return flags return flags
} }
var hostDynamicGccLibs, hostStaticGccLibs map[android.HostType][]string var hostDynamicGccLibs, hostStaticGccLibs map[android.OsType][]string
func init() { func init() {
hostDynamicGccLibs = map[android.HostType][]string{ hostDynamicGccLibs = map[android.OsType][]string{
android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"}, android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"},
android.Darwin: []string{"-lc", "-lSystem"}, android.Darwin: []string{"-lc", "-lSystem"},
android.Windows: []string{"-lmsvcr110", "-lmingw32", "-lgcc", "-lmoldname", android.Windows: []string{"-lmsvcr110", "-lmingw32", "-lgcc", "-lmoldname",
@@ -190,7 +190,7 @@ func init() {
"-lkernel32", "-lmingw32", "-lgcc", "-lmoldname", "-lmingwex", "-lkernel32", "-lmingw32", "-lgcc", "-lmoldname", "-lmingwex",
"-lmsvcrt"}, "-lmsvcrt"},
} }
hostStaticGccLibs = map[android.HostType][]string{ hostStaticGccLibs = map[android.OsType][]string{
android.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"}, android.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"},
android.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"}, android.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"},
android.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"}, android.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"},

View File

@@ -22,23 +22,13 @@ import (
type toolchainFactory func(arch android.Arch) Toolchain type toolchainFactory func(arch android.Arch) Toolchain
var toolchainFactories = map[android.HostOrDevice]map[android.HostType]map[android.ArchType]toolchainFactory{ var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory)
android.Host: map[android.HostType]map[android.ArchType]toolchainFactory{
android.Linux: make(map[android.ArchType]toolchainFactory),
android.Darwin: make(map[android.ArchType]toolchainFactory),
android.Windows: make(map[android.ArchType]toolchainFactory),
},
android.Device: map[android.HostType]map[android.ArchType]toolchainFactory{
android.NoHostType: make(map[android.ArchType]toolchainFactory),
},
}
func registerDeviceToolchainFactory(arch android.ArchType, factory toolchainFactory) { func registerToolchainFactory(os android.OsType, arch android.ArchType, factory toolchainFactory) {
toolchainFactories[android.Device][android.NoHostType][arch] = factory if toolchainFactories[os] == nil {
} toolchainFactories[os] = make(map[android.ArchType]toolchainFactory)
}
func registerHostToolchainFactory(ht android.HostType, arch android.ArchType, factory toolchainFactory) { toolchainFactories[os][arch] = factory
toolchainFactories[android.Host][ht][arch] = factory
} }
type Toolchain interface { type Toolchain interface {

View File

@@ -263,5 +263,5 @@ func x86_64ToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerDeviceToolchainFactory(android.X86_64, x86_64ToolchainFactory) registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
} }

View File

@@ -280,6 +280,6 @@ func darwinX8664ToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerHostToolchainFactory(android.Darwin, android.X86, darwinX86ToolchainFactory) registerToolchainFactory(android.Darwin, android.X86, darwinX86ToolchainFactory)
registerHostToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory) registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory)
} }

View File

@@ -286,5 +286,5 @@ func x86ToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerDeviceToolchainFactory(android.X86, x86ToolchainFactory) registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
} }

View File

@@ -254,6 +254,6 @@ func linuxX8664ToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerHostToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory) registerToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory)
registerHostToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory) registerToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory)
} }

View File

@@ -199,6 +199,6 @@ func windowsX8664ToolchainFactory(arch android.Arch) Toolchain {
} }
func init() { func init() {
registerHostToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory) registerToolchainFactory(android.Windows, android.X86, windowsX86ToolchainFactory)
registerHostToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory) registerToolchainFactory(android.Windows, android.X86_64, windowsX8664ToolchainFactory)
} }

View File

@@ -97,8 +97,7 @@ func genruleDepsMutator(ctx android.BottomUpMutatorContext) {
if g, ok := ctx.Module().(*generator); ok { if g, ok := ctx.Module().(*generator); ok {
if g.properties.Tool != "" { if g.properties.Tool != "" {
ctx.AddFarVariationDependencies([]blueprint.Variation{ ctx.AddFarVariationDependencies([]blueprint.Variation{
{"host_or_device", android.Host.String()}, {"arch", ctx.AConfig().BuildOsVariant},
{"host_type", android.CurrentHostType().String()},
}, nil, g.properties.Tool) }, nil, g.properties.Tool)
} }
} }