Create os and arch variants for bootstrap Go modules

AddFarVariationDependencies was broken, which allowed modules to add
dependencies on bootstrap Go modules using os and arch variations
even though boostrap Go modules did not have any variations.  Mutate
bootstrap Go modules in the os and arch mutators so that they have the
expected os and arch variations.

This relands Ida7bc75a51ab1d2d38a6be11f574399097380cc9 with fixes
to also mutate *bootstrap.goPackage modules so that they can find a
matching *bootstrap.goBinary module when creating their pluginFor
dependency, and to create a variation for linux_bionic when it is
enabled so that linux_bionic builds can package Go binaries.

Also requries https://github.com/google/blueprint/pull/320 to
support multiple variants of bootstrap Go modules.

Test: all soong tests
Change-Id: Ibc627aa262c298a076d171a4c21b0b9c2a7b0ada
This commit is contained in:
Colin Cross
2020-08-24 18:04:09 -07:00
parent b695937f12
commit 617b88a288
2 changed files with 54 additions and 13 deletions

View File

@@ -23,6 +23,7 @@ import (
"strings"
"github.com/google/blueprint"
"github.com/google/blueprint/bootstrap"
"github.com/google/blueprint/proptools"
)
@@ -689,13 +690,31 @@ func (target Target) Variations() []blueprint.Variation {
}
}
func osMutator(mctx BottomUpMutatorContext) {
func osMutator(bpctx blueprint.BottomUpMutatorContext) {
var module Module
var ok bool
if module, ok = mctx.Module().(Module); !ok {
if module, ok = bpctx.Module().(Module); !ok {
if bootstrap.IsBootstrapModule(bpctx.Module()) {
// Bootstrap Go modules are always the build OS or linux bionic.
config := bpctx.Config().(Config)
osNames := []string{config.BuildOSTarget.OsVariation()}
for _, hostCrossTarget := range config.Targets[LinuxBionic] {
if hostCrossTarget.Arch.ArchType == config.BuildOSTarget.Arch.ArchType {
osNames = append(osNames, hostCrossTarget.OsVariation())
}
}
osNames = FirstUniqueStrings(osNames)
bpctx.CreateVariations(osNames...)
}
return
}
// Bootstrap Go module support above requires this mutator to be a
// blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext
// filters out non-Soong modules. Now that we've handled them, create a
// normal android.BottomUpMutatorContext.
mctx := bottomUpMutatorContextFactory(bpctx, module, false)
base := module.base()
if !base.ArchSpecific() {
@@ -819,13 +838,23 @@ func GetOsSpecificVariantsOfCommonOSVariant(mctx BaseModuleContext) []Module {
//
// Modules can be initialized with InitAndroidMultiTargetsArchModule, in which case they will be split by OsClass,
// but will have a common Target that is expected to handle all other selected Targets via ctx.MultiTargets().
func archMutator(mctx BottomUpMutatorContext) {
func archMutator(bpctx blueprint.BottomUpMutatorContext) {
var module Module
var ok bool
if module, ok = mctx.Module().(Module); !ok {
if module, ok = bpctx.Module().(Module); !ok {
if bootstrap.IsBootstrapModule(bpctx.Module()) {
// Bootstrap Go modules are always the build architecture.
bpctx.CreateVariations(bpctx.Config().(Config).BuildOSTarget.ArchVariation())
}
return
}
// Bootstrap Go module support above requires this mutator to be a
// blueprint.BottomUpMutatorContext because android.BottomUpMutatorContext
// filters out non-Soong modules. Now that we've handled them, create a
// normal android.BottomUpMutatorContext.
mctx := bottomUpMutatorContextFactory(bpctx, module, false)
base := module.base()
if !base.ArchSpecific() {
@@ -903,7 +932,7 @@ func archMutator(mctx BottomUpMutatorContext) {
modules := mctx.CreateVariations(targetNames...)
for i, m := range modules {
addTargetProperties(m, targets[i], multiTargets, i == 0)
m.(Module).base().setArchProperties(mctx)
m.base().setArchProperties(mctx)
}
}