summaryrefslogtreecommitdiff
path: root/cc
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2019-11-25 22:30:17 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2019-11-25 22:30:17 +0000
commit09ef474b6f797eb4f81e65b1736be30fbb3dd9cf (patch)
treebf03e0eab4434dc6defff90cbe0d0a23e3b78403 /cc
parent4b49b768a2cb7d455aea5347d27d9045b8c481fa (diff)
parent7228ecd5e3c9282e7e6f4a81d81fd333cb08eaff (diff)
Merge changes I0dcc9c7b,I9bc40642
* changes: Move cc.imageMutator into the android package Make CreateVariations return []android.Module
Diffstat (limited to 'cc')
-rw-r--r--cc/cc.go161
-rw-r--r--cc/genrule.go48
-rw-r--r--cc/library.go8
-rw-r--r--cc/sanitize.go4
-rw-r--r--cc/testing.go2
5 files changed, 90 insertions, 133 deletions
diff --git a/cc/cc.go b/cc/cc.go
index aa656da6e..f306a007e 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -37,7 +37,7 @@ func init() {
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 @@ type BaseProperties struct {
// 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.
@@ -826,7 +829,7 @@ func (c *Module) HasVendorVariant() bool {
}
func (c *Module) InRecovery() bool {
- return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
+ return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
}
func (c *Module) OnlyInRecovery() bool {
@@ -1588,8 +1591,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
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)
@@ -1727,14 +1729,8 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
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())
}
@@ -2389,15 +2385,6 @@ func (c *Module) installable() bool {
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 {
@@ -2481,15 +2468,9 @@ func DefaultsFactory(props ...interface{}) android.Module {
}
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) {
@@ -2512,74 +2493,9 @@ func squashRecoverySrcs(m *Module) {
}
}
-func ImageMutator(mctx android.BottomUpMutatorContext) {
- if mctx.Os() != android.Android {
- return
- }
-
- 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
- }
+var _ android.ImageInterface = (*Module)(nil)
+func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
// Sanity check
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
productSpecific := mctx.ProductSpecific()
@@ -2587,7 +2503,6 @@ func ImageMutator(mctx android.BottomUpMutatorContext) {
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 {
@@ -2595,38 +2510,32 @@ func ImageMutator(mctx android.BottomUpMutatorContext) {
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
}
}
}
@@ -2705,28 +2614,34 @@ func ImageMutator(mctx android.BottomUpMutatorContext) {
}
}
- 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 e594f4b2f..e74dd4d72 100644
--- a/cc/genrule.go
+++ b/cc/genrule.go
@@ -26,9 +26,6 @@ func init() {
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 @@ type GenruleExtraProperties struct {
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 @@ func genRuleFactory() android.Module {
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 b8c4b5125..98cae3d49 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1359,9 +1359,11 @@ func VersionMutator(mctx android.BottomUpMutatorContext) {
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 2bf051e5a..55bdd1c5c 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -886,13 +886,13 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
// 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 3943e72cc..3b10f876f 100644
--- a/cc/testing.go
+++ b/cc/testing.go
@@ -271,7 +271,7 @@ func CreateTestContext(bp string, fs map[string][]byte,
ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)
ctx.RegisterModuleType("vndk_libraries_txt", 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()