Separate HostOrDevice out of Arch
Take HostOrDevice out of Arch, and put it into AndroidModuleBase instead. Also separate out the host vs. device mutator from ArchMutator. This will make it possible for genrules to depend on a host tool, regardless of which host arches it is compiled for. Change-Id: I22bbfd28b65c3eebdfa101a712f90dd615148dc8
This commit is contained in:
11
cc/cc.go
11
cc/cc.go
@@ -342,10 +342,11 @@ var _ common.AndroidDynamicDepender = (*CCBase)(nil)
|
|||||||
|
|
||||||
func (c *CCBase) findToolchain(ctx common.AndroidModuleContext) Toolchain {
|
func (c *CCBase) findToolchain(ctx common.AndroidModuleContext) Toolchain {
|
||||||
arch := ctx.Arch()
|
arch := ctx.Arch()
|
||||||
factory := toolchainFactories[arch.HostOrDevice][arch.ArchType]
|
hod := ctx.HostOrDevice()
|
||||||
|
factory := toolchainFactories[hod][arch.ArchType]
|
||||||
if factory == nil {
|
if factory == nil {
|
||||||
panic(fmt.Sprintf("Toolchain not found for %s arch %q",
|
panic(fmt.Sprintf("Toolchain not found for %s arch %q",
|
||||||
arch.HostOrDevice.String(), arch.String()))
|
hod.String(), arch.String()))
|
||||||
}
|
}
|
||||||
return factory(arch.ArchVariant, arch.CpuVariant)
|
return factory(arch.ArchVariant, arch.CpuVariant)
|
||||||
}
|
}
|
||||||
@@ -471,13 +472,13 @@ func (c *CCBase) collectFlags(ctx common.AndroidModuleContext, toolchain Toolcha
|
|||||||
flags.GlobalFlags = append(flags.GlobalFlags,
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
||||||
toolchain.ClangCflags(),
|
toolchain.ClangCflags(),
|
||||||
"${commonClangGlobalCflags}",
|
"${commonClangGlobalCflags}",
|
||||||
fmt.Sprintf("${%sClangGlobalCflags}", ctx.Arch().HostOrDevice))
|
fmt.Sprintf("${%sClangGlobalCflags}", ctx.HostOrDevice()))
|
||||||
} else {
|
} else {
|
||||||
flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}")
|
flags.CppFlags = append(flags.CppFlags, "${commonGlobalCppflags}")
|
||||||
flags.GlobalFlags = append(flags.GlobalFlags,
|
flags.GlobalFlags = append(flags.GlobalFlags,
|
||||||
toolchain.Cflags(),
|
toolchain.Cflags(),
|
||||||
"${commonGlobalCflags}",
|
"${commonGlobalCflags}",
|
||||||
fmt.Sprintf("${%sGlobalCflags}", ctx.Arch().HostOrDevice))
|
fmt.Sprintf("${%sGlobalCflags}", ctx.HostOrDevice()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
@@ -588,7 +589,7 @@ func (c *CCBase) depsToPathsFromList(ctx common.AndroidModuleContext,
|
|||||||
// of host and device. Ignore the disabled one.
|
// of host and device. Ignore the disabled one.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if a.HostOrDevice() != ctx.Arch().HostOrDevice {
|
if a.HostOrDevice() != ctx.HostOrDevice() {
|
||||||
ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(),
|
ctx.ModuleErrorf("host/device mismatch between %q and %q", ctx.ModuleName(),
|
||||||
otherName)
|
otherName)
|
||||||
return
|
return
|
||||||
|
@@ -75,6 +75,7 @@ func main() {
|
|||||||
ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
|
ctx.RegisterModuleType("android_app", java.AndroidAppFactory)
|
||||||
|
|
||||||
// Mutators
|
// Mutators
|
||||||
|
ctx.RegisterEarlyMutator("host_or_device", common.HostOrDeviceMutator)
|
||||||
ctx.RegisterEarlyMutator("arch", common.ArchMutator)
|
ctx.RegisterEarlyMutator("arch", common.ArchMutator)
|
||||||
ctx.RegisterEarlyMutator("link", cc.LinkageMutator)
|
ctx.RegisterEarlyMutator("link", cc.LinkageMutator)
|
||||||
ctx.RegisterEarlyMutator("test_per_src", cc.TestPerSrcMutator)
|
ctx.RegisterEarlyMutator("test_per_src", cc.TestPerSrcMutator)
|
||||||
|
@@ -129,15 +129,14 @@ type archProperties struct {
|
|||||||
|
|
||||||
// An Arch indicates a single CPU architecture.
|
// An Arch indicates a single CPU architecture.
|
||||||
type Arch struct {
|
type Arch struct {
|
||||||
HostOrDevice HostOrDevice
|
ArchType ArchType
|
||||||
ArchType ArchType
|
ArchVariant string
|
||||||
ArchVariant string
|
CpuVariant string
|
||||||
CpuVariant string
|
Abi string
|
||||||
Abi string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Arch) String() string {
|
func (a Arch) String() string {
|
||||||
s := a.HostOrDevice.String() + "_" + a.ArchType.String()
|
s := a.ArchType.String()
|
||||||
if a.ArchVariant != "" {
|
if a.ArchVariant != "" {
|
||||||
s += "_" + a.ArchVariant
|
s += "_" + a.ArchVariant
|
||||||
}
|
}
|
||||||
@@ -247,37 +246,60 @@ var hostOrDeviceName = map[HostOrDevice]string{
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
armArch = Arch{
|
armArch = Arch{
|
||||||
HostOrDevice: Device,
|
ArchType: Arm,
|
||||||
ArchType: Arm,
|
ArchVariant: "armv7-a-neon",
|
||||||
ArchVariant: "armv7-a-neon",
|
CpuVariant: "cortex-a15",
|
||||||
CpuVariant: "cortex-a15",
|
Abi: "armeabi-v7a",
|
||||||
Abi: "armeabi-v7a",
|
|
||||||
}
|
}
|
||||||
arm64Arch = Arch{
|
arm64Arch = Arch{
|
||||||
HostOrDevice: Device,
|
ArchType: Arm64,
|
||||||
ArchType: Arm64,
|
ArchVariant: "armv8-a",
|
||||||
ArchVariant: "armv8-a",
|
CpuVariant: "denver",
|
||||||
CpuVariant: "denver",
|
Abi: "arm64-v8a",
|
||||||
Abi: "arm64-v8a",
|
|
||||||
}
|
}
|
||||||
hostArch = Arch{
|
x86Arch = Arch{
|
||||||
HostOrDevice: Host,
|
ArchType: X86,
|
||||||
ArchType: X86,
|
|
||||||
}
|
}
|
||||||
host64Arch = Arch{
|
x8664Arch = Arch{
|
||||||
HostOrDevice: Host,
|
ArchType: X86_64,
|
||||||
ArchType: X86_64,
|
|
||||||
}
|
}
|
||||||
commonDevice = Arch{
|
commonArch = Arch{
|
||||||
HostOrDevice: Device,
|
ArchType: Common,
|
||||||
ArchType: Common,
|
|
||||||
}
|
|
||||||
commonHost = Arch{
|
|
||||||
HostOrDevice: Host,
|
|
||||||
ArchType: Common,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func HostOrDeviceMutator(mctx blueprint.EarlyMutatorContext) {
|
||||||
|
var module AndroidModule
|
||||||
|
var ok bool
|
||||||
|
if module, ok = mctx.Module().(AndroidModule); !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.(AndroidModule).base().SetHostOrDevice(hods[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ArchMutator(mctx blueprint.EarlyMutatorContext) {
|
func ArchMutator(mctx blueprint.EarlyMutatorContext) {
|
||||||
var module AndroidModule
|
var module AndroidModule
|
||||||
var ok bool
|
var ok bool
|
||||||
@@ -290,19 +312,19 @@ func ArchMutator(mctx blueprint.EarlyMutatorContext) {
|
|||||||
|
|
||||||
arches := []Arch{}
|
arches := []Arch{}
|
||||||
|
|
||||||
if module.base().HostSupported() {
|
if module.base().HostSupported() && module.base().HostOrDevice().Host() {
|
||||||
switch module.base().commonProperties.Compile_multilib {
|
switch module.base().commonProperties.Compile_multilib {
|
||||||
case "common":
|
case "common":
|
||||||
arches = append(arches, commonHost)
|
arches = append(arches, commonArch)
|
||||||
default:
|
default:
|
||||||
arches = append(arches, host64Arch)
|
arches = append(arches, x8664Arch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if module.base().DeviceSupported() {
|
if module.base().DeviceSupported() && module.base().HostOrDevice().Device() {
|
||||||
switch module.base().commonProperties.Compile_multilib {
|
switch module.base().commonProperties.Compile_multilib {
|
||||||
case "common":
|
case "common":
|
||||||
arches = append(arches, commonDevice)
|
arches = append(arches, commonArch)
|
||||||
case "both":
|
case "both":
|
||||||
arches = append(arches, arm64Arch, armArch)
|
arches = append(arches, arm64Arch, armArch)
|
||||||
case "first", "64":
|
case "first", "64":
|
||||||
@@ -328,7 +350,7 @@ func ArchMutator(mctx blueprint.EarlyMutatorContext) {
|
|||||||
|
|
||||||
for i, m := range modules {
|
for i, m := range modules {
|
||||||
m.(AndroidModule).base().SetArch(arches[i])
|
m.(AndroidModule).base().SetArch(arches[i])
|
||||||
m.(AndroidModule).base().setArchProperties(mctx, arches[i])
|
m.(AndroidModule).base().setArchProperties(mctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,7 +395,10 @@ func InitArchModule(m AndroidModule, defaultMultilib Multilib,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite the module's properties structs to contain arch-specific values.
|
// Rewrite the module's properties structs to contain arch-specific values.
|
||||||
func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext, arch Arch) {
|
func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext) {
|
||||||
|
arch := a.commonProperties.CompileArch
|
||||||
|
hod := a.commonProperties.CompileHostOrDevice
|
||||||
|
|
||||||
if arch.ArchType == Common {
|
if arch.ArchType == Common {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -406,7 +431,6 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext,
|
|||||||
// key: value,
|
// key: value,
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
hod := arch.HostOrDevice
|
|
||||||
a.extendProperties(ctx, "target", hod.FieldLower(), generalPropsValue,
|
a.extendProperties(ctx, "target", hod.FieldLower(), generalPropsValue,
|
||||||
reflect.ValueOf(a.archProperties[i].Target).FieldByName(hod.Field()).Elem().Elem())
|
reflect.ValueOf(a.archProperties[i].Target).FieldByName(hod.Field()).Elem().Elem())
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@ var (
|
|||||||
|
|
||||||
type androidBaseContext interface {
|
type androidBaseContext interface {
|
||||||
Arch() Arch
|
Arch() Arch
|
||||||
|
HostOrDevice() HostOrDevice
|
||||||
Host() bool
|
Host() bool
|
||||||
Device() bool
|
Device() bool
|
||||||
Darwin() bool
|
Darwin() bool
|
||||||
@@ -86,6 +87,9 @@ type commonProperties struct {
|
|||||||
// platform
|
// platform
|
||||||
Compile_multilib string
|
Compile_multilib string
|
||||||
|
|
||||||
|
// Set by HostOrDeviceMutator
|
||||||
|
CompileHostOrDevice HostOrDevice `blueprint:"mutated"`
|
||||||
|
|
||||||
// Set by ArchMutator
|
// Set by ArchMutator
|
||||||
CompileArch Arch `blueprint:"mutated"`
|
CompileArch Arch `blueprint:"mutated"`
|
||||||
|
|
||||||
@@ -196,12 +200,16 @@ func (a *AndroidModuleBase) base() *AndroidModuleBase {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AndroidModuleBase) SetHostOrDevice(hod HostOrDevice) {
|
||||||
|
a.commonProperties.CompileHostOrDevice = hod
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AndroidModuleBase) SetArch(arch Arch) {
|
func (a *AndroidModuleBase) SetArch(arch Arch) {
|
||||||
a.commonProperties.CompileArch = arch
|
a.commonProperties.CompileArch = arch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidModuleBase) HostOrDevice() HostOrDevice {
|
func (a *AndroidModuleBase) HostOrDevice() HostOrDevice {
|
||||||
return a.commonProperties.CompileArch.HostOrDevice
|
return a.commonProperties.CompileHostOrDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidModuleBase) HostSupported() bool {
|
func (a *AndroidModuleBase) HostSupported() bool {
|
||||||
@@ -293,6 +301,7 @@ func (a *AndroidModuleBase) DynamicDependencies(ctx blueprint.DynamicDependerMod
|
|||||||
DynamicDependerModuleContext: ctx,
|
DynamicDependerModuleContext: ctx,
|
||||||
androidBaseContextImpl: androidBaseContextImpl{
|
androidBaseContextImpl: androidBaseContextImpl{
|
||||||
arch: a.commonProperties.CompileArch,
|
arch: a.commonProperties.CompileArch,
|
||||||
|
hod: a.commonProperties.CompileHostOrDevice,
|
||||||
config: ctx.Config().(Config),
|
config: ctx.Config().(Config),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -309,6 +318,7 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
|||||||
ModuleContext: ctx,
|
ModuleContext: ctx,
|
||||||
androidBaseContextImpl: androidBaseContextImpl{
|
androidBaseContextImpl: androidBaseContextImpl{
|
||||||
arch: a.commonProperties.CompileArch,
|
arch: a.commonProperties.CompileArch,
|
||||||
|
hod: a.commonProperties.CompileHostOrDevice,
|
||||||
config: ctx.Config().(Config),
|
config: ctx.Config().(Config),
|
||||||
},
|
},
|
||||||
installDeps: a.computeInstallDeps(ctx),
|
installDeps: a.computeInstallDeps(ctx),
|
||||||
@@ -336,6 +346,7 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
|||||||
|
|
||||||
type androidBaseContextImpl struct {
|
type androidBaseContextImpl struct {
|
||||||
arch Arch
|
arch Arch
|
||||||
|
hod HostOrDevice
|
||||||
debug bool
|
debug bool
|
||||||
config Config
|
config Config
|
||||||
}
|
}
|
||||||
@@ -366,16 +377,20 @@ func (a *androidBaseContextImpl) Arch() Arch {
|
|||||||
return a.arch
|
return a.arch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice {
|
||||||
|
return a.hod
|
||||||
|
}
|
||||||
|
|
||||||
func (a *androidBaseContextImpl) Host() bool {
|
func (a *androidBaseContextImpl) Host() bool {
|
||||||
return a.arch.HostOrDevice.Host()
|
return a.hod.Host()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *androidBaseContextImpl) Device() bool {
|
func (a *androidBaseContextImpl) Device() bool {
|
||||||
return a.arch.HostOrDevice.Device()
|
return a.hod.Device()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *androidBaseContextImpl) Darwin() bool {
|
func (a *androidBaseContextImpl) Darwin() bool {
|
||||||
return a.arch.HostOrDevice.Host() && runtime.GOOS == "darwin"
|
return a.hod.Host() && runtime.GOOS == "darwin"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *androidBaseContextImpl) Debug() bool {
|
func (a *androidBaseContextImpl) Debug() bool {
|
||||||
@@ -391,7 +406,7 @@ func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string
|
|||||||
|
|
||||||
config := a.AConfig()
|
config := a.AConfig()
|
||||||
var fullInstallPath string
|
var fullInstallPath string
|
||||||
if a.arch.HostOrDevice.Device() {
|
if a.hod.Device() {
|
||||||
// TODO: replace unset with a device name once we have device targeting
|
// TODO: replace unset with a device name once we have device targeting
|
||||||
fullInstallPath = filepath.Join(config.DeviceOut(), "system",
|
fullInstallPath = filepath.Join(config.DeviceOut(), "system",
|
||||||
installPath, name)
|
installPath, name)
|
||||||
|
Reference in New Issue
Block a user