Move cc.imageMutator into the android package
Prepare for making the image mutator available to all modules and
moving it between the os and arch mutators by moving it into the
android package and using an interface implemented by the module
types to control it.
Bug: 142286466
Test: No unexpected changes to out/soong/build.ninja
Change-Id: I0dcc9c7b5ec80edffade340c367f6ae4da34151b
diff --git a/cc/cc.go b/cc/cc.go
index 06617ad..aa977e2 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -37,7 +37,7 @@
android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.BottomUp("vndk", VndkMutator).Parallel()
- ctx.BottomUp("image", ImageMutator).Parallel()
+ ctx.BottomUp("image", android.ImageMutator).Parallel()
ctx.BottomUp("link", LinkageMutator).Parallel()
ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
@@ -218,7 +218,10 @@
// Make this module available when building for recovery
Recovery_available *bool
- InRecovery bool `blueprint:"mutated"`
+ // Set by ImageMutator
+ CoreVariantNeeded bool `blueprint:"mutated"`
+ RecoveryVariantNeeded bool `blueprint:"mutated"`
+ VendorVariants []string `blueprint:"mutated"`
// Allows this module to use non-APEX version of libraries. Useful
// for building binaries that are started before APEXes are activated.
@@ -822,7 +825,7 @@
}
func (c *Module) InRecovery() bool {
- return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
+ return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
}
func (c *Module) OnlyInRecovery() bool {
@@ -1584,8 +1587,7 @@
depTag = headerExportDepTag
}
if buildStubs {
- actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
- blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}),
+ actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
depTag, lib)
} else {
actx.AddVariationDependencies(nil, depTag, lib)
@@ -1723,14 +1725,8 @@
if vndkdep := c.vndkdep; vndkdep != nil {
if vndkdep.isVndkExt() {
- var baseModuleMode string
- if actx.DeviceConfig().VndkVersion() == "" {
- baseModuleMode = coreMode
- } else {
- baseModuleMode = c.imageVariation()
- }
actx.AddVariationDependencies([]blueprint.Variation{
- {Mutator: "image", Variation: baseModuleMode},
+ c.ImageVariation(),
{Mutator: "link", Variation: "shared"},
}, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
}
@@ -2385,15 +2381,6 @@
return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
}
-func (c *Module) imageVariation() string {
- if c.UseVndk() {
- return vendorMode + "." + c.Properties.VndkVersion
- } else if c.InRecovery() {
- return recoveryMode
- }
- return coreMode
-}
-
func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
outputFiles, err := c.OutputFiles("")
if err != nil {
@@ -2477,15 +2464,9 @@
}
const (
- // coreMode is the variant used for framework-private libraries, or
- // SDK libraries. (which framework-private libraries can use)
- coreMode = "core"
-
- // vendorMode is the variant prefix used for /vendor code that compiles
+ // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
// against the VNDK.
- vendorMode = "vendor"
-
- recoveryMode = "recovery"
+ VendorVariationPrefix = "vendor."
)
func squashVendorSrcs(m *Module) {
@@ -2508,74 +2489,9 @@
}
}
-func ImageMutator(mctx android.BottomUpMutatorContext) {
- if mctx.Os() != android.Android {
- return
- }
+var _ android.ImageInterface = (*Module)(nil)
- if g, ok := mctx.Module().(*genrule.Module); ok {
- if props, ok := g.Extra.(*GenruleExtraProperties); ok {
- var coreVariantNeeded bool = false
- var vendorVariantNeeded bool = false
- var recoveryVariantNeeded bool = false
- if mctx.DeviceConfig().VndkVersion() == "" {
- coreVariantNeeded = true
- } else if Bool(props.Vendor_available) {
- coreVariantNeeded = true
- vendorVariantNeeded = true
- } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
- vendorVariantNeeded = true
- } else {
- coreVariantNeeded = true
- }
- if Bool(props.Recovery_available) {
- recoveryVariantNeeded = true
- }
-
- if recoveryVariantNeeded {
- primaryArch := mctx.Config().DevicePrimaryArchType()
- moduleArch := g.Target().Arch.ArchType
- if moduleArch != primaryArch {
- recoveryVariantNeeded = false
- }
- }
-
- var variants []string
- if coreVariantNeeded {
- variants = append(variants, coreMode)
- }
- if vendorVariantNeeded {
- variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion())
- if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" {
- variants = append(variants, vendorMode+"."+vndkVersion)
- }
- }
- if recoveryVariantNeeded {
- variants = append(variants, recoveryMode)
- }
- mod := mctx.CreateVariations(variants...)
- for i, v := range variants {
- if v == recoveryMode {
- m := mod[i].(*genrule.Module)
- m.Extra.(*GenruleExtraProperties).InRecovery = true
- }
- }
- }
- }
-
- //TODO When LinkableInterface supports VNDK, this should be mctx.Module().(LinkableInterface)
- m, ok := mctx.Module().(*Module)
- if !ok {
- if linkable, ok := mctx.Module().(LinkableInterface); ok {
- variations := []string{coreMode}
- if linkable.InRecovery() {
- variations = append(variations, recoveryMode)
- }
- mctx.CreateVariations(variations...)
- }
- return
- }
-
+func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
// Sanity check
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
productSpecific := mctx.ProductSpecific()
@@ -2583,7 +2499,6 @@
if m.VendorProperties.Vendor_available != nil && vendorSpecific {
mctx.PropertyErrorf("vendor_available",
"doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
- return
}
if vndkdep := m.vndkdep; vndkdep != nil {
@@ -2591,38 +2506,32 @@
if productSpecific {
mctx.PropertyErrorf("product_specific",
"product_specific must not be true when `vndk: {enabled: true}`")
- return
}
if vendorSpecific {
if !vndkdep.isVndkExt() {
mctx.PropertyErrorf("vndk",
"must set `extends: \"...\"` to vndk extension")
- return
}
} else {
if vndkdep.isVndkExt() {
mctx.PropertyErrorf("vndk",
"must set `vendor: true` to set `extends: %q`",
m.getVndkExtendsModuleName())
- return
}
if m.VendorProperties.Vendor_available == nil {
mctx.PropertyErrorf("vndk",
"vendor_available must be set to either true or false when `vndk: {enabled: true}`")
- return
}
}
} else {
if vndkdep.isVndkSp() {
mctx.PropertyErrorf("vndk",
"must set `enabled: true` to set `support_system_process: true`")
- return
}
if vndkdep.isVndkExt() {
mctx.PropertyErrorf("vndk",
"must set `enabled: true` to set `extends: %q`",
m.getVndkExtendsModuleName())
- return
}
}
}
@@ -2701,28 +2610,34 @@
}
}
- var variants []string
- if coreVariantNeeded {
- variants = append(variants, coreMode)
- }
for _, variant := range android.FirstUniqueStrings(vendorVariants) {
- variants = append(variants, vendorMode+"."+variant)
+ m.Properties.VendorVariants = append(m.Properties.VendorVariants, VendorVariationPrefix+variant)
}
- if recoveryVariantNeeded {
- variants = append(variants, recoveryMode)
- }
- mod := mctx.CreateVariations(variants...)
- for i, v := range variants {
- if strings.HasPrefix(v, vendorMode+".") {
- m := mod[i].(*Module)
- m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".")
- squashVendorSrcs(m)
- } else if v == recoveryMode {
- m := mod[i].(*Module)
- m.Properties.InRecovery = true
- m.MakeAsPlatform()
- squashRecoverySrcs(m)
- }
+
+ m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
+ m.Properties.CoreVariantNeeded = coreVariantNeeded
+}
+
+func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
+ return c.Properties.CoreVariantNeeded
+}
+
+func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
+ return c.Properties.RecoveryVariantNeeded
+}
+
+func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
+ return c.Properties.VendorVariants
+}
+
+func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
+ m := module.(*Module)
+ if variant == android.RecoveryVariation {
+ m.MakeAsPlatform()
+ squashRecoverySrcs(m)
+ } else if strings.HasPrefix(variant, VendorVariationPrefix) {
+ m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
+ squashVendorSrcs(m)
}
}
diff --git a/cc/genrule.go b/cc/genrule.go
index e594f4b..e74dd4d 100644
--- a/cc/genrule.go
+++ b/cc/genrule.go
@@ -26,9 +26,6 @@
type GenruleExtraProperties struct {
Vendor_available *bool
Recovery_available *bool
-
- // This genrule is for recovery variant
- InRecovery bool `blueprint:"mutated"`
}
// cc_genrule is a genrule that can depend on other cc_* objects.
@@ -37,7 +34,9 @@
func genRuleFactory() android.Module {
module := genrule.NewGenRule()
- module.Extra = &GenruleExtraProperties{}
+ extra := &GenruleExtraProperties{}
+ module.Extra = extra
+ module.ImageInterface = extra
module.AddProperties(module.Extra)
android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibBoth)
@@ -46,3 +45,44 @@
return module
}
+
+var _ android.ImageInterface = (*GenruleExtraProperties)(nil)
+
+func (g *GenruleExtraProperties) ImageMutatorBegin(ctx android.BaseModuleContext) {}
+
+func (g *GenruleExtraProperties) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
+ if ctx.DeviceConfig().VndkVersion() == "" {
+ return true
+ }
+
+ return Bool(g.Vendor_available) || !(ctx.SocSpecific() || ctx.DeviceSpecific())
+}
+
+func (g *GenruleExtraProperties) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
+ if Bool(g.Recovery_available) {
+ primaryArch := ctx.Config().DevicePrimaryArchType()
+ moduleArch := ctx.Target().Arch.ArchType
+ return moduleArch == primaryArch
+ }
+ return false
+}
+
+func (g *GenruleExtraProperties) ExtraImageVariations(ctx android.BaseModuleContext) []string {
+ if ctx.DeviceConfig().VndkVersion() == "" {
+ return nil
+ }
+
+ if Bool(g.Vendor_available) || ctx.SocSpecific() || ctx.DeviceSpecific() {
+ var variants []string
+ variants = append(variants, VendorVariationPrefix+ctx.DeviceConfig().PlatformVndkVersion())
+ if vndkVersion := ctx.DeviceConfig().VndkVersion(); vndkVersion != "current" {
+ variants = append(variants, VendorVariationPrefix+vndkVersion)
+ }
+ return variants
+ }
+
+ return nil
+}
+
+func (g *GenruleExtraProperties) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) {
+}
diff --git a/cc/library.go b/cc/library.go
index dde067c..91b864b 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1355,9 +1355,11 @@
return
}
if genrule, ok := mctx.Module().(*genrule.Module); ok {
- if props, ok := genrule.Extra.(*GenruleExtraProperties); ok && !props.InRecovery {
- mctx.CreateVariations("")
- return
+ if _, ok := genrule.Extra.(*GenruleExtraProperties); ok {
+ if !genrule.InRecovery() {
+ mctx.CreateVariations("")
+ return
+ }
}
}
}
diff --git a/cc/sanitize.go b/cc/sanitize.go
index 2bf051e..55bdd1c 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -886,13 +886,13 @@
// static executable gets static runtime libs
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "static"},
- {Mutator: "image", Variation: c.imageVariation()},
+ c.ImageVariation(),
}...), StaticDepTag, append([]string{runtimeLibrary}, extraStaticDeps...)...)
} else if !c.static() && !c.header() {
// dynamic executable and shared libs get shared runtime libs
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "shared"},
- {Mutator: "image", Variation: c.imageVariation()},
+ c.ImageVariation(),
}...), earlySharedDepTag, runtimeLibrary)
}
// static lib does not have dependency to the runtime library. The
diff --git a/cc/testing.go b/cc/testing.go
index 9ad72d9..e3f53ec 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -271,7 +271,7 @@
ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(VndkPrebuiltSharedFactory))
ctx.RegisterModuleType("vndk_libraries_txt", android.ModuleFactoryAdaptor(VndkLibrariesTxtFactory))
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
- ctx.BottomUp("image", ImageMutator).Parallel()
+ ctx.BottomUp("image", android.ImageMutator).Parallel()
ctx.BottomUp("link", LinkageMutator).Parallel()
ctx.BottomUp("vndk", VndkMutator).Parallel()
ctx.BottomUp("version", VersionMutator).Parallel()