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/java/aar.go b/java/aar.go
index 9cab0bd..8d2a74a 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -477,6 +477,8 @@
a.aapt.buildActions(ctx, sdkContext(a))
a.exportedSdkLibs = a.aapt.sdkLibraries
+ a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
+
ctx.CheckbuildFile(a.proguardOptionsFile)
ctx.CheckbuildFile(a.exportPackage)
ctx.CheckbuildFile(a.aaptSrcJar)
@@ -569,6 +571,8 @@
manifest android.WritablePath
exportedStaticPackages android.Paths
+
+ hideApexVariantFromMake bool
}
func (a *AARImport) sdkVersion() sdkSpec {
@@ -662,6 +666,8 @@
return
}
+ a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
+
aarName := ctx.ModuleName() + ".aar"
var aar android.Path
aar = android.PathForModuleSrc(ctx, a.properties.Aars[0])
diff --git a/java/androidmk.go b/java/androidmk.go
index 65c44a3..f72ee37 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -23,8 +23,7 @@
func (library *Library) AndroidMkEntriesHostDex() android.AndroidMkEntries {
hostDexNeeded := Bool(library.deviceProperties.Hostdex) && !library.Host()
- if !library.IsForPlatform() {
- // Don't emit hostdex modules from the APEX variants
+ if library.hideApexVariantFromMake {
hostDexNeeded = false
}
@@ -61,22 +60,15 @@
func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
var entriesList []android.AndroidMkEntries
- mainEntries := android.AndroidMkEntries{Disabled: true}
-
- // For a java library built for an APEX, we don't need Make module
- hideFromMake := !library.IsForPlatform()
- // If not available for platform, don't emit to make.
- if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
- hideFromMake = true
- }
- if hideFromMake {
- // May still need to add some additional dependencies. This will be called
- // once for the platform variant (even if it is not being used) and once each
- // for the APEX specific variants. In order to avoid adding the dependency
- // multiple times only add it for the platform variant.
+ if library.hideApexVariantFromMake {
+ // For a java library built for an APEX we don't need Make module
+ entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
+ } else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) {
+ // Platform variant. If not available for the platform, we don't need Make module.
+ // May still need to add some additional dependencies.
checkedModulePaths := library.additionalCheckedModules
- if library.IsForPlatform() && len(checkedModulePaths) != 0 {
- mainEntries = android.AndroidMkEntries{
+ if len(checkedModulePaths) != 0 {
+ entriesList = append(entriesList, android.AndroidMkEntries{
Class: "FAKE",
// Need at least one output file in order for this to take effect.
OutputFile: android.OptionalPathForPath(checkedModulePaths[0]),
@@ -86,10 +78,12 @@
entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", checkedModulePaths.Strings()...)
},
},
- }
+ })
+ } else {
+ entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true})
}
} else {
- mainEntries = android.AndroidMkEntries{
+ entriesList = append(entriesList, android.AndroidMkEntries{
Class: "JAVA_LIBRARIES",
DistFiles: library.distFiles,
OutputFile: android.OptionalPathForPath(library.outputFile),
@@ -134,12 +128,11 @@
entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
},
},
- }
+ })
}
- hostDexEntries := library.AndroidMkEntriesHostDex()
+ entriesList = append(entriesList, library.AndroidMkEntriesHostDex())
- entriesList = append(entriesList, mainEntries, hostDexEntries)
return entriesList
}
@@ -189,7 +182,7 @@
}
func (prebuilt *Import) AndroidMkEntries() []android.AndroidMkEntries {
- if !prebuilt.IsForPlatform() || !prebuilt.ContainingSdk().Unversioned() {
+ if prebuilt.hideApexVariantFromMake || !prebuilt.ContainingSdk().Unversioned() {
return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true,
}}
@@ -211,7 +204,7 @@
}
func (prebuilt *DexImport) AndroidMkEntries() []android.AndroidMkEntries {
- if !prebuilt.IsForPlatform() {
+ if prebuilt.hideApexVariantFromMake {
return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true,
}}
@@ -239,7 +232,7 @@
}
func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries {
- if !prebuilt.IsForPlatform() {
+ if prebuilt.hideApexVariantFromMake {
return []android.AndroidMkEntries{{
Disabled: true,
}}
@@ -309,7 +302,7 @@
}
func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
- if !app.IsForPlatform() || app.appProperties.HideFromMake {
+ if app.hideApexVariantFromMake || app.appProperties.HideFromMake {
return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true,
}}
@@ -458,7 +451,7 @@
}
func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries {
- if !a.IsForPlatform() {
+ if a.hideApexVariantFromMake {
return []android.AndroidMkEntries{{
Disabled: true,
}}
@@ -638,7 +631,7 @@
}
func (a *AndroidAppImport) AndroidMkEntries() []android.AndroidMkEntries {
- if !a.IsForPlatform() {
+ if a.hideApexVariantFromMake {
// The non-platform variant is placed inside APEX. No reason to
// make it available to Make.
return nil
diff --git a/java/app.go b/java/app.go
index 13d08b9..c25835c 100755
--- a/java/app.go
+++ b/java/app.go
@@ -480,8 +480,9 @@
ctx.PropertyErrorf("min_sdk_version", "invalid value %q: %s", a.minSdkVersion(), err)
}
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
return (minSdkVersion >= 23 && Bool(a.appProperties.Use_embedded_native_libs)) ||
- !a.IsForPlatform()
+ !apexInfo.IsForPlatform()
}
// Returns whether this module should have the dex file stored uncompressed in the APK.
@@ -504,8 +505,9 @@
}
func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool {
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
return ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) ||
- !a.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
+ !apexInfo.IsForPlatform() || a.appProperties.AlwaysPackageNativeLibs
}
func generateAaptRenamePackageFlags(packageName string, renameResourcesPackage bool) []string {
@@ -756,6 +758,10 @@
func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
var apkDeps android.Paths
+ if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
+ a.hideApexVariantFromMake = true
+ }
+
a.aapt.useEmbeddedNativeLibs = a.useEmbeddedNativeLibs(ctx)
a.aapt.useEmbeddedDex = Bool(a.appProperties.Use_embedded_dex)
@@ -850,8 +856,10 @@
BuildBundleModule(ctx, bundleFile, a.exportPackage, jniJarFile, dexJarFile)
a.bundleFile = bundleFile
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+
// Install the app package.
- if (Bool(a.Module.properties.Installable) || ctx.Host()) && a.IsForPlatform() {
+ if (Bool(a.Module.properties.Installable) || ctx.Host()) && apexInfo.IsForPlatform() {
ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
for _, extra := range a.extraOutputFiles {
ctx.InstallFile(a.installDir, extra.Base(), extra)
@@ -979,7 +987,7 @@
}
func (a *AndroidApp) Updatable() bool {
- return Bool(a.appProperties.Updatable) || a.ApexModuleBase.Updatable()
+ return Bool(a.appProperties.Updatable)
}
func (a *AndroidApp) getCertString(ctx android.BaseModuleContext) string {
@@ -1335,6 +1343,8 @@
preprocessed bool
installPath android.InstallPath
+
+ hideApexVariantFromMake bool
}
type AndroidAppImportProperties struct {
@@ -1481,6 +1491,11 @@
}
func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext) {
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ if !apexInfo.IsForPlatform() {
+ a.hideApexVariantFromMake = true
+ }
+
numCertPropsSet := 0
if String(a.properties.Certificate) != "" {
numCertPropsSet++
@@ -1569,7 +1584,7 @@
// TODO: Optionally compress the output apk.
- if a.IsForPlatform() {
+ if apexInfo.IsForPlatform() {
a.installPath = ctx.InstallFile(installDir, apkFilename, a.outputFile)
}
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index f1b7178..20dbc66 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -94,7 +94,7 @@
}
// Don't preopt APEX variant module
- if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() {
+ if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
return true
}
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index 7877031..9f49786 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -266,12 +266,13 @@
}
// Check that this module satisfies constraints for a particular boot image.
- apex, isApexModule := module.(android.ApexModule)
- fromUpdatableApex := isApexModule && apex.Updatable()
+ _, isApexModule := module.(android.ApexModule)
+ apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
+ fromUpdatableApex := isApexModule && apexInfo.Updatable
if image.name == artBootImageName {
- if isApexModule && len(apex.InApexes()) > 0 && allHavePrefix(apex.InApexes(), "com.android.art.") {
+ if isApexModule && len(apexInfo.InApexes) > 0 && allHavePrefix(apexInfo.InApexes, "com.android.art.") {
// ok: found the jar in the ART apex
- } else if isApexModule && apex.IsForPlatform() && isHostdex(module) {
+ } else if isApexModule && apexInfo.IsForPlatform() && isHostdex(module) {
// exception (skip and continue): special "hostdex" platform variant
return -1, nil
} else if name == "jacocoagent" && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
@@ -279,7 +280,7 @@
return -1, nil
} else if fromUpdatableApex {
// error: this jar is part of an updatable apex other than ART
- ctx.Errorf("module %q from updatable apexes %q is not allowed in the ART boot image", name, apex.InApexes())
+ ctx.Errorf("module %q from updatable apexes %q is not allowed in the ART boot image", name, apexInfo.InApexes)
} else {
// error: this jar is part of the platform or a non-updatable apex
ctx.Errorf("module %q is not allowed in the ART boot image", name)
@@ -289,7 +290,7 @@
// ok: this jar is part of the platform or a non-updatable apex
} else {
// error: this jar is part of an updatable apex
- ctx.Errorf("module %q from updatable apexes %q is not allowed in the framework boot image", name, apex.InApexes())
+ ctx.Errorf("module %q from updatable apexes %q is not allowed in the framework boot image", name, apexInfo.InApexes)
}
} else {
panic("unknown boot image: " + image.name)
diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go
index 61a9b97..b140b89 100644
--- a/java/hiddenapi_singleton.go
+++ b/java/hiddenapi_singleton.go
@@ -161,10 +161,9 @@
// For a java lib included in an APEX, only take the one built for
// the platform variant, and skip the variants for APEXes.
// Otherwise, the hiddenapi tool will complain about duplicated classes
- if a, ok := module.(android.ApexModule); ok {
- if android.InAnyApex(module.Name()) && !a.IsForPlatform() {
- return
- }
+ apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
+ if !apexInfo.IsForPlatform() {
+ return
}
bootDexJars = append(bootDexJars, jar)
diff --git a/java/java.go b/java/java.go
index 1d7eaa7..7821035 100644
--- a/java/java.go
+++ b/java/java.go
@@ -451,6 +451,8 @@
// Collect the module directory for IDE info in java/jdeps.go.
modulePaths []string
+
+ hideApexVariantFromMake bool
}
func (j *Module) addHostProperties() {
@@ -638,8 +640,9 @@
// Force enable the instrumentation for java code that is built for APEXes ...
// except for the jacocoagent itself (because instrumenting jacocoagent using jacocoagent
// doesn't make sense) or framework libraries (e.g. libraries found in the InstrumentFrameworkModules list) unless EMMA_INSTRUMENT_FRAMEWORK is true.
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
isJacocoAgent := ctx.ModuleName() == "jacocoagent"
- if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !isJacocoAgent && !j.IsForPlatform() {
+ if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
return true
} else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
@@ -1590,7 +1593,8 @@
j.implementationAndResourcesJar = implementationAndResourcesJar
// Enable dex compilation for the APEX variants, unless it is disabled explicitly
- if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() {
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() {
if j.dexProperties.Compile_dex == nil {
j.dexProperties.Compile_dex = proptools.BoolPtr(true)
}
@@ -1672,7 +1676,7 @@
j.linter.compileSdkVersion = lintSDKVersionString(j.sdkVersion())
j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3"
- if j.ApexVariationName() != "" && ctx.Config().UnbundledBuildApps() {
+ if !apexInfo.IsForPlatform() && ctx.Config().UnbundledBuildApps() {
j.linter.buildModuleReportZip = true
}
j.linter.lint(ctx)
@@ -1934,7 +1938,7 @@
func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool {
// Store uncompressed (and aligned) any dex files from jars in APEXes.
- if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() {
+ if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
return true
}
@@ -1956,6 +1960,11 @@
}
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ if !apexInfo.IsForPlatform() {
+ j.hideApexVariantFromMake = true
+ }
+
j.checkSdkVersions(ctx)
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
@@ -1970,7 +1979,7 @@
// Collect the module directory for IDE info in java/jdeps.go.
j.modulePaths = append(j.modulePaths, ctx.ModuleDir())
- exclusivelyForApex := android.InAnyApex(ctx.ModuleName()) && !j.IsForPlatform()
+ exclusivelyForApex := !apexInfo.IsForPlatform()
if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex {
var extraInstallDeps android.Paths
if j.InstallMixin != nil {
@@ -2562,6 +2571,8 @@
combinedClasspathFile android.Path
exportedSdkLibs dexpreopt.LibraryPaths
exportAidlIncludeDirs android.Paths
+
+ hideApexVariantFromMake bool
}
func (j *Import) sdkVersion() sdkSpec {
@@ -2617,6 +2628,10 @@
}
func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ if !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() {
+ j.hideApexVariantFromMake = true
+ }
+
jars := android.PathsForModuleSrc(ctx, j.properties.Jars)
jarName := j.Stem() + ".jar"
@@ -2849,6 +2864,8 @@
maybeStrippedDexJarFile android.Path
dexpreopter
+
+ hideApexVariantFromMake bool
}
func (j *DexImport) Prebuilt() *android.Prebuilt {
@@ -2884,6 +2901,11 @@
ctx.PropertyErrorf("jars", "exactly one jar must be provided")
}
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ if !apexInfo.IsForPlatform() {
+ j.hideApexVariantFromMake = true
+ }
+
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter)
@@ -2928,7 +2950,7 @@
j.maybeStrippedDexJarFile = dexOutputFile
- if j.IsForPlatform() {
+ if apexInfo.IsForPlatform() {
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
j.Stem()+".jar", dexOutputFile)
}
diff --git a/java/lint.go b/java/lint.go
index 3a210cc..3df582f 100644
--- a/java/lint.go
+++ b/java/lint.go
@@ -451,10 +451,13 @@
return
}
- if apex, ok := m.(android.ApexModule); ok && apex.NotAvailableForPlatform() && apex.IsForPlatform() {
- // There are stray platform variants of modules in apexes that are not available for
- // the platform, and they sometimes can't be built. Don't depend on them.
- return
+ if apex, ok := m.(android.ApexModule); ok && apex.NotAvailableForPlatform() {
+ apexInfo := ctx.ModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
+ if apexInfo.IsForPlatform() {
+ // There are stray platform variants of modules in apexes that are not available for
+ // the platform, and they sometimes can't be built. Don't depend on them.
+ return
+ }
}
if l, ok := m.(lintOutputsIntf); ok {
diff --git a/java/sdk_library.go b/java/sdk_library.go
index 60924a6..3673ea1 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -1410,22 +1410,14 @@
return android.Paths{jarPath.Path()}
}
-// Get the apex names for module, nil if it is for platform.
-func getApexNamesForModule(module android.Module) []string {
- if apex, ok := module.(android.ApexModule); ok {
- return apex.InApexes()
- }
-
- return nil
-}
-
// Check to see if the other module is within the same set of named APEXes as this module.
//
// If either this or the other module are on the platform then this will return
// false.
-func withinSameApexesAs(module android.ApexModule, other android.Module) bool {
- names := module.InApexes()
- return len(names) > 0 && reflect.DeepEqual(names, getApexNamesForModule(other))
+func withinSameApexesAs(ctx android.BaseModuleContext, other android.Module) bool {
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ otherApexInfo := ctx.OtherModuleProvider(other, android.ApexInfoProvider).(android.ApexInfo)
+ return len(otherApexInfo.InApexes) > 0 && reflect.DeepEqual(apexInfo.InApexes, otherApexInfo.InApexes)
}
func (module *SdkLibrary) sdkJars(ctx android.BaseModuleContext, sdkVersion sdkSpec, headerJars bool) android.Paths {
@@ -1444,7 +1436,7 @@
// Only allow access to the implementation library in the following condition:
// * No sdk_version specified on the referencing module.
// * The referencing module is in the same apex as this.
- if sdkVersion.kind == sdkPrivate || withinSameApexesAs(module, ctx.Module()) {
+ if sdkVersion.kind == sdkPrivate || withinSameApexesAs(ctx, module) {
if headerJars {
return module.HeaderJars()
} else {
@@ -1961,7 +1953,7 @@
// For consistency with SdkLibrary make the implementation jar available to libraries that
// are within the same APEX.
implLibraryModule := module.implLibraryModule
- if implLibraryModule != nil && withinSameApexesAs(module, ctx.Module()) {
+ if implLibraryModule != nil && withinSameApexesAs(ctx, module) {
if headerJars {
return implLibraryModule.HeaderJars()
} else {
@@ -2057,6 +2049,8 @@
outputFilePath android.OutputPath
installDirPath android.InstallPath
+
+ hideApexVariantFromMake bool
}
type sdkLibraryXmlProperties struct {
@@ -2114,13 +2108,13 @@
}
// File path to the runtime implementation library
-func (module *sdkLibraryXml) implPath() string {
+func (module *sdkLibraryXml) implPath(ctx android.ModuleContext) string {
implName := proptools.String(module.properties.Lib_name)
- if apexName := module.ApexVariationName(); apexName != "" {
+ if apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo); !apexInfo.IsForPlatform() {
// TODO(b/146468504): ApexVariationName() is only a soong module name, not apex name.
// In most cases, this works fine. But when apex_name is set or override_apex is used
// this can be wrong.
- return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexName, implName)
+ return fmt.Sprintf("/apex/%s/javalib/%s.jar", apexInfo.ApexVariationName, implName)
}
partition := "system"
if module.SocSpecific() {
@@ -2136,8 +2130,10 @@
}
func (module *sdkLibraryXml) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ module.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
+
libName := proptools.String(module.properties.Lib_name)
- xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath())
+ xmlContent := fmt.Sprintf(permissionsTemplate, libName, module.implPath(ctx))
module.outputFilePath = android.PathForModuleOut(ctx, libName+".xml").OutputPath
rule := android.NewRuleBuilder()
@@ -2151,7 +2147,7 @@
}
func (module *sdkLibraryXml) AndroidMkEntries() []android.AndroidMkEntries {
- if !module.IsForPlatform() {
+ if module.hideApexVariantFromMake {
return []android.AndroidMkEntries{android.AndroidMkEntries{
Disabled: true,
}}