Merge "Add method to determine variations from a Target"

am: ad4a597c79

Change-Id: I98e8e5e0b8dd7f21d4f9bdf713c21daf396159f3
This commit is contained in:
Colin Cross 2019-10-17 13:17:17 -07:00 committed by android-build-merger
commit ee8633937f
15 changed files with 92 additions and 99 deletions

View File

@ -199,19 +199,19 @@ func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod bluep
switch amod.Os().Class {
case Host:
// Make cannot identify LOCAL_MODULE_HOST_ARCH:= common.
if archStr != "common" {
if amod.Arch().ArchType != Common {
a.SetString("LOCAL_MODULE_HOST_ARCH", archStr)
}
host = true
case HostCross:
// Make cannot identify LOCAL_MODULE_HOST_CROSS_ARCH:= common.
if archStr != "common" {
if amod.Arch().ArchType != Common {
a.SetString("LOCAL_MODULE_HOST_CROSS_ARCH", archStr)
}
host = true
case Device:
// Make cannot identify LOCAL_MODULE_TARGET_ARCH:= common.
if archStr != "common" {
if amod.Arch().ArchType != Common {
if amod.Target().NativeBridge {
hostArchStr := amod.Target().NativeBridgeHostArchName
if hostArchStr != "" {

View File

@ -22,9 +22,12 @@ import (
"strconv"
"strings"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
const COMMON_VARIANT = "common"
var (
archTypeList []ArchType
@ -36,7 +39,7 @@ var (
X86_64 = newArch("x86_64", "lib64")
Common = ArchType{
Name: "common",
Name: COMMON_VARIANT,
}
)
@ -702,11 +705,23 @@ type Target struct {
}
func (target Target) String() string {
variant := ""
return target.ArchVariation()
}
func (target Target) ArchVariation() string {
var variation string
if target.NativeBridge {
variant = "native_bridge_"
variation = "native_bridge_"
}
variation += target.Arch.String()
return target.Os.String() + "_" + variation
}
func (target Target) Variations() []blueprint.Variation {
return []blueprint.Variation{
{Mutator: "arch", Variation: target.ArchVariation()},
}
return target.Os.String() + "_" + variant + target.Arch.String()
}
// archMutator splits a module into a variant for each Target requested by the module. Target selection

View File

@ -89,9 +89,10 @@ type config struct {
ConfigFileName string
ProductVariablesFileName string
Targets map[OsType][]Target
BuildOsVariant string
BuildOsCommonVariant string
Targets map[OsType][]Target
BuildOSTarget Target // the Target for tools run on the build machine
BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine
AndroidCommonTarget Target // the Target for common modules for the Android device
// multilibConflicts for an ArchType is true if there is earlier configured device architecture with the same
// multilib value.
@ -289,8 +290,9 @@ func TestArchConfig(buildDir string, env map[string]string) Config {
config.Targets[BuildOs] = config.Targets[BuildOs][:1]
}
config.BuildOsVariant = config.Targets[BuildOs][0].String()
config.BuildOsCommonVariant = getCommonTargets(config.Targets[BuildOs])[0].String()
config.BuildOSTarget = config.Targets[BuildOs][0]
config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
@ -374,8 +376,11 @@ func NewConfig(srcDir, buildDir string) (Config, error) {
}
config.Targets = targets
config.BuildOsVariant = targets[BuildOs][0].String()
config.BuildOsCommonVariant = getCommonTargets(targets[BuildOs])[0].String()
config.BuildOSTarget = config.Targets[BuildOs][0]
config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0]
if len(config.Targets[Android]) > 0 {
config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
}
if err := config.fromEnv(); err != nil {
return Config{}, err

View File

@ -52,9 +52,8 @@ func ProtoDeps(ctx BottomUpMutatorContext, p *ProtoProperties) {
}
if plugin := String(p.Proto.Plugin); plugin != "" {
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Config().BuildOsVariant},
}, ProtoPluginDepTag, "protoc-gen-"+plugin)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(),
ProtoPluginDepTag, "protoc-gen-"+plugin)
}
}

View File

@ -619,28 +619,25 @@ type apexBundle struct {
func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext,
native_shared_libs []string, binaries []string, tests []string,
arch string, imageVariation string) {
target android.Target, imageVariation string) {
// Use *FarVariation* to be able to depend on modules having
// conflicting variations with this module. This is required since
// arch variant of an APEX bundle is 'common' but it is 'arm' or 'arm64'
// for native shared libs.
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: arch},
ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: imageVariation},
{Mutator: "link", Variation: "shared"},
{Mutator: "version", Variation: ""}, // "" is the non-stub variant
}, sharedLibTag, native_shared_libs...)
}...), sharedLibTag, native_shared_libs...)
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: arch},
{Mutator: "image", Variation: imageVariation},
}, executableTag, binaries...)
ctx.AddFarVariationDependencies(append(target.Variations(),
blueprint.Variation{Mutator: "image", Variation: imageVariation}),
executableTag, binaries...)
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: arch},
ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: imageVariation},
{Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
}, testTag, tests...)
}...), testTag, tests...)
}
func (a *apexBundle) combineProperties(ctx android.BottomUpMutatorContext) {
@ -672,49 +669,45 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
for i, target := range targets {
// When multilib.* is omitted for native_shared_libs, it implies
// multilib.both.
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: target.String()},
ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: a.getImageVariation(config)},
{Mutator: "link", Variation: "shared"},
}, sharedLibTag, a.properties.Native_shared_libs...)
}...), sharedLibTag, a.properties.Native_shared_libs...)
// When multilib.* is omitted for tests, it implies
// multilib.both.
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: target.String()},
ctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: a.getImageVariation(config)},
{Mutator: "test_per_src", Variation: ""}, // "" is the all-tests variant
}, testTag, a.properties.Tests...)
}...), testTag, a.properties.Tests...)
// Add native modules targetting both ABIs
addDependenciesForNativeModules(ctx,
a.properties.Multilib.Both.Native_shared_libs,
a.properties.Multilib.Both.Binaries,
a.properties.Multilib.Both.Tests,
target.String(),
target,
a.getImageVariation(config))
isPrimaryAbi := i == 0
if isPrimaryAbi {
// When multilib.* is omitted for binaries, it implies
// multilib.first.
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: target.String()},
{Mutator: "image", Variation: a.getImageVariation(config)},
}, executableTag, a.properties.Binaries...)
ctx.AddFarVariationDependencies(append(target.Variations(),
blueprint.Variation{Mutator: "image", Variation: a.getImageVariation(config)}),
executableTag, a.properties.Binaries...)
// Add native modules targetting the first ABI
addDependenciesForNativeModules(ctx,
a.properties.Multilib.First.Native_shared_libs,
a.properties.Multilib.First.Binaries,
a.properties.Multilib.First.Tests,
target.String(),
target,
a.getImageVariation(config))
// When multilib.* is omitted for prebuilts, it implies multilib.first.
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: target.String()},
}, prebuiltTag, a.properties.Prebuilts...)
ctx.AddFarVariationDependencies(target.Variations(),
prebuiltTag, a.properties.Prebuilts...)
}
switch target.Arch.ArchType.Multilib {
@ -724,14 +717,14 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
a.properties.Multilib.Lib32.Native_shared_libs,
a.properties.Multilib.Lib32.Binaries,
a.properties.Multilib.Lib32.Tests,
target.String(),
target,
a.getImageVariation(config))
addDependenciesForNativeModules(ctx,
a.properties.Multilib.Prefer32.Native_shared_libs,
a.properties.Multilib.Prefer32.Binaries,
a.properties.Multilib.Prefer32.Tests,
target.String(),
target,
a.getImageVariation(config))
case "lib64":
// Add native modules targetting 64-bit ABI
@ -739,7 +732,7 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
a.properties.Multilib.Lib64.Native_shared_libs,
a.properties.Multilib.Lib64.Binaries,
a.properties.Multilib.Lib64.Tests,
target.String(),
target,
a.getImageVariation(config))
if !has32BitTarget {
@ -747,7 +740,7 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
a.properties.Multilib.Prefer32.Native_shared_libs,
a.properties.Multilib.Prefer32.Binaries,
a.properties.Multilib.Prefer32.Tests,
target.String(),
target,
a.getImageVariation(config))
}
@ -756,7 +749,7 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
if sanitizer == "hwaddress" {
addDependenciesForNativeModules(ctx,
[]string{"libclang_rt.hwasan-aarch64-android"},
nil, nil, target.String(), a.getImageVariation(config))
nil, nil, target, a.getImageVariation(config))
break
}
}
@ -765,13 +758,11 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) {
}
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: "android_common"},
}, javaLibTag, a.properties.Java_libs...)
ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
javaLibTag, a.properties.Java_libs...)
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: "android_common"},
}, androidAppTag, a.properties.Apps...)
ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
androidAppTag, a.properties.Apps...)
if String(a.properties.Key) == "" {
ctx.ModuleErrorf("key is missing")
@ -1664,17 +1655,17 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexName, moduleDir string,
host := false
switch fi.module.Target().Os.Class {
case android.Host:
if archStr != "common" {
if fi.module.Target().Arch.ArchType != android.Common {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_ARCH :=", archStr)
}
host = true
case android.HostCross:
if archStr != "common" {
if fi.module.Target().Arch.ArchType != android.Common {
fmt.Fprintln(w, "LOCAL_MODULE_HOST_CROSS_ARCH :=", archStr)
}
host = true
case android.Device:
if archStr != "common" {
if fi.module.Target().Arch.ArchType != android.Common {
fmt.Fprintln(w, "LOCAL_MODULE_TARGET_ARCH :=", archStr)
}
}

View File

@ -1389,10 +1389,9 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
depTag = headerExportDepTag
}
if buildStubs {
actx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Target().String()},
{Mutator: "image", Variation: c.imageVariation()},
}, depTag, lib)
actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}),
depTag, lib)
} else {
actx.AddVariationDependencies(nil, depTag, lib)
}

