Merge "Don't generate aapt2 srcjars when using resource processor" into main am: 002764c8ee
am: 1a436c9b61
am: c2bb066321
am: 005bef73b0
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2690449 Change-Id: I6c106db3c860d5809cc28d53d3b7177e9020614a Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -146,21 +146,25 @@ func aapt2CompileZip(ctx android.ModuleContext, flata android.WritablePath, zip
|
|||||||
|
|
||||||
var aapt2LinkRule = pctx.AndroidStaticRule("aapt2Link",
|
var aapt2LinkRule = pctx.AndroidStaticRule("aapt2Link",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf $genDir && ` +
|
Command: `$preamble` +
|
||||||
`${config.Aapt2Cmd} link -o $out $flags --java $genDir --proguard $proguardOptions ` +
|
`${config.Aapt2Cmd} link -o $out $flags --proguard $proguardOptions ` +
|
||||||
`--output-text-symbols ${rTxt} $inFlags && ` +
|
`--output-text-symbols ${rTxt} $inFlags` +
|
||||||
`${config.SoongZipCmd} -write_if_changed -jar -o $genJar -C $genDir -D $genDir &&` +
|
`$postamble`,
|
||||||
`${config.ExtractJarPackagesCmd} -i $genJar -o $extraPackages --prefix '--extra-packages ' && ` +
|
|
||||||
`rm -rf $genDir`,
|
|
||||||
|
|
||||||
CommandDeps: []string{
|
CommandDeps: []string{
|
||||||
"${config.Aapt2Cmd}",
|
"${config.Aapt2Cmd}",
|
||||||
"${config.SoongZipCmd}",
|
"${config.SoongZipCmd}",
|
||||||
"${config.ExtractJarPackagesCmd}",
|
|
||||||
},
|
},
|
||||||
Restat: true,
|
Restat: true,
|
||||||
},
|
},
|
||||||
"flags", "inFlags", "proguardOptions", "genDir", "genJar", "rTxt", "extraPackages")
|
"flags", "inFlags", "proguardOptions", "rTxt", "extraPackages", "preamble", "postamble")
|
||||||
|
|
||||||
|
var aapt2ExtractExtraPackagesRule = pctx.AndroidStaticRule("aapt2ExtractExtraPackages",
|
||||||
|
blueprint.RuleParams{
|
||||||
|
Command: `${config.ExtractJarPackagesCmd} -i $in -o $out --prefix '--extra-packages '`,
|
||||||
|
CommandDeps: []string{"${config.ExtractJarPackagesCmd}"},
|
||||||
|
Restat: true,
|
||||||
|
})
|
||||||
|
|
||||||
var fileListToFileRule = pctx.AndroidStaticRule("fileListToFile",
|
var fileListToFileRule = pctx.AndroidStaticRule("fileListToFile",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
@@ -176,12 +180,10 @@ var mergeAssetsRule = pctx.AndroidStaticRule("mergeAssets",
|
|||||||
})
|
})
|
||||||
|
|
||||||
func aapt2Link(ctx android.ModuleContext,
|
func aapt2Link(ctx android.ModuleContext,
|
||||||
packageRes, genJar, proguardOptions, rTxt, extraPackages android.WritablePath,
|
packageRes, genJar, proguardOptions, rTxt android.WritablePath,
|
||||||
flags []string, deps android.Paths,
|
flags []string, deps android.Paths,
|
||||||
compiledRes, compiledOverlay, assetPackages android.Paths, splitPackages android.WritablePaths) {
|
compiledRes, compiledOverlay, assetPackages android.Paths, splitPackages android.WritablePaths) {
|
||||||
|
|
||||||
genDir := android.PathForModuleGen(ctx, "aapt2", "R")
|
|
||||||
|
|
||||||
var inFlags []string
|
var inFlags []string
|
||||||
|
|
||||||
if len(compiledRes) > 0 {
|
if len(compiledRes) > 0 {
|
||||||
@@ -218,7 +220,7 @@ func aapt2Link(ctx android.ModuleContext,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set auxiliary outputs as implicit outputs to establish correct dependency chains.
|
// Set auxiliary outputs as implicit outputs to establish correct dependency chains.
|
||||||
implicitOutputs := append(splitPackages, proguardOptions, genJar, rTxt, extraPackages)
|
implicitOutputs := append(splitPackages, proguardOptions, rTxt)
|
||||||
linkOutput := packageRes
|
linkOutput := packageRes
|
||||||
|
|
||||||
// AAPT2 ignores assets in overlays. Merge them after linking.
|
// AAPT2 ignores assets in overlays. Merge them after linking.
|
||||||
@@ -233,25 +235,49 @@ func aapt2Link(ctx android.ModuleContext,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note the absence of splitPackages. The caller is supposed to compose and provide --split flag
|
||||||
|
// values via the flags parameter when it wants to split outputs.
|
||||||
|
// TODO(b/174509108): Perhaps we can process it in this func while keeping the code reasonably
|
||||||
|
// tidy.
|
||||||
|
args := map[string]string{
|
||||||
|
"flags": strings.Join(flags, " "),
|
||||||
|
"inFlags": strings.Join(inFlags, " "),
|
||||||
|
"proguardOptions": proguardOptions.String(),
|
||||||
|
"rTxt": rTxt.String(),
|
||||||
|
}
|
||||||
|
|
||||||
|
if genJar != nil {
|
||||||
|
// Generating java source files from aapt2 was requested, use aapt2LinkAndGenRule and pass it
|
||||||
|
// genJar and genDir args.
|
||||||
|
genDir := android.PathForModuleGen(ctx, "aapt2", "R")
|
||||||
|
ctx.Variable(pctx, "aapt2GenDir", genDir.String())
|
||||||
|
ctx.Variable(pctx, "aapt2GenJar", genJar.String())
|
||||||
|
implicitOutputs = append(implicitOutputs, genJar)
|
||||||
|
args["preamble"] = `rm -rf $aapt2GenDir && `
|
||||||
|
args["postamble"] = `&& ${config.SoongZipCmd} -write_if_changed -jar -o $aapt2GenJar -C $aapt2GenDir -D $aapt2GenDir && ` +
|
||||||
|
`rm -rf $aapt2GenDir`
|
||||||
|
args["flags"] += " --java $aapt2GenDir"
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: aapt2LinkRule,
|
Rule: aapt2LinkRule,
|
||||||
Description: "aapt2 link",
|
Description: "aapt2 link",
|
||||||
Implicits: deps,
|
Implicits: deps,
|
||||||
Output: linkOutput,
|
Output: linkOutput,
|
||||||
ImplicitOutputs: implicitOutputs,
|
ImplicitOutputs: implicitOutputs,
|
||||||
// Note the absence of splitPackages. The caller is supposed to compose and provide --split flag
|
Args: args,
|
||||||
// values via the flags parameter when it wants to split outputs.
|
})
|
||||||
// TODO(b/174509108): Perhaps we can process it in this func while keeping the code reasonably
|
}
|
||||||
// tidy.
|
|
||||||
Args: map[string]string{
|
// aapt2ExtractExtraPackages takes a srcjar generated by aapt2 or a classes jar generated by ResourceProcessorBusyBox
|
||||||
"flags": strings.Join(flags, " "),
|
// and converts it to a text file containing a list of --extra_package arguments for passing to Make modules so they
|
||||||
"inFlags": strings.Join(inFlags, " "),
|
// correctly generate R.java entries for packages provided by transitive dependencies.
|
||||||
"proguardOptions": proguardOptions.String(),
|
func aapt2ExtractExtraPackages(ctx android.ModuleContext, out android.WritablePath, in android.Path) {
|
||||||
"genDir": genDir.String(),
|
ctx.Build(pctx, android.BuildParams{
|
||||||
"genJar": genJar.String(),
|
Rule: aapt2ExtractExtraPackagesRule,
|
||||||
"rTxt": rTxt.String(),
|
Description: "aapt2 extract extra packages",
|
||||||
"extraPackages": extraPackages.String(),
|
Input: in,
|
||||||
},
|
Output: out,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
java/aar.go
23
java/aar.go
@@ -376,13 +376,12 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
packageRes := android.PathForModuleOut(ctx, "package-res.apk")
|
packageRes := android.PathForModuleOut(ctx, "package-res.apk")
|
||||||
// the subdir "android" is required to be filtered by package names
|
|
||||||
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
|
|
||||||
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
||||||
rTxt := android.PathForModuleOut(ctx, "R.txt")
|
rTxt := android.PathForModuleOut(ctx, "R.txt")
|
||||||
// This file isn't used by Soong, but is generated for exporting
|
// This file isn't used by Soong, but is generated for exporting
|
||||||
extraPackages := android.PathForModuleOut(ctx, "extra_packages")
|
extraPackages := android.PathForModuleOut(ctx, "extra_packages")
|
||||||
var transitiveRJars android.Paths
|
var transitiveRJars android.Paths
|
||||||
|
var srcJar android.WritablePath
|
||||||
|
|
||||||
var compiledResDirs []android.Paths
|
var compiledResDirs []android.Paths
|
||||||
for _, dir := range resDirs {
|
for _, dir := range resDirs {
|
||||||
@@ -459,15 +458,19 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !a.useResourceProcessorBusyBox() {
|
||||||
|
// the subdir "android" is required to be filtered by package names
|
||||||
|
srcJar = android.PathForModuleGen(ctx, "android", "R.srcjar")
|
||||||
|
}
|
||||||
|
|
||||||
// No need to specify assets from dependencies to aapt2Link for libraries, all transitive assets will be
|
// No need to specify assets from dependencies to aapt2Link for libraries, all transitive assets will be
|
||||||
// provided to the final app aapt2Link step.
|
// provided to the final app aapt2Link step.
|
||||||
var transitiveAssets android.Paths
|
var transitiveAssets android.Paths
|
||||||
if !a.isLibrary {
|
if !a.isLibrary {
|
||||||
transitiveAssets = android.ReverseSliceInPlace(staticDeps.assets())
|
transitiveAssets = android.ReverseSliceInPlace(staticDeps.assets())
|
||||||
}
|
}
|
||||||
aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt, extraPackages,
|
aapt2Link(ctx, packageRes, srcJar, proguardOptionsFile, rTxt,
|
||||||
linkFlags, linkDeps, compiledRes, compiledOverlay, transitiveAssets, 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 ") {
|
if android.PrefixInList(linkFlags, "-A ") {
|
||||||
@@ -484,8 +487,11 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon
|
|||||||
if a.useResourceProcessorBusyBox() {
|
if a.useResourceProcessorBusyBox() {
|
||||||
rJar := android.PathForModuleOut(ctx, "busybox/R.jar")
|
rJar := android.PathForModuleOut(ctx, "busybox/R.jar")
|
||||||
resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary)
|
resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary)
|
||||||
|
aapt2ExtractExtraPackages(ctx, extraPackages, rJar)
|
||||||
transitiveRJars = append(transitiveRJars, rJar)
|
transitiveRJars = append(transitiveRJars, rJar)
|
||||||
a.rJar = rJar
|
a.rJar = rJar
|
||||||
|
} else {
|
||||||
|
aapt2ExtractExtraPackages(ctx, extraPackages, srcJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.aaptSrcJar = srcJar
|
a.aaptSrcJar = srcJar
|
||||||
@@ -731,9 +737,10 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
|
|||||||
|
|
||||||
ctx.CheckbuildFile(a.aapt.proguardOptionsFile)
|
ctx.CheckbuildFile(a.aapt.proguardOptionsFile)
|
||||||
ctx.CheckbuildFile(a.aapt.exportPackage)
|
ctx.CheckbuildFile(a.aapt.exportPackage)
|
||||||
ctx.CheckbuildFile(a.aapt.aaptSrcJar)
|
|
||||||
if a.useResourceProcessorBusyBox() {
|
if a.useResourceProcessorBusyBox() {
|
||||||
ctx.CheckbuildFile(a.aapt.rJar)
|
ctx.CheckbuildFile(a.aapt.rJar)
|
||||||
|
} else {
|
||||||
|
ctx.CheckbuildFile(a.aapt.aaptSrcJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
// apps manifests are handled by aapt, don't let Module see them
|
// apps manifests are handled by aapt, don't let Module see them
|
||||||
@@ -1063,8 +1070,6 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags)
|
aapt2CompileZip(ctx, flata, a.aarPath, "res", compileFlags)
|
||||||
|
|
||||||
a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
|
a.exportPackage = android.PathForModuleOut(ctx, "package-res.apk")
|
||||||
// the subdir "android" is required to be filtered by package names
|
|
||||||
srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar")
|
|
||||||
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options")
|
||||||
a.rTxt = android.PathForModuleOut(ctx, "R.txt")
|
a.rTxt = android.PathForModuleOut(ctx, "R.txt")
|
||||||
a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
|
a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages")
|
||||||
@@ -1100,12 +1105,14 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets())
|
transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets())
|
||||||
aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, a.rTxt, a.extraAaptPackagesFile,
|
aapt2Link(ctx, a.exportPackage, nil, proguardOptionsFile, a.rTxt,
|
||||||
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
|
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil)
|
||||||
|
|
||||||
a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar")
|
a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar")
|
||||||
resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true)
|
resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true)
|
||||||
|
|
||||||
|
aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar)
|
||||||
|
|
||||||
resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL)
|
resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL)
|
||||||
resourcesNodesDepSetBuilder.Direct(&resourcesNode{
|
resourcesNodesDepSetBuilder.Direct(&resourcesNode{
|
||||||
resPackage: a.exportPackage,
|
resPackage: a.exportPackage,
|
||||||
|
@@ -1022,7 +1022,13 @@ func (a *AndroidApp) OutputFiles(tag string) (android.Paths, error) {
|
|||||||
case ".aapt.proguardOptionsFile":
|
case ".aapt.proguardOptionsFile":
|
||||||
return []android.Path{a.proguardOptionsFile}, nil
|
return []android.Path{a.proguardOptionsFile}, nil
|
||||||
case ".aapt.srcjar":
|
case ".aapt.srcjar":
|
||||||
return []android.Path{a.aaptSrcJar}, nil
|
if a.aaptSrcJar != nil {
|
||||||
|
return []android.Path{a.aaptSrcJar}, nil
|
||||||
|
}
|
||||||
|
case ".aapt.jar":
|
||||||
|
if a.rJar != nil {
|
||||||
|
return []android.Path{a.rJar}, nil
|
||||||
|
}
|
||||||
case ".export-package.apk":
|
case ".export-package.apk":
|
||||||
return []android.Path{a.exportPackage}, nil
|
return []android.Path{a.exportPackage}, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user