Skip version mutator for host/ramdisk/recovery

"version" mutator creates stubs variants for "cc" libraries with
"stubs.versions". These stubs are for APEX-APEX or APEX-Platform
boundaries.

For host/ramdisk/recovery variants, stubs are not necessary.

Bug: 153698496
Test: m
Change-Id: Id576c4318d9d69246a4a7e2fb4145d5fd2ab9416
This commit is contained in:
Jooyung Han 2020-04-10 12:57:24 +09:00
parent fc5608ec80
commit c40b5193fe
4 changed files with 22 additions and 12 deletions

View File

@ -1849,8 +1849,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
var variations []blueprint.Variation
variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
versionVariantAvail := !c.InRecovery() && !c.InRamdisk()
if version != "" && versionVariantAvail {
if version != "" && VersionVariantAvailable(c) {
// Version is explicitly specified. i.e. libFoo#30
variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
depTag.ExplicitlyVersioned = true
@ -1860,7 +1859,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
// If the version is not specified, add dependency to all stubs libraries.
// The stubs library will be used when the depending module is built for APEX and
// the dependent module is not in the same APEX.
if version == "" && versionVariantAvail {
if version == "" && VersionVariantAvailable(c) {
for _, ver := range stubsVersionsFor(actx.Config())[name] {
// Note that depTag.ExplicitlyVersioned is false in this case.
actx.AddVariationDependencies([]blueprint.Variation{
@ -2258,7 +2257,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
if ccDep.CcLibrary() && !depIsStatic {
depIsStubs := ccDep.BuildStubs()
depHasStubs := ccDep.HasStubsVariants()
depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
@ -2274,8 +2273,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// If not building for APEX, use stubs only when it is from
// an APEX (and not from platform)
useThisDep = (depInPlatform != depIsStubs)
if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
// However, for ramdisk, recovery or bootstrap modules,
if c.bootstrap() {
// However, for host, ramdisk, recovery or bootstrap modules,
// always link to non-stub variant
useThisDep = !depIsStubs
}

View File

@ -1486,10 +1486,18 @@ func createVersionVariations(mctx android.BottomUpMutatorContext, versions []str
}
}
// Version mutator splits a module into the mandatory non-stubs variant
func VersionVariantAvailable(module interface {
Host() bool
InRamdisk() bool
InRecovery() bool
}) bool {
return !module.Host() && !module.InRamdisk() && !module.InRecovery()
}
// VersionMutator splits a module into the mandatory non-stubs variant
// (which is unnamed) and zero or more stubs variants.
func VersionMutator(mctx android.BottomUpMutatorContext) {
if library, ok := mctx.Module().(LinkableInterface); ok && !library.InRecovery() {
if library, ok := mctx.Module().(LinkableInterface); ok && VersionVariantAvailable(library) {
if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 {
versions := library.StubsVersions()
normalizeVersions(mctx, versions)
@ -1525,7 +1533,7 @@ func VersionMutator(mctx android.BottomUpMutatorContext) {
}
if genrule, ok := mctx.Module().(*genrule.Module); ok {
if _, ok := genrule.Extra.(*GenruleExtraProperties); ok {
if !genrule.InRecovery() {
if VersionVariantAvailable(genrule) {
mctx.CreateVariations("")
return
}

View File

@ -39,6 +39,8 @@ type LinkableInterface interface {
Shared() bool
Toc() android.OptionalPath
Host() bool
InRamdisk() bool
OnlyInRamdisk() bool

View File

@ -727,13 +727,14 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
deps := mod.deps(ctx)
commonDepVariations := []blueprint.Variation{}
commonDepVariations = append(commonDepVariations,
blueprint.Variation{Mutator: "version", Variation: ""})
if cc.VersionVariantAvailable(mod) {
commonDepVariations = append(commonDepVariations,
blueprint.Variation{Mutator: "version", Variation: ""})
}
if !mod.Host() {
commonDepVariations = append(commonDepVariations,
blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
}
actx.AddVariationDependencies(
append(commonDepVariations, []blueprint.Variation{
{Mutator: "rust_libraries", Variation: "rlib"},