Reland: Use depsets for transitive manifests and assets
Instead of rolling assets and manifests up through each static lib, provide them as a DepSet. This will help with the next patch, which needs to pass all the transitive manifests and R.txt files together. This relands Id8b3aa2bed3771e82ab6bde192c9b43baa38b54c with a fix to include additional manifests from dependencies in the final manifest merger. Test: app_test.go Test: TestManifestMerger Change-Id: Ied0a6cfee2f18e87188db145b9411d4a903ab6c9
This commit is contained in:
parent
02bccdf37c
commit
ab8d138d42
4 changed files with 190 additions and 116 deletions
271
java/aar.go
271
java/aar.go
|
@ -31,10 +31,9 @@ import (
|
||||||
type AndroidLibraryDependency interface {
|
type AndroidLibraryDependency interface {
|
||||||
LibraryDependency
|
LibraryDependency
|
||||||
ExportPackage() android.Path
|
ExportPackage() android.Path
|
||||||
ExportedRRODirs() []rroDir
|
ResourcesNodeDepSet() *android.DepSet[*resourcesNode]
|
||||||
ExportedStaticPackages() android.Paths
|
RRODirsDepSet() *android.DepSet[rroDir]
|
||||||
ExportedManifests() android.Paths
|
ManifestsDepSet() *android.DepSet[android.Path]
|
||||||
ExportedAssets() android.OptionalPath
|
|
||||||
SetRROEnforcedForDependent(enforce bool)
|
SetRROEnforcedForDependent(enforce bool)
|
||||||
IsRROEnforced(ctx android.BaseModuleContext) bool
|
IsRROEnforced(ctx android.BaseModuleContext) bool
|
||||||
}
|
}
|
||||||
|
@ -94,30 +93,32 @@ type aaptProperties struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type aapt struct {
|
type aapt struct {
|
||||||
aaptSrcJar android.Path
|
aaptSrcJar android.Path
|
||||||
exportPackage android.Path
|
exportPackage android.Path
|
||||||
manifestPath android.Path
|
manifestPath android.Path
|
||||||
transitiveManifestPaths android.Paths
|
proguardOptionsFile android.Path
|
||||||
proguardOptionsFile android.Path
|
rTxt android.Path
|
||||||
rroDirs []rroDir
|
extraAaptPackagesFile android.Path
|
||||||
rTxt android.Path
|
mergedManifestFile android.Path
|
||||||
extraAaptPackagesFile android.Path
|
noticeFile android.OptionalPath
|
||||||
mergedManifestFile android.Path
|
assetPackage android.OptionalPath
|
||||||
noticeFile android.OptionalPath
|
isLibrary bool
|
||||||
assetPackage android.OptionalPath
|
defaultManifestVersion string
|
||||||
isLibrary bool
|
useEmbeddedNativeLibs bool
|
||||||
defaultManifestVersion string
|
useEmbeddedDex bool
|
||||||
useEmbeddedNativeLibs bool
|
usesNonSdkApis bool
|
||||||
useEmbeddedDex bool
|
hasNoCode bool
|
||||||
usesNonSdkApis bool
|
LoggingParent string
|
||||||
hasNoCode bool
|
resourceFiles android.Paths
|
||||||
LoggingParent string
|
|
||||||
resourceFiles android.Paths
|
|
||||||
|
|
||||||
splitNames []string
|
splitNames []string
|
||||||
splits []split
|
splits []split
|
||||||
|
|
||||||
aaptProperties aaptProperties
|
aaptProperties aaptProperties
|
||||||
|
|
||||||
|
resourcesNodesDepSet *android.DepSet[*resourcesNode]
|
||||||
|
rroDirsDepSet *android.DepSet[rroDir]
|
||||||
|
manifestsDepSet *android.DepSet[android.Path]
|
||||||
}
|
}
|
||||||
|
|
||||||
type split struct {
|
type split struct {
|
||||||
|
@ -141,17 +142,16 @@ func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) {
|
||||||
func (a *aapt) ExportPackage() android.Path {
|
func (a *aapt) ExportPackage() android.Path {
|
||||||
return a.exportPackage
|
return a.exportPackage
|
||||||
}
|
}
|
||||||
|
func (a *aapt) ResourcesNodeDepSet() *android.DepSet[*resourcesNode] {
|
||||||
func (a *aapt) ExportedRRODirs() []rroDir {
|
return a.resourcesNodesDepSet
|
||||||
return a.rroDirs
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) ExportedManifests() android.Paths {
|
func (a *aapt) RRODirsDepSet() *android.DepSet[rroDir] {
|
||||||
return a.transitiveManifestPaths
|
return a.rroDirsDepSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) ExportedAssets() android.OptionalPath {
|
func (a *aapt) ManifestsDepSet() *android.DepSet[android.Path] {
|
||||||
return a.assetPackage
|
return a.manifestsDepSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *aapt) SetRROEnforcedForDependent(enforce bool) {
|
func (a *aapt) SetRROEnforcedForDependent(enforce bool) {
|
||||||
|
@ -291,7 +291,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
||||||
classLoaderContexts dexpreopt.ClassLoaderContextMap, excludedLibs []string,
|
classLoaderContexts dexpreopt.ClassLoaderContextMap, excludedLibs []string,
|
||||||
enforceDefaultTargetSdkVersion bool, extraLinkFlags ...string) {
|
enforceDefaultTargetSdkVersion bool, extraLinkFlags ...string) {
|
||||||
|
|
||||||
transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assetPackages, libDeps, libFlags :=
|
staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedDeps, libFlags :=
|
||||||
aaptLibs(ctx, sdkContext, classLoaderContexts)
|
aaptLibs(ctx, sdkContext, classLoaderContexts)
|
||||||
|
|
||||||
// Exclude any libraries from the supplied list.
|
// Exclude any libraries from the supplied list.
|
||||||
|
@ -314,13 +314,20 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
||||||
EnforceDefaultTargetSdkVersion: enforceDefaultTargetSdkVersion,
|
EnforceDefaultTargetSdkVersion: enforceDefaultTargetSdkVersion,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList())
|
||||||
|
|
||||||
// Add additional manifest files to transitive manifests.
|
// Add additional manifest files to transitive manifests.
|
||||||
additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
|
additionalManifests := android.PathsForModuleSrc(ctx, a.aaptProperties.Additional_manifests)
|
||||||
a.transitiveManifestPaths = append(android.Paths{manifestPath}, additionalManifests...)
|
transitiveManifestPaths := append(android.Paths{manifestPath}, additionalManifests...)
|
||||||
a.transitiveManifestPaths = append(a.transitiveManifestPaths, transitiveStaticLibManifests...)
|
// TODO(b/288358614): Soong has historically not merged manifests from dependencies of android_library_import
|
||||||
|
// modules. Merging manifests from dependencies could remove the need for pom2bp to generate the "-nodeps" copies
|
||||||
|
// of androidx libraries, but doing so triggers errors due to errors introduced by existing dependencies of
|
||||||
|
// android_library_import modules. If this is fixed, staticManifestsDepSet can be dropped completely in favor of
|
||||||
|
// staticResourcesNodesDepSet.manifests()
|
||||||
|
transitiveManifestPaths = append(transitiveManifestPaths, staticManifestsDepSet.ToList()...)
|
||||||
|
|
||||||
if len(a.transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
|
if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
|
||||||
a.mergedManifestFile = manifestMerger(ctx, a.transitiveManifestPaths[0], a.transitiveManifestPaths[1:], a.isLibrary)
|
a.mergedManifestFile = manifestMerger(ctx, transitiveManifestPaths[0], transitiveManifestPaths[1:], a.isLibrary)
|
||||||
if !a.isLibrary {
|
if !a.isLibrary {
|
||||||
// Only use the merged manifest for applications. For libraries, the transitive closure of manifests
|
// Only use the merged manifest for applications. For libraries, the transitive closure of manifests
|
||||||
// will be propagated to the final application and merged there. The merged manifest for libraries is
|
// will be propagated to the final application and merged there. The merged manifest for libraries is
|
||||||
|
@ -333,9 +340,9 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
||||||
|
|
||||||
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
|
||||||
|
|
||||||
rroDirs = append(rroDirs, staticRRODirs...)
|
|
||||||
linkFlags = append(linkFlags, libFlags...)
|
linkFlags = append(linkFlags, libFlags...)
|
||||||
linkDeps = append(linkDeps, libDeps...)
|
linkDeps = append(linkDeps, sharedDeps...)
|
||||||
|
linkDeps = append(linkDeps, staticDeps.resPackages()...)
|
||||||
linkFlags = append(linkFlags, extraLinkFlags...)
|
linkFlags = append(linkFlags, extraLinkFlags...)
|
||||||
if a.isLibrary {
|
if a.isLibrary {
|
||||||
linkFlags = append(linkFlags, "--static-lib")
|
linkFlags = append(linkFlags, "--static-lib")
|
||||||
|
@ -363,6 +370,10 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
||||||
|
|
||||||
var compiledRes, compiledOverlay android.Paths
|
var compiledRes, compiledOverlay android.Paths
|
||||||
|
|
||||||
|
// AAPT2 overlays are in lowest to highest priority order, reverse the topological order
|
||||||
|
// of transitiveStaticLibs.
|
||||||
|
transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages())
|
||||||
|
|
||||||
compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
|
compiledOverlay = append(compiledOverlay, transitiveStaticLibs...)
|
||||||
|
|
||||||
if len(transitiveStaticLibs) > 0 {
|
if len(transitiveStaticLibs) > 0 {
|
||||||
|
@ -404,12 +415,18 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No need to specify assets from dependencies to aapt2Link for libraries, all transitive assets will be
|
||||||
|
// provided to the final app aapt2Link step.
|
||||||
|
var transitiveAssets android.Paths
|
||||||
|
if !a.isLibrary {
|
||||||
|
transitiveAssets = android.ReverseSliceInPlace(staticDeps.assets())
|
||||||
|
}
|
||||||
aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
|
aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
|
||||||
linkFlags, linkDeps, compiledRes, compiledOverlay, assetPackages, splitPackages)
|
linkFlags, linkDeps, compiledRes, compiledOverlay, transitiveAssets, splitPackages)
|
||||||
|
|
||||||
// Extract assets from the resource package output so that they can be used later in aapt2link
|
// Extract assets from the resource package output so that they can be used later in aapt2link
|
||||||
// for modules that depend on this one.
|
// for modules that depend on this one.
|
||||||
if android.PrefixInList(linkFlags, "-A ") || len(assetPackages) > 0 {
|
if android.PrefixInList(linkFlags, "-A ") {
|
||||||
assets := android.PathForModuleOut(ctx, "assets.zip")
|
assets := android.PathForModuleOut(ctx, "assets.zip")
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: extractAssetsRule,
|
Rule: extractAssetsRule,
|
||||||
|
@ -424,17 +441,66 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
||||||
a.exportPackage = packageRes
|
a.exportPackage = packageRes
|
||||||
a.manifestPath = manifestPath
|
a.manifestPath = manifestPath
|
||||||
a.proguardOptionsFile = proguardOptionsFile
|
a.proguardOptionsFile = proguardOptionsFile
|
||||||
a.rroDirs = rroDirs
|
|
||||||
a.extraAaptPackagesFile = extraPackages
|
a.extraAaptPackagesFile = extraPackages
|
||||||
a.rTxt = rTxt
|
a.rTxt = rTxt
|
||||||
a.splits = splits
|
a.splits = splits
|
||||||
|
a.resourcesNodesDepSet = android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL).
|
||||||
|
Direct(&resourcesNode{
|
||||||
|
resPackage: a.exportPackage,
|
||||||
|
manifest: a.manifestPath,
|
||||||
|
additionalManifests: additionalManifests,
|
||||||
|
assets: a.assetPackage,
|
||||||
|
}).
|
||||||
|
Transitive(staticResourcesNodesDepSet).Build()
|
||||||
|
a.rroDirsDepSet = android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL).
|
||||||
|
Direct(rroDirs...).
|
||||||
|
Transitive(staticRRODirsDepSet).Build()
|
||||||
|
a.manifestsDepSet = android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).
|
||||||
|
Direct(a.manifestPath).
|
||||||
|
DirectSlice(additionalManifests).
|
||||||
|
Transitive(staticManifestsDepSet).Build()
|
||||||
|
}
|
||||||
|
|
||||||
|
type resourcesNode struct {
|
||||||
|
resPackage android.Path
|
||||||
|
manifest android.Path
|
||||||
|
additionalManifests android.Paths
|
||||||
|
assets android.OptionalPath
|
||||||
|
}
|
||||||
|
|
||||||
|
type transitiveAarDeps []*resourcesNode
|
||||||
|
|
||||||
|
func (t transitiveAarDeps) resPackages() android.Paths {
|
||||||
|
var paths android.Paths
|
||||||
|
for _, dep := range t {
|
||||||
|
paths = append(paths, dep.resPackage)
|
||||||
|
}
|
||||||
|
return android.FirstUniquePaths(paths)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t transitiveAarDeps) manifests() android.Paths {
|
||||||
|
var paths android.Paths
|
||||||
|
for _, dep := range t {
|
||||||
|
paths = append(paths, dep.manifest)
|
||||||
|
paths = append(paths, dep.additionalManifests...)
|
||||||
|
}
|
||||||
|
return android.FirstUniquePaths(paths)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t transitiveAarDeps) assets() android.Paths {
|
||||||
|
var paths android.Paths
|
||||||
|
for _, dep := range t {
|
||||||
|
if dep.assets.Valid() {
|
||||||
|
paths = append(paths, dep.assets.Path())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
// aaptLibs collects libraries from dependencies and sdk_version and converts them into paths
|
||||||
func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) (
|
func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoaderContexts dexpreopt.ClassLoaderContextMap) (
|
||||||
transitiveStaticLibs, transitiveStaticLibManifests android.Paths, staticRRODirs []rroDir, assets, deps android.Paths, flags []string) {
|
staticResourcesNodes *android.DepSet[*resourcesNode], staticRRODirs *android.DepSet[rroDir],
|
||||||
|
staticManifests *android.DepSet[android.Path], sharedLibs android.Paths, flags []string) {
|
||||||
var sharedLibs android.Paths
|
|
||||||
|
|
||||||
if classLoaderContexts == nil {
|
if classLoaderContexts == nil {
|
||||||
// Not all callers need to compute class loader context, those who don't just pass nil.
|
// Not all callers need to compute class loader context, those who don't just pass nil.
|
||||||
|
@ -447,6 +513,10 @@ func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoa
|
||||||
sharedLibs = append(sharedLibs, sdkDep.jars...)
|
sharedLibs = append(sharedLibs, sdkDep.jars...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var resourcesNodeDepSets []*android.DepSet[*resourcesNode]
|
||||||
|
rroDirsDepSetBuilder := android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL)
|
||||||
|
manifestsDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL)
|
||||||
|
|
||||||
ctx.VisitDirectDeps(func(module android.Module) {
|
ctx.VisitDirectDeps(func(module android.Module) {
|
||||||
depTag := ctx.OtherModuleDependencyTag(module)
|
depTag := ctx.OtherModuleDependencyTag(module)
|
||||||
|
|
||||||
|
@ -469,32 +539,28 @@ func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoa
|
||||||
}
|
}
|
||||||
case staticLibTag:
|
case staticLibTag:
|
||||||
if exportPackage != nil {
|
if exportPackage != nil {
|
||||||
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
|
resourcesNodeDepSets = append(resourcesNodeDepSets, aarDep.ResourcesNodeDepSet())
|
||||||
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
|
rroDirsDepSetBuilder.Transitive(aarDep.RRODirsDepSet())
|
||||||
transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
|
manifestsDepSetBuilder.Transitive(aarDep.ManifestsDepSet())
|
||||||
if aarDep.ExportedAssets().Valid() {
|
|
||||||
assets = append(assets, aarDep.ExportedAssets().Path())
|
|
||||||
}
|
|
||||||
|
|
||||||
outer:
|
|
||||||
for _, d := range aarDep.ExportedRRODirs() {
|
|
||||||
for _, e := range staticRRODirs {
|
|
||||||
if d.path == e.path {
|
|
||||||
continue outer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
staticRRODirs = append(staticRRODirs, d)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addCLCFromDep(ctx, module, classLoaderContexts)
|
addCLCFromDep(ctx, module, classLoaderContexts)
|
||||||
})
|
})
|
||||||
|
|
||||||
deps = append(deps, sharedLibs...)
|
// AAPT2 overlays are in lowest to highest priority order, the topological order will be reversed later.
|
||||||
deps = append(deps, transitiveStaticLibs...)
|
// Reverse the dependency order now going into the depset so that it comes out in order after the second
|
||||||
|
// reverse later.
|
||||||
|
// NOTE: this is legacy and probably incorrect behavior, for most other cases (e.g. conflicting classes in
|
||||||
|
// dependencies) the highest priority dependency is listed first, but for resources the highest priority
|
||||||
|
// dependency has to be listed last.
|
||||||
|
staticResourcesNodes = android.NewDepSet(android.TOPOLOGICAL, nil,
|
||||||
|
android.ReverseSliceInPlace(resourcesNodeDepSets))
|
||||||
|
|
||||||
if len(transitiveStaticLibs) > 0 {
|
staticRRODirs = rroDirsDepSetBuilder.Build()
|
||||||
|
staticManifests = manifestsDepSetBuilder.Build()
|
||||||
|
|
||||||
|
if len(staticResourcesNodes.ToList()) > 0 {
|
||||||
flags = append(flags, "--auto-add-overlay")
|
flags = append(flags, "--auto-add-overlay")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,10 +568,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext android.SdkContext, classLoa
|
||||||
flags = append(flags, "-I "+sharedLib.String())
|
flags = append(flags, "-I "+sharedLib.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
|
return staticResourcesNodes, staticRRODirs, staticManifests, sharedLibs, flags
|
||||||
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
|
|
||||||
|
|
||||||
return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, assets, deps, flags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidLibrary struct {
|
type AndroidLibrary struct {
|
||||||
|
@ -516,8 +579,6 @@ type AndroidLibrary struct {
|
||||||
androidLibraryProperties androidLibraryProperties
|
androidLibraryProperties androidLibraryProperties
|
||||||
|
|
||||||
aarFile android.WritablePath
|
aarFile android.WritablePath
|
||||||
|
|
||||||
exportedStaticPackages android.Paths
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ android.OutputFileProducer = (*AndroidLibrary)(nil)
|
var _ android.OutputFileProducer = (*AndroidLibrary)(nil)
|
||||||
|
@ -532,10 +593,6 @@ func (a *AndroidLibrary) OutputFiles(tag string) (android.Paths, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidLibrary) ExportedStaticPackages() android.Paths {
|
|
||||||
return a.exportedStaticPackages
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
|
var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
|
||||||
|
|
||||||
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
|
@ -579,19 +636,15 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
|
||||||
|
|
||||||
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles,
|
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles,
|
||||||
android.PathsForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)...)
|
android.PathsForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)...)
|
||||||
|
|
||||||
ctx.VisitDirectDeps(func(m android.Module) {
|
ctx.VisitDirectDeps(func(m android.Module) {
|
||||||
if ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
if ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
||||||
if lib, ok := m.(LibraryDependency); ok {
|
if lib, ok := m.(LibraryDependency); ok {
|
||||||
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
|
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
|
||||||
}
|
}
|
||||||
if alib, ok := m.(AndroidLibraryDependency); ok {
|
|
||||||
a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportPackage())
|
|
||||||
a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportedStaticPackages()...)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
|
a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
|
||||||
a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages)
|
|
||||||
|
|
||||||
prebuiltJniPackages := android.Paths{}
|
prebuiltJniPackages := android.Paths{}
|
||||||
ctx.VisitDirectDeps(func(module android.Module) {
|
ctx.VisitDirectDeps(func(module android.Module) {
|
||||||
|
@ -681,7 +734,8 @@ type AARImport struct {
|
||||||
manifest android.WritablePath
|
manifest android.WritablePath
|
||||||
assetsPackage android.WritablePath
|
assetsPackage android.WritablePath
|
||||||
|
|
||||||
exportedStaticPackages android.Paths
|
resourcesNodesDepSet *android.DepSet[*resourcesNode]
|
||||||
|
manifestsDepSet *android.DepSet[android.Path]
|
||||||
|
|
||||||
hideApexVariantFromMake bool
|
hideApexVariantFromMake bool
|
||||||
|
|
||||||
|
@ -738,25 +792,20 @@ var _ AndroidLibraryDependency = (*AARImport)(nil)
|
||||||
func (a *AARImport) ExportPackage() android.Path {
|
func (a *AARImport) ExportPackage() android.Path {
|
||||||
return a.exportPackage
|
return a.exportPackage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
|
func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
|
||||||
return android.Paths{a.proguardFlags}
|
return android.Paths{a.proguardFlags}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) ExportedRRODirs() []rroDir {
|
func (a *AARImport) ResourcesNodeDepSet() *android.DepSet[*resourcesNode] {
|
||||||
return nil
|
return a.resourcesNodesDepSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) ExportedStaticPackages() android.Paths {
|
func (a *AARImport) RRODirsDepSet() *android.DepSet[rroDir] {
|
||||||
return a.exportedStaticPackages
|
return android.NewDepSet[rroDir](android.TOPOLOGICAL, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AARImport) ExportedManifests() android.Paths {
|
func (a *AARImport) ManifestsDepSet() *android.DepSet[android.Path] {
|
||||||
return android.Paths{a.manifest}
|
return a.manifestsDepSet
|
||||||
}
|
|
||||||
|
|
||||||
func (a *AARImport) ExportedAssets() android.OptionalPath {
|
|
||||||
return android.OptionalPathForPath(a.assetsPackage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RRO enforcement is not available on aar_import since its RRO dirs are not
|
// RRO enforcement is not available on aar_import since its RRO dirs are not
|
||||||
|
@ -891,32 +940,44 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
linkFlags = append(linkFlags, "--manifest "+a.manifest.String())
|
||||||
linkDeps = append(linkDeps, a.manifest)
|
linkDeps = append(linkDeps, a.manifest)
|
||||||
|
|
||||||
transitiveStaticLibs, staticLibManifests, staticRRODirs, transitiveAssets, libDeps, libFlags :=
|
staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedLibs, libFlags :=
|
||||||
aaptLibs(ctx, android.SdkContext(a), nil)
|
aaptLibs(ctx, android.SdkContext(a), nil)
|
||||||
|
|
||||||
_ = staticLibManifests
|
_ = staticRRODirsDepSet
|
||||||
_ = staticRRODirs
|
staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList())
|
||||||
|
|
||||||
linkDeps = append(linkDeps, libDeps...)
|
// AAPT2 overlays are in lowest to highest priority order, reverse the topological order
|
||||||
|
// of transitiveStaticLibs.
|
||||||
|
transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages())
|
||||||
|
|
||||||
|
linkDeps = append(linkDeps, sharedLibs...)
|
||||||
|
linkDeps = append(linkDeps, transitiveStaticLibs...)
|
||||||
linkFlags = append(linkFlags, libFlags...)
|
linkFlags = append(linkFlags, libFlags...)
|
||||||
|
|
||||||
overlayRes := append(android.Paths{flata}, transitiveStaticLibs...)
|
overlayRes := append(android.Paths{flata}, transitiveStaticLibs...)
|
||||||
|
|
||||||
|
transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets())
|
||||||
aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
|
aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile,
|
||||||
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
|
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
|
||||||
|
|
||||||
// Merge this import's assets with its dependencies' assets (if there are any).
|
resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL)
|
||||||
if len(transitiveAssets) > 0 {
|
resourcesNodesDepSetBuilder.Direct(&resourcesNode{
|
||||||
mergedAssets := android.PathForModuleOut(ctx, "merged-assets.zip")
|
resPackage: a.exportPackage,
|
||||||
inputZips := append(android.Paths{a.assetsPackage}, transitiveAssets...)
|
manifest: a.manifest,
|
||||||
ctx.Build(pctx, android.BuildParams{
|
assets: android.OptionalPathForPath(a.assetsPackage),
|
||||||
Rule: mergeAssetsRule,
|
})
|
||||||
Inputs: inputZips,
|
resourcesNodesDepSetBuilder.Transitive(staticResourcesNodesDepSet)
|
||||||
Output: mergedAssets,
|
a.resourcesNodesDepSet = resourcesNodesDepSetBuilder.Build()
|
||||||
Description: "merge assets from dependencies and self",
|
|
||||||
})
|
manifestDepSetBuilder := android.NewDepSetBuilder[android.Path](android.TOPOLOGICAL).Direct(a.manifest)
|
||||||
a.assetsPackage = mergedAssets
|
// TODO(b/288358614): Soong has historically not merged manifests from dependencies of android_library_import
|
||||||
}
|
// modules. Merging manifests from dependencies could remove the need for pom2bp to generate the "-nodeps" copies
|
||||||
|
// of androidx libraries, but doing so triggers errors due to errors introduced by existing dependencies of
|
||||||
|
// android_library_import modules. If this is fixed, AndroidLibraryDependency.ManifestsDepSet can be dropped
|
||||||
|
// completely in favor of AndroidLibraryDependency.ResourceNodesDepSet.manifest
|
||||||
|
//manifestDepSetBuilder.Transitive(transitiveStaticDeps.manifests)
|
||||||
|
_ = staticManifestsDepSet
|
||||||
|
a.manifestsDepSet = manifestDepSetBuilder.Build()
|
||||||
|
|
||||||
a.collectTransitiveHeaderJars(ctx)
|
a.collectTransitiveHeaderJars(ctx)
|
||||||
ctx.SetProvider(JavaInfoProvider, JavaInfo{
|
ctx.SetProvider(JavaInfoProvider, JavaInfo{
|
||||||
|
|
|
@ -368,8 +368,13 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
|
||||||
|
|
||||||
filterRRO := func(filter overlayType) android.Paths {
|
filterRRO := func(filter overlayType) android.Paths {
|
||||||
var paths android.Paths
|
var paths android.Paths
|
||||||
for _, d := range app.rroDirs {
|
seen := make(map[android.Path]bool)
|
||||||
|
for _, d := range app.rroDirsDepSet.ToList() {
|
||||||
if d.overlayType == filter {
|
if d.overlayType == filter {
|
||||||
|
if seen[d.path] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[d.path] = true
|
||||||
paths = append(paths, d.path)
|
paths = append(paths, d.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,8 +204,8 @@ func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidApp) ExportedStaticPackages() android.Paths {
|
func (a *AndroidApp) ResourcesNodeDepSet() *android.DepSet[*resourcesNode] {
|
||||||
return nil
|
return a.aapt.resourcesNodesDepSet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidApp) OutputFile() android.Path {
|
func (a *AndroidApp) OutputFile() android.Path {
|
||||||
|
|
|
@ -599,7 +599,7 @@ func TestLibraryAssets(t *testing.T) {
|
||||||
android_library {
|
android_library {
|
||||||
name: "lib3",
|
name: "lib3",
|
||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
static_libs: ["lib4"],
|
static_libs: ["lib4", "import"],
|
||||||
}
|
}
|
||||||
|
|
||||||
android_library {
|
android_library {
|
||||||
|
@ -607,6 +607,12 @@ func TestLibraryAssets(t *testing.T) {
|
||||||
sdk_version: "current",
|
sdk_version: "current",
|
||||||
asset_dirs: ["assets_b"],
|
asset_dirs: ["assets_b"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android_library_import {
|
||||||
|
name: "import",
|
||||||
|
sdk_version: "current",
|
||||||
|
aars: ["import.aar"],
|
||||||
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -616,11 +622,12 @@ func TestLibraryAssets(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "foo",
|
name: "foo",
|
||||||
// lib1 has its own asset. lib3 doesn't have any, but provides lib4's transitively.
|
// lib1 has its own assets. lib3 doesn't have any, but lib4 and import have assets.
|
||||||
assetPackages: []string{
|
assetPackages: []string{
|
||||||
"out/soong/.intermediates/foo/android_common/aapt2/package-res.apk",
|
"out/soong/.intermediates/foo/android_common/aapt2/package-res.apk",
|
||||||
"out/soong/.intermediates/lib1/android_common/assets.zip",
|
"out/soong/.intermediates/lib1/android_common/assets.zip",
|
||||||
"out/soong/.intermediates/lib3/android_common/assets.zip",
|
"out/soong/.intermediates/lib4/android_common/assets.zip",
|
||||||
|
"out/soong/.intermediates/import/android_common/assets.zip",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -632,10 +639,6 @@ func TestLibraryAssets(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "lib3",
|
name: "lib3",
|
||||||
assetPackages: []string{
|
|
||||||
"out/soong/.intermediates/lib3/android_common/aapt2/package-res.apk",
|
|
||||||
"out/soong/.intermediates/lib4/android_common/assets.zip",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "lib4",
|
name: "lib4",
|
||||||
|
@ -761,11 +764,14 @@ func TestAndroidResourceProcessor(t *testing.T) {
|
||||||
appResources: nil,
|
appResources: nil,
|
||||||
appOverlays: []string{
|
appOverlays: []string{
|
||||||
"out/soong/.intermediates/transitive/android_common/package-res.apk",
|
"out/soong/.intermediates/transitive/android_common/package-res.apk",
|
||||||
|
"out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
|
||||||
"out/soong/.intermediates/transitive_import/android_common/package-res.apk",
|
"out/soong/.intermediates/transitive_import/android_common/package-res.apk",
|
||||||
"out/soong/.intermediates/direct/android_common/package-res.apk",
|
"out/soong/.intermediates/direct/android_common/package-res.apk",
|
||||||
|
"out/soong/.intermediates/direct_import_dep/android_common/package-res.apk",
|
||||||
"out/soong/.intermediates/direct_import/android_common/package-res.apk",
|
"out/soong/.intermediates/direct_import/android_common/package-res.apk",
|
||||||
"out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat",
|
"out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat",
|
||||||
},
|
},
|
||||||
|
|
||||||
appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
|
appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
|
||||||
appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"},
|
appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"},
|
||||||
appClasspath: []string{
|
appClasspath: []string{
|
||||||
|
@ -782,9 +788,11 @@ func TestAndroidResourceProcessor(t *testing.T) {
|
||||||
directResources: nil,
|
directResources: nil,
|
||||||
directOverlays: []string{
|
directOverlays: []string{
|
||||||
"out/soong/.intermediates/transitive/android_common/package-res.apk",
|
"out/soong/.intermediates/transitive/android_common/package-res.apk",
|
||||||
|
"out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk",
|
||||||
"out/soong/.intermediates/transitive_import/android_common/package-res.apk",
|
"out/soong/.intermediates/transitive_import/android_common/package-res.apk",
|
||||||
"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat",
|
"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat",
|
||||||
},
|
},
|
||||||
|
|
||||||
directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
|
directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"},
|
||||||
directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"},
|
directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"},
|
||||||
directClasspath: []string{
|
directClasspath: []string{
|
||||||
|
@ -1198,7 +1206,7 @@ func TestAndroidResourceOverlays(t *testing.T) {
|
||||||
overlayFiles = resourceListToFiles(module, android.PathsRelativeToTop(overlayList.Inputs))
|
overlayFiles = resourceListToFiles(module, android.PathsRelativeToTop(overlayList.Inputs))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() {
|
for _, d := range module.Module().(AndroidLibraryDependency).RRODirsDepSet().ToList() {
|
||||||
var prefix string
|
var prefix string
|
||||||
if d.overlayType == device {
|
if d.overlayType == device {
|
||||||
prefix = "device:"
|
prefix = "device:"
|
||||||
|
|
Loading…
Reference in a new issue