Merge "Use an option struct in aapt.buildActions & manifestMerger" into main am: 37e64f9c91 am: a51e83ac06 am: aa0e12c22b

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2769926

Change-Id: I11ddee3b3dacf67aa35d79532fd2dce90afa9b07
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Alix Espino
2023-10-12 04:30:19 +00:00
committed by Automerger Merge Worker
4 changed files with 53 additions and 20 deletions

View File

@@ -301,23 +301,29 @@ var extractAssetsRule = pctx.AndroidStaticRule("extractAssets",
CommandDeps: []string{"${config.Zip2ZipCmd}"}, CommandDeps: []string{"${config.Zip2ZipCmd}"},
}) })
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkContext, type aaptBuildActionOptions struct {
classLoaderContexts dexpreopt.ClassLoaderContextMap, excludedLibs []string, sdkContext android.SdkContext
enforceDefaultTargetSdkVersion bool, extraLinkFlags ...string) { classLoaderContexts dexpreopt.ClassLoaderContextMap
excludedLibs []string
enforceDefaultTargetSdkVersion bool
extraLinkFlags []string
}
func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptions) {
staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedDeps, libFlags := staticResourcesNodesDepSet, staticRRODirsDepSet, staticManifestsDepSet, sharedDeps, libFlags :=
aaptLibs(ctx, sdkContext, classLoaderContexts) aaptLibs(ctx, opts.sdkContext, opts.classLoaderContexts)
// Exclude any libraries from the supplied list. // Exclude any libraries from the supplied list.
classLoaderContexts = classLoaderContexts.ExcludeLibs(excludedLibs) opts.classLoaderContexts = opts.classLoaderContexts.ExcludeLibs(opts.excludedLibs)
// App manifest file // App manifest file
manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml") manifestFile := proptools.StringDefault(a.aaptProperties.Manifest, "AndroidManifest.xml")
manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile) manifestSrcPath := android.PathForModuleSrc(ctx, manifestFile)
manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{ manifestPath := ManifestFixer(ctx, manifestSrcPath, ManifestFixerParams{
SdkContext: sdkContext, SdkContext: opts.sdkContext,
ClassLoaderContexts: classLoaderContexts, ClassLoaderContexts: opts.classLoaderContexts,
IsLibrary: a.isLibrary, IsLibrary: a.isLibrary,
DefaultManifestVersion: a.defaultManifestVersion, DefaultManifestVersion: a.defaultManifestVersion,
UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs, UseEmbeddedNativeLibs: a.useEmbeddedNativeLibs,
@@ -325,7 +331,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
UseEmbeddedDex: a.useEmbeddedDex, UseEmbeddedDex: a.useEmbeddedDex,
HasNoCode: a.hasNoCode, HasNoCode: a.hasNoCode,
LoggingParent: a.LoggingParent, LoggingParent: a.LoggingParent,
EnforceDefaultTargetSdkVersion: enforceDefaultTargetSdkVersion, EnforceDefaultTargetSdkVersion: opts.enforceDefaultTargetSdkVersion,
}) })
staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList()) staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList())
@@ -341,7 +347,10 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
transitiveManifestPaths = append(transitiveManifestPaths, staticManifestsDepSet.ToList()...) transitiveManifestPaths = append(transitiveManifestPaths, staticManifestsDepSet.ToList()...)
if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) { if len(transitiveManifestPaths) > 1 && !Bool(a.aaptProperties.Dont_merge_manifests) {
a.mergedManifestFile = manifestMerger(ctx, transitiveManifestPaths[0], transitiveManifestPaths[1:], a.isLibrary) manifestMergerParams := ManifestMergerParams{
staticLibManifests: transitiveManifestPaths[1:],
isLibrary: a.isLibrary}
a.mergedManifestFile = manifestMerger(ctx, transitiveManifestPaths[0], manifestMergerParams)
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
@@ -352,12 +361,12 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
a.mergedManifestFile = manifestPath a.mergedManifestFile = manifestPath
} }
compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath) compileFlags, linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, opts.sdkContext, manifestPath)
linkFlags = append(linkFlags, libFlags...) linkFlags = append(linkFlags, libFlags...)
linkDeps = append(linkDeps, sharedDeps...) linkDeps = append(linkDeps, sharedDeps...)
linkDeps = append(linkDeps, staticDeps.resPackages()...) linkDeps = append(linkDeps, staticDeps.resPackages()...)
linkFlags = append(linkFlags, extraLinkFlags...) linkFlags = append(linkFlags, opts.extraLinkFlags...)
if a.isLibrary { if a.isLibrary {
linkFlags = append(linkFlags, "--static-lib") linkFlags = append(linkFlags, "--static-lib")
} }
@@ -729,7 +738,13 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.aapt.isLibrary = true a.aapt.isLibrary = true
a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx) a.classLoaderContexts = a.usesLibrary.classLoaderContextForUsesLibDeps(ctx)
a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, nil, false) a.aapt.buildActions(ctx,
aaptBuildActionOptions{
sdkContext: android.SdkContext(a),
classLoaderContexts: a.classLoaderContexts,
enforceDefaultTargetSdkVersion: false,
},
)
a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform() a.hideApexVariantFromMake = !ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()

