diff options
| author | Colin Cross <ccross@android.com> | 2015-05-07 14:11:29 -0700 |
|---|---|---|
| committer | Colin Cross <ccross@google.com> | 2015-05-09 00:10:19 +0000 |
| commit | d3ba039f74da29fc3d4184850e6e29acba58057c (patch) | |
| tree | 8fa86124d4c62f351be43338891ff2b3782ebfbf /common | |
| parent | af11df153818e2d4be62da430cd386b66580f7a0 (diff) | |
| download | build_soong-d3ba039f74da29fc3d4184850e6e29acba58057c.tar.gz build_soong-d3ba039f74da29fc3d4184850e6e29acba58057c.tar.bz2 build_soong-d3ba039f74da29fc3d4184850e6e29acba58057c.zip | |
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
Diffstat (limited to 'common')
| -rw-r--r-- | common/arch.go | 98 | ||||
| -rw-r--r-- | common/module.go | 25 |
2 files changed, 81 insertions, 42 deletions
diff --git a/common/arch.go b/common/arch.go index 38613a06..2a09ae95 100644 --- a/common/arch.go +++ b/common/arch.go @@ -129,15 +129,14 @@ type archProperties struct { // An Arch indicates a single CPU architecture. type Arch struct { - HostOrDevice HostOrDevice - ArchType ArchType - ArchVariant string - CpuVariant string - Abi string + ArchType ArchType + ArchVariant string + CpuVariant string + Abi string } func (a Arch) String() string { - s := a.HostOrDevice.String() + "_" + a.ArchType.String() + s := a.ArchType.String() if a.ArchVariant != "" { s += "_" + a.ArchVariant } @@ -247,37 +246,60 @@ var hostOrDeviceName = map[HostOrDevice]string{ var ( armArch = Arch{ - HostOrDevice: Device, - ArchType: Arm, - ArchVariant: "armv7-a-neon", - CpuVariant: "cortex-a15", - Abi: "armeabi-v7a", + ArchType: Arm, + ArchVariant: "armv7-a-neon", + CpuVariant: "cortex-a15", + Abi: "armeabi-v7a", } arm64Arch = Arch{ - HostOrDevice: Device, - ArchType: Arm64, - ArchVariant: "armv8-a", - CpuVariant: "denver", - Abi: "arm64-v8a", + ArchType: Arm64, + ArchVariant: "armv8-a", + CpuVariant: "denver", + Abi: "arm64-v8a", } - hostArch = Arch{ - HostOrDevice: Host, - ArchType: X86, + x86Arch = Arch{ + ArchType: X86, } - host64Arch = Arch{ - HostOrDevice: Host, - ArchType: X86_64, + x8664Arch = Arch{ + ArchType: X86_64, } - commonDevice = Arch{ - HostOrDevice: Device, - ArchType: Common, - } - commonHost = Arch{ - HostOrDevice: Host, - ArchType: Common, + commonArch = Arch{ + 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) { var module AndroidModule var ok bool @@ -290,19 +312,19 @@ func ArchMutator(mctx blueprint.EarlyMutatorContext) { arches := []Arch{} - if module.base().HostSupported() { + if module.base().HostSupported() && module.base().HostOrDevice().Host() { switch module.base().commonProperties.Compile_multilib { case "common": - arches = append(arches, commonHost) + arches = append(arches, commonArch) 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 { case "common": - arches = append(arches, commonDevice) + arches = append(arches, commonArch) case "both": arches = append(arches, arm64Arch, armArch) case "first", "64": @@ -328,7 +350,7 @@ func ArchMutator(mctx blueprint.EarlyMutatorContext) { for i, m := range modules { 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. -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 { return } @@ -406,7 +431,6 @@ func (a *AndroidModuleBase) setArchProperties(ctx blueprint.EarlyMutatorContext, // key: value, // }, // }, - hod := arch.HostOrDevice a.extendProperties(ctx, "target", hod.FieldLower(), generalPropsValue, reflect.ValueOf(a.archProperties[i].Target).FieldByName(hod.Field()).Elem().Elem()) diff --git a/common/module.go b/common/module.go index d9337885..ef7c63ae 100644 --- a/common/module.go +++ b/common/module.go @@ -32,6 +32,7 @@ var ( type androidBaseContext interface { Arch() Arch + HostOrDevice() HostOrDevice Host() bool Device() bool Darwin() bool @@ -86,6 +87,9 @@ type commonProperties struct { // platform Compile_multilib string + // Set by HostOrDeviceMutator + CompileHostOrDevice HostOrDevice `blueprint:"mutated"` + // Set by ArchMutator CompileArch Arch `blueprint:"mutated"` @@ -196,12 +200,16 @@ func (a *AndroidModuleBase) base() *AndroidModuleBase { return a } +func (a *AndroidModuleBase) SetHostOrDevice(hod HostOrDevice) { + a.commonProperties.CompileHostOrDevice = hod +} + func (a *AndroidModuleBase) SetArch(arch Arch) { a.commonProperties.CompileArch = arch } func (a *AndroidModuleBase) HostOrDevice() HostOrDevice { - return a.commonProperties.CompileArch.HostOrDevice + return a.commonProperties.CompileHostOrDevice } func (a *AndroidModuleBase) HostSupported() bool { @@ -293,6 +301,7 @@ func (a *AndroidModuleBase) DynamicDependencies(ctx blueprint.DynamicDependerMod DynamicDependerModuleContext: ctx, androidBaseContextImpl: androidBaseContextImpl{ arch: a.commonProperties.CompileArch, + hod: a.commonProperties.CompileHostOrDevice, config: ctx.Config().(Config), }, } @@ -309,6 +318,7 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { ModuleContext: ctx, androidBaseContextImpl: androidBaseContextImpl{ arch: a.commonProperties.CompileArch, + hod: a.commonProperties.CompileHostOrDevice, config: ctx.Config().(Config), }, installDeps: a.computeInstallDeps(ctx), @@ -336,6 +346,7 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) { type androidBaseContextImpl struct { arch Arch + hod HostOrDevice debug bool config Config } @@ -366,16 +377,20 @@ func (a *androidBaseContextImpl) Arch() Arch { return a.arch } +func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice { + return a.hod +} + func (a *androidBaseContextImpl) Host() bool { - return a.arch.HostOrDevice.Host() + return a.hod.Host() } func (a *androidBaseContextImpl) Device() bool { - return a.arch.HostOrDevice.Device() + return a.hod.Device() } 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 { @@ -391,7 +406,7 @@ func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string config := a.AConfig() var fullInstallPath string - if a.arch.HostOrDevice.Device() { + if a.hod.Device() { // TODO: replace unset with a device name once we have device targeting fullInstallPath = filepath.Join(config.DeviceOut(), "system", installPath, name) |