View File

@ -884,18 +884,16 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
// added to libFlags and LOCAL_SHARED_LIBRARIES by cc.Module
if c.staticBinary() {
// static executable gets static runtime libs
mctx.AddFarVariationDependencies([]blueprint.Variation{
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "static"},
{Mutator: "image", Variation: c.imageVariation()},
{Mutator: "arch", Variation: mctx.Target().String()},
}, staticDepTag, runtimeLibrary)
}...), staticDepTag, runtimeLibrary)
} else if !c.static() && !c.header() {
// dynamic executable and shared libs get shared runtime libs
mctx.AddFarVariationDependencies([]blueprint.Variation{
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "shared"},
{Mutator: "image", Variation: c.imageVariation()},
{Mutator: "arch", Variation: mctx.Target().String()},
}, earlySharedDepTag, runtimeLibrary)
}...), earlySharedDepTag, runtimeLibrary)
}
// static lib does not have dependency to the runtime library. The
// dependency will be added to the executables or shared libs using

View File

@ -172,9 +172,7 @@ func (g *Module) DepsMutator(ctx android.BottomUpMutatorContext) {
if m := android.SrcIsModule(tool); m != "" {
tool = m
}
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Config().BuildOsVariant},
}, tag, tool)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), tag, tool)
}
}
}

View File

@ -167,10 +167,8 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
embedJni := a.shouldEmbedJnis(ctx)
for _, jniTarget := range ctx.MultiTargets() {
variation := []blueprint.Variation{
{Mutator: "arch", Variation: jniTarget.String()},
{Mutator: "link", Variation: "shared"},
}
variation := append(jniTarget.Variations(),
blueprint.Variation{Mutator: "link", Variation: "shared"})
tag := &jniDependencyTag{
target: jniTarget,
}

View File

@ -18,8 +18,6 @@ import (
"fmt"
"io"
"github.com/google/blueprint"
"android/soong/android"
)
@ -83,13 +81,13 @@ func HostForDeviceFactory() android.Module {
var deviceHostConverterDepTag = dependencyTag{name: "device_host_converter"}
func (d *DeviceForHost) DepsMutator(ctx android.BottomUpMutatorContext) {
variation := []blueprint.Variation{{Mutator: "arch", Variation: "android_common"}}
ctx.AddFarVariationDependencies(variation, deviceHostConverterDepTag, d.properties.Libs...)
ctx.AddFarVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(),
deviceHostConverterDepTag, d.properties.Libs...)
}
func (d *HostForDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
variation := []blueprint.Variation{{Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant}}
ctx.AddFarVariationDependencies(variation, deviceHostConverterDepTag, d.properties.Libs...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(),
deviceHostConverterDepTag, d.properties.Libs...)
}
func (d *DeviceHostConverter) GenerateAndroidBuildActions(ctx android.ModuleContext) {

View File

@ -60,7 +60,7 @@ func TestDeviceForHost(t *testing.T) {
deviceImportModule := ctx.ModuleForTests("device_import_module", "android_common")
deviceImportCombined := deviceImportModule.Output("combined/device_import_module.jar")
hostModule := ctx.ModuleForTests("host_module", config.BuildOsCommonVariant)
hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
hostJavac := hostModule.Output("javac/host_module.jar")
hostRes := hostModule.Output("res/host_module.jar")
combined := hostModule.Output("combined/host_module.jar")
@ -133,11 +133,11 @@ func TestHostForDevice(t *testing.T) {
ctx, config := testJava(t, bp)
hostModule := ctx.ModuleForTests("host_module", config.BuildOsCommonVariant)
hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
hostJavac := hostModule.Output("javac/host_module.jar")
hostRes := hostModule.Output("res/host_module.jar")
hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOsCommonVariant)
hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOSCommonTarget.String())
hostImportCombined := hostImportModule.Output("combined/host_import_module.jar")
deviceModule := ctx.ModuleForTests("device_module", "android_common")

View File

@ -551,9 +551,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...)
ctx.AddVariationDependencies(nil, staticLibTag, j.properties.Static_libs...)
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant},
}, pluginTag, j.properties.Plugins...)
ctx.AddFarVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), pluginTag, j.properties.Plugins...)
android.ProtoDeps(ctx, &j.protoProperties)
if j.hasSrcExt(".proto") {

View File

@ -306,22 +306,17 @@ func (p *Module) DepsMutator(ctx android.BottomUpMutatorContext) {
if p.bootstrapper.autorun() {
launcherModule = "py2-launcher-autorun"
}
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Target().String()},
}, launcherTag, launcherModule)
ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherTag, launcherModule)
// Add py2-launcher shared lib dependencies. Ideally, these should be
// derived from the `shared_libs` property of "py2-launcher". However, we
// cannot read the property at this stage and it will be too late to add
// dependencies later.
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Target().String()},
}, launcherSharedLibTag, "libsqlite")
ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag, "libsqlite")
if ctx.Target().Os.Bionic() {
ctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: ctx.Target().String()},
}, launcherSharedLibTag, "libc", "libdl", "libm")
ctx.AddFarVariationDependencies(ctx.Target().Variations(), launcherSharedLibTag,
"libc", "libdl", "libm")
}
}

View File

@ -496,7 +496,7 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}
// proc_macros are compiler plugins, and so we need the host arch variant as a dependendcy.
actx.AddFarVariationDependencies([]blueprint.Variation{{Mutator: "arch", Variation: ctx.Config().BuildOsVariant}}, procMacroDepTag, deps.ProcMacros...)
actx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(), procMacroDepTag, deps.ProcMacros...)
}
func (mod *Module) Name() string {

View File

@ -147,11 +147,10 @@ func memberMutator(mctx android.BottomUpMutatorContext) {
targets := mctx.MultiTargets()
for _, target := range targets {
mctx.AddFarVariationDependencies([]blueprint.Variation{
{Mutator: "arch", Variation: target.String()},
mctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
{Mutator: "image", Variation: "core"},
{Mutator: "link", Variation: "shared"},
}, sdkMemberDepTag, m.properties.Native_shared_libs...)
}...), sdkMemberDepTag, m.properties.Native_shared_libs...)
}
}
}