View File

@@ -200,11 +200,16 @@ func ManifestFixer(ctx android.ModuleContext, manifest android.Path,
return fixedManifest.WithoutRel() return fixedManifest.WithoutRel()
} }
func manifestMerger(ctx android.ModuleContext, manifest android.Path, staticLibManifests android.Paths, type ManifestMergerParams struct {
isLibrary bool) android.Path { staticLibManifests android.Paths
isLibrary bool
}
func manifestMerger(ctx android.ModuleContext, manifest android.Path,
params ManifestMergerParams) android.Path {
var args string var args string
if !isLibrary { if !params.isLibrary {
// Follow Gradle's behavior, only pass --remove-tools-declarations when merging app manifests. // Follow Gradle's behavior, only pass --remove-tools-declarations when merging app manifests.
args = "--remove-tools-declarations" args = "--remove-tools-declarations"
} }
@@ -214,10 +219,10 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, staticLibM
Rule: manifestMergerRule, Rule: manifestMergerRule,
Description: "merge manifest", Description: "merge manifest",
Input: manifest, Input: manifest,
Implicits: staticLibManifests, Implicits: params.staticLibManifests,
Output: mergedManifest, Output: mergedManifest,
Args: map[string]string{ Args: map[string]string{
"libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "), "libs": android.JoinWithPrefix(params.staticLibManifests.Strings(), "--libs "),
"args": args, "args": args,
}, },
}) })

View File

@@ -481,8 +481,15 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
if a.Updatable() { if a.Updatable() {
a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion
} }
a.aapt.buildActions(ctx, android.SdkContext(a), a.classLoaderContexts, a.aapt.buildActions(ctx,
a.usesLibraryProperties.Exclude_uses_libs, a.enforceDefaultTargetSdkVersion(), aaptLinkFlags...) aaptBuildActionOptions{
android.SdkContext(a),
a.classLoaderContexts,
a.usesLibraryProperties.Exclude_uses_libs,
a.enforceDefaultTargetSdkVersion(),
aaptLinkFlags,
},
)
// apps manifests are handled by aapt, don't let Module see them // apps manifests are handled by aapt, don't let Module see them
a.properties.Manifest = nil a.properties.Manifest = nil

View File

@@ -146,7 +146,13 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC
aaptLinkFlags = append(aaptLinkFlags, aaptLinkFlags = append(aaptLinkFlags,
"--rename-overlay-category "+*r.overridableProperties.Category) "--rename-overlay-category "+*r.overridableProperties.Category)
} }
r.aapt.buildActions(ctx, r, nil, nil, false, aaptLinkFlags...) r.aapt.buildActions(ctx,
aaptBuildActionOptions{
sdkContext: r,
enforceDefaultTargetSdkVersion: false,
extraLinkFlags: aaptLinkFlags,
},
)
// Sign the built package // Sign the built package
_, _, certificates := collectAppDeps(ctx, r, false, false) _, _, certificates := collectAppDeps(ctx, r, false, false)