Add nested class loader subcontext at the proper hierarchy level.
When adding a subcontext in a class loader context tree, there are two possible cases: 1) the root of the subcontext is itself a <uses-library> and should be present as a node in the tree, or 2) the root is not a <uses-library>, but some of its dependencies are -- in that case they should be disconnected from the root, and the resulting forrest should be added at the top-level. Example: 1) C is a <uses-library>: A ├── B └── C ├── D └── E └── F 2) C is not a <uses-library>: A ├── B ├── D └── E └── F Before the patch subcontexts for transitive dependencies were added before the subcontext for the direct dependency (even if it was a <uses-library>, resulting in case-2 hierarchy when case-1 should have been used. Previosuly this didn't matter because class loader context was a flat set of libraries, but now it matters because class loader context is a tree. This patch changes the order in which libraries are added, so that direct dependencies are added before transitive ones. The context adding method now accepts an "implicit root" parameter, so that when adding transitive dependencies it can check if the corresponding direct dependency is a <uses-library> and already present in the context. Partially constructed class loader context is now propagated top-down into aapt.buildActions, so that the method can use existing part of the context to decide where the missing part should be connected. Test: lunch aosp_cf_x86_phone-userdebug && m Bug: 132357300 Change-Id: I649aff9e27494306885a4f4fc90226c399636b57
This commit is contained in:
47
java/aar.go
47
java/aar.go
@@ -109,7 +109,6 @@ type aapt struct {
|
||||
useEmbeddedNativeLibs bool
|
||||
useEmbeddedDex bool
|
||||
usesNonSdkApis bool
|
||||
sdkLibraries dexpreopt.ClassLoaderContextMap
|
||||
hasNoCode bool
|
||||
LoggingParent string
|
||||
resourceFiles android.Paths
|
||||
@@ -259,12 +258,11 @@ var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
|
||||
CommandDeps: []string{"${config.Zip2ZipCmd}"},
|
||||
})
|
||||
|
||||
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
|
||||
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext,
|
||||
sdkLibraries dexpreopt.ClassLoaderContextMap, extraLinkFlags ...string) {
|
||||
|
||||
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags, sdkLibraries :=
|
||||
aaptLibs(ctx, sdkContext)
|
||||
|
||||
a.sdkLibraries = sdkLibraries
|
||||
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags :=
|
||||
aaptLibs(ctx, sdkContext, sdkLibraries)
|
||||
|
||||
// App manifest file
|
||||
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
|
||||
@@ -391,29 +389,31 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
|
||||
}
|
||||
|
||||
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
||||
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths,
|
||||
staticRRODirs []rroDir, assets, deps android.Paths, flags []string, sdkLibraries dexpreopt.ClassLoaderContextMap) {
|
||||
func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext, sdkLibraries dexpreopt.ClassLoaderContextMap) (
|
||||
transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) {
|
||||
|
||||
var sharedLibs android.Paths
|
||||
|
||||
if sdkLibraries == nil {
|
||||
// Not all callers need to compute class loader context, those who don't just pass nil.
|
||||
// Create a temporary class loader context here (it will be computed, but not used).
|
||||
sdkLibraries = make(dexpreopt.ClassLoaderContextMap)
|
||||
}
|
||||
|
||||
sdkDep := decodeSdkDep(ctx, sdkContext)
|
||||
if sdkDep.useFiles {
|
||||
sharedLibs = append(sharedLibs, sdkDep.jars...)
|
||||
}
|
||||
|
||||
sdkLibraries = make(dexpreopt.ClassLoaderContextMap)
|
||||
|
||||
ctx.VisitDirectDeps(func(module android.Module) {
|
||||
depName := ctx.OtherModuleName(module)
|
||||
|
||||
var exportPackage android.Path
|
||||
aarDep, _ := module.(AndroidLibraryDependency)
|
||||
if aarDep != nil {
|
||||
exportPackage = aarDep.ExportPackage()
|
||||
}
|
||||
|
||||
if dep, ok := module.(Dependency); ok {
|
||||
sdkLibraries.AddContextMap(dep.ExportedSdkLibs())
|
||||
}
|
||||
|
||||
switch ctx.OtherModuleDependencyTag(module) {
|
||||
case instrumentationForTag:
|
||||
// Nothing, instrumentationForTag is treated as libTag for javac but not for aapt2.
|
||||
@@ -439,7 +439,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
||||
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
|
||||
sdkLibraries.AddContextMap(aarDep.ExportedSdkLibs())
|
||||
sdkLibraries.AddContextMap(aarDep.ExportedSdkLibs(), depName)
|
||||
if aarDep.ExportedAssets().Valid() {
|
||||
assets = append(assets, aarDep.ExportedAssets().Path())
|
||||
}
|
||||
@@ -457,6 +457,12 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add nested dependencies after processing the direct dependency: if it is a <uses-library>,
|
||||
// nested context is added as its subcontext, and should not be re-added at the top-level.
|
||||
if dep, ok := module.(Dependency); ok {
|
||||
sdkLibraries.AddContextMap(dep.ExportedSdkLibs(), depName)
|
||||
}
|
||||
})
|
||||
|
||||
deps = append(deps, sharedLibs...)
|
||||
@@ -473,7 +479,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
|
||||
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
||||
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
|
||||
|
||||
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags, sdkLibraries
|
||||
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags
|
||||
}
|
||||
|
||||
type AndroidLibrary struct {
|
||||
@@ -508,8 +514,8 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
|
||||
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
a.aapt.isLibrary = true
|
||||
a.aapt.buildActions(ctx, sdkContext(a))
|
||||
a.exportedSdkLibs = a.aapt.sdkLibraries
|
||||
a.exportedSdkLibs = make(dexpreopt.ClassLoaderContextMap)
|
||||
a.aapt.buildActions(ctx, sdkContext(a), a.exportedSdkLibs)
|
||||
|
||||
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
|
||||
|
||||
@@ -781,12 +787,11 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
||||
linkDeps = append(linkDeps, a.manifest)
|
||||
|
||||
transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags, sdkLibraries :=
|
||||
aaptLibs(ctx, sdkContext(a))
|
||||
transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags :=
|
||||
aaptLibs(ctx, sdkContext(a), nil)
|
||||
|
||||
_ = staticLibManifests
|
||||
_ = staticRRODirs
|
||||
_ = sdkLibraries
|
||||
|
||||
linkDeps = append(linkDeps, libDeps...)
|
||||
linkFlags = append(linkFlags, libFlags...)
|
||||
|
Reference in New Issue
Block a user