Merge changes Id93bcaea,Ia8f9f910

* changes:
  Pass --remove-tools-declarations to manifest merger
  Don't use merged manifest for android_library modules
This commit is contained in:
Treehugger Robot 2019-04-25 14:47:37 +00:00 committed by Gerrit Code Review
commit 02cbe8f1c6
3 changed files with 74 additions and 47 deletions

View file

@ -29,7 +29,7 @@ type AndroidLibraryDependency interface {
ExportedProguardFlagFiles() android.Paths ExportedProguardFlagFiles() android.Paths
ExportedRRODirs() []rroDir ExportedRRODirs() []rroDir
ExportedStaticPackages() android.Paths ExportedStaticPackages() android.Paths
ExportedManifest() android.Path ExportedManifests() android.Paths
} }
func init() { func init() {
@ -74,10 +74,12 @@ 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
rroDirs []rroDir rroDirs []rroDir
rTxt android.Path rTxt android.Path
extraAaptPackagesFile android.Path extraAaptPackagesFile android.Path
mergedManifestFile android.Path
isLibrary bool isLibrary bool
uncompressedJNI bool uncompressedJNI bool
useEmbeddedDex bool useEmbeddedDex bool
@ -103,8 +105,8 @@ func (a *aapt) ExportedRRODirs() []rroDir {
return a.rroDirs return a.rroDirs
} }
func (a *aapt) ExportedManifest() android.Path { func (a *aapt) ExportedManifests() android.Paths {
return a.manifestPath return a.transitiveManifestPaths
} }
func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string, func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, manifestPath android.Path) (flags []string,
@ -192,14 +194,28 @@ func (a *aapt) deps(ctx android.BottomUpMutatorContext, sdkContext sdkContext) {
} }
func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) { func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, extraLinkFlags ...string) {
transitiveStaticLibs, staticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext) transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, libDeps, libFlags := aaptLibs(ctx, sdkContext)
// 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 := manifestMerger(ctx, manifestSrcPath, sdkContext, staticLibManifests, a.isLibrary, manifestPath := manifestFixer(ctx, manifestSrcPath, sdkContext,
a.uncompressedJNI, a.useEmbeddedDex, a.usesNonSdkApis) a.isLibrary, a.uncompressedJNI, a.usesNonSdkApis, a.useEmbeddedDex)
a.transitiveManifestPaths = append(android.Paths{manifestPath}, transitiveStaticLibManifests...)
if len(transitiveStaticLibManifests) > 0 {
a.mergedManifestFile = manifestMerger(ctx, manifestPath, transitiveStaticLibManifests, a.isLibrary)
if !a.isLibrary {
// 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
// only passed to Make, which can't handle transitive dependencies.
manifestPath = a.mergedManifestFile
}
} else {
a.mergedManifestFile = manifestPath
}
linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath) linkFlags, linkDeps, resDirs, overlayDirs, rroDirs, resZips := a.aapt2Flags(ctx, sdkContext, manifestPath)
@ -286,7 +302,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext sdkContext, ex
} }
// 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 sdkContext) (transitiveStaticLibs, staticLibManifests android.Paths, func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStaticLibs, transitiveStaticLibManifests android.Paths,
staticRRODirs []rroDir, deps android.Paths, flags []string) { staticRRODirs []rroDir, deps android.Paths, flags []string) {
var sharedLibs android.Paths var sharedLibs android.Paths
@ -314,7 +330,7 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
if exportPackage != nil { if exportPackage != nil {
transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...) transitiveStaticLibs = append(transitiveStaticLibs, aarDep.ExportedStaticPackages()...)
transitiveStaticLibs = append(transitiveStaticLibs, exportPackage) transitiveStaticLibs = append(transitiveStaticLibs, exportPackage)
staticLibManifests = append(staticLibManifests, aarDep.ExportedManifest()) transitiveStaticLibManifests = append(transitiveStaticLibManifests, aarDep.ExportedManifests()...)
outer: outer:
for _, d := range aarDep.ExportedRRODirs() { for _, d := range aarDep.ExportedRRODirs() {
@ -341,8 +357,9 @@ func aaptLibs(ctx android.ModuleContext, sdkContext sdkContext) (transitiveStati
} }
transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs) transitiveStaticLibs = android.FirstUniquePaths(transitiveStaticLibs)
transitiveStaticLibManifests = android.FirstUniquePaths(transitiveStaticLibManifests)
return transitiveStaticLibs, staticLibManifests, staticRRODirs, deps, flags return transitiveStaticLibs, transitiveStaticLibManifests, staticRRODirs, deps, flags
} }
type AndroidLibrary struct { type AndroidLibrary struct {
@ -498,8 +515,8 @@ func (a *AARImport) ExportedStaticPackages() android.Paths {
return a.exportedStaticPackages return a.exportedStaticPackages
} }
func (a *AARImport) ExportedManifest() android.Path { func (a *AARImport) ExportedManifests() android.Paths {
return a.manifest return android.Paths{a.manifest}
} }
func (a *AARImport) Prebuilt() *android.Prebuilt { func (a *AARImport) Prebuilt() *android.Prebuilt {

View file

@ -36,13 +36,14 @@ var manifestFixerRule = pctx.AndroidStaticRule("manifestFixer",
var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger", var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
blueprint.RuleParams{ blueprint.RuleParams{
Command: `${config.ManifestMergerCmd} --main $in $libs --out $out`, Command: `${config.ManifestMergerCmd} $args --main $in $libs --out $out`,
CommandDeps: []string{"${config.ManifestMergerCmd}"}, CommandDeps: []string{"${config.ManifestMergerCmd}"},
}, },
"libs") "args", "libs")
func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext, // Uses manifest_fixer.py to inject minSdkVersion, etc. into an AndroidManifest.xml
staticLibManifests android.Paths, isLibrary, uncompressedJNI, useEmbeddedDex, usesNonSdkApis bool) android.Path { func manifestFixer(ctx android.ModuleContext, manifest android.Path, sdkContext sdkContext,
isLibrary, uncompressedJNI, usesNonSdkApis, useEmbeddedDex bool) android.Path {
var args []string var args []string
if isLibrary { if isLibrary {
@ -79,10 +80,10 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext
deps = append(deps, apiFingerprint) deps = append(deps, apiFingerprint)
} }
// Inject minSdkVersion into the manifest
fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml") fixedManifest := android.PathForModuleOut(ctx, "manifest_fixer", "AndroidManifest.xml")
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: manifestFixerRule, Rule: manifestFixerRule,
Description: "fix manifest",
Input: manifest, Input: manifest,
Implicits: deps, Implicits: deps,
Output: fixedManifest, Output: fixedManifest,
@ -92,22 +93,31 @@ func manifestMerger(ctx android.ModuleContext, manifest android.Path, sdkContext
"args": strings.Join(args, " "), "args": strings.Join(args, " "),
}, },
}) })
manifest = fixedManifest
// Merge static aar dependency manifests if necessary return fixedManifest
if len(staticLibManifests) > 0 { }
func manifestMerger(ctx android.ModuleContext, manifest android.Path, staticLibManifests android.Paths,
isLibrary bool) android.Path {
var args string
if !isLibrary {
// Follow Gradle's behavior, only pass --remove-tools-declarations when merging app manifests.
args = "--remove-tools-declarations"
}
mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml") mergedManifest := android.PathForModuleOut(ctx, "manifest_merger", "AndroidManifest.xml")
ctx.Build(pctx, android.BuildParams{ ctx.Build(pctx, android.BuildParams{
Rule: manifestMergerRule, Rule: manifestMergerRule,
Description: "merge manifest",
Input: manifest, Input: manifest,
Implicits: staticLibManifests, Implicits: staticLibManifests,
Output: mergedManifest, Output: mergedManifest,
Args: map[string]string{ Args: map[string]string{
"libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "), "libs": android.JoinWithPrefix(staticLibManifests.Strings(), "--libs "),
"args": args,
}, },
}) })
manifest = mergedManifest
}
return manifest return mergedManifest
} }

View file

@ -390,7 +390,7 @@ func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String()) fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", a.extraAaptPackagesFile.String())
fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String()) fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.mergedManifestFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
strings.Join(a.exportedProguardFlagFiles.Strings(), " ")) strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")