Remove global state from apex modules
A global variant was used to store the global mapping between
modules and APEXes. Replace it with storing pointers to APEX
contents inside each module so that they can query the contents
of any APEXes they belong to.
Bug: 146393795
Test: all Soong tests
Test: single line change to build.ninja host install dependency ordering
Test: no Android-${TARGET_PRODUCT}.mk, make_vars-${TARGET_PRODUCT}.mk or late-${TARGET_PRODUCT}.mk
Change-Id: Id2d7b73ea27f8c3b41d30820bdd86b65c539bfa4
diff --git a/cc/cc.go b/cc/cc.go
index 03290ad..8188550 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -366,6 +366,7 @@
bootstrap() bool
mustUseVendorVariant() bool
nativeCoverage() bool
+ directlyInAnyApex() bool
}
type ModuleContext interface {
@@ -545,8 +546,17 @@
dataLibDepTag = dependencyTag{name: "data lib"}
runtimeDepTag = dependencyTag{name: "runtime lib"}
testPerSrcDepTag = dependencyTag{name: "test_per_src"}
+ testForDepTag = dependencyTag{name: "test for apex"}
+
+ stubImplDepTag = copyDirectlyInAnyApexDependencyTag{name: "stub_impl"}
)
+type copyDirectlyInAnyApexDependencyTag dependencyTag
+
+func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
+
+var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
+
func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
ccLibDepTag, ok := depTag.(libraryDependencyTag)
return ok && ccLibDepTag.shared()
@@ -622,6 +632,8 @@
// For apex variants, this is set as apex.min_sdk_version
apexSdkVersion android.ApiLevel
+
+ hideApexVariantFromMake bool
}
func (c *Module) Toc() android.OptionalPath {
@@ -1363,11 +1375,11 @@
}
func (ctx *moduleContextImpl) isForPlatform() bool {
- return ctx.mod.IsForPlatform()
+ return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
}
func (ctx *moduleContextImpl) apexVariationName() string {
- return ctx.mod.ApexVariationName()
+ return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
}
func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
@@ -1390,6 +1402,10 @@
return ctx.mod.nativeCoverage()
}
+func (ctx *moduleContextImpl) directlyInAnyApex() bool {
+ return ctx.mod.DirectlyInAnyApex()
+}
+
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
return &Module{
hod: hod,
@@ -1545,6 +1561,11 @@
return
}
+ apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ if !apexInfo.IsForPlatform() {
+ c.hideApexVariantFromMake = true
+ }
+
c.makeLinkType = c.getMakeLinkType(actx)
c.Properties.SubName = ""
@@ -1676,8 +1697,7 @@
// force anything in the make world to link against the stubs library.
// (unless it is explicitly referenced via .bootstrap suffix or the
// module is marked with 'bootstrap: true').
- if c.HasStubsVariants() &&
- android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
+ if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() &&
!c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
c.IsStubs() {
c.Properties.HideFromMake = false // unhide
@@ -1686,13 +1706,13 @@
// glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
- if isSnapshotAware(ctx, c) {
+ if isSnapshotAware(ctx, c, apexInfo) {
i.collectHeadersForSnapshot(ctx)
}
}
}
- if c.installable() {
+ if c.installable(apexInfo) {
c.installer.install(ctx, c.outputFile.Path())
if ctx.Failed() {
return
@@ -2381,8 +2401,9 @@
// For the dependency from platform to apex, use the latest stubs
c.apexSdkVersion = android.FutureApiLevel
- if !c.IsForPlatform() {
- c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ if !apexInfo.IsForPlatform() {
+ c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
}
if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
@@ -2493,8 +2514,8 @@
if ccDep.CcLibrary() && !libDepTag.static() {
depIsStubs := ccDep.BuildStubs()
depHasStubs := CanBeOrLinkAgainstVersionVariants(c) && ccDep.HasStubsVariants()
- depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
- depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
+ depInSameApexes := android.DirectlyInAllApexes(apexInfo, depName)
+ depInPlatform := !dep.(android.ApexModule).AnyVariantDirectlyInAnyApex()
var useThisDep bool
if depIsStubs && libDepTag.explicitlyVersioned {
@@ -2504,7 +2525,7 @@
// Use non-stub variant if that is the only choice
// (i.e. depending on a lib without stubs.version property)
useThisDep = true
- } else if c.IsForPlatform() {
+ } else if apexInfo.IsForPlatform() {
// If not building for APEX, use stubs only when it is from
// an APEX (and not from platform)
useThisDep = (depInPlatform != depIsStubs)
@@ -2513,11 +2534,12 @@
// always link to non-stub variant
useThisDep = !depIsStubs
}
- for _, testFor := range c.TestFor() {
- // Another exception: if this module is bundled with an APEX, then
- // it is linked with the non-stub variant of a module in the APEX
- // as if this is part of the APEX.
- if android.DirectlyInApex(testFor, depName) {
+ // Another exception: if this module is bundled with an APEX, then
+ // it is linked with the non-stub variant of a module in the APEX
+ // as if this is part of the APEX.
+ testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
+ for _, apexContents := range testFor.ApexContents {
+ if apexContents.DirectlyInApex(depName) {
useThisDep = !depIsStubs
break
}
@@ -2549,7 +2571,7 @@
// by default, use current version of LLNDK
versionToUse := ""
versions := m.AllStubsVersions()
- if c.ApexVariationName() != "" && len(versions) > 0 {
+ if apexInfo.ApexVariationName != "" && len(versions) > 0 {
// if this is for use_vendor apex && dep has stubsVersions
// apply the same rule of apex sdk enforcement to choose right version
var err error
@@ -2711,10 +2733,11 @@
c.Properties.AndroidMkHeaderLibs, makeLibName)
case libDepTag.shared():
if ccDep.CcLibrary() {
- if ccDep.BuildStubs() && android.InAnyApex(depName) {
+ if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() {
// Add the dependency to the APEX(es) providing the library so that
// m <module> can trigger building the APEXes as well.
- for _, an := range android.GetApexesForModule(depName) {
+ depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
+ for _, an := range depApexInfo.InApexes {
c.Properties.ApexesProvidingSharedLibs = append(
c.Properties.ApexesProvidingSharedLibs, an)
}
@@ -3018,7 +3041,7 @@
c.installer.everInstallable()
}
-func (c *Module) installable() bool {
+func (c *Module) installable(apexInfo android.ApexInfo) bool {
ret := c.EverInstallable() &&
// Check to see whether the module has been configured to not be installed.
proptools.BoolDefault(c.Properties.Installable, true) &&
@@ -3027,7 +3050,7 @@
// The platform variant doesn't need further condition. Apex variants however might not
// be installable because it will likely to be included in the APEX and won't appear
// in the system partition.
- if c.IsForPlatform() {
+ if apexInfo.IsForPlatform() {
return ret
}