Translate --custom-package aapt2 flag for ResourceProcessorBusyBox

When --custom-package is specified as an aapt2 flag translate it to
--packageForR when running ResourceProcessorBusyBox.

Bug: 294256649
Test: m javac-check
Change-Id: I2c97c760ea8a0203790feda82b98e12c2dbd7b72
This commit is contained in:
Colin Cross 2024-01-03 19:42:25 -08:00
parent 36ce95848b
commit d3f7d1a44c

View file

@ -544,7 +544,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
if a.useResourceProcessorBusyBox() {
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, a.aaptProperties.Aaptflags)
aapt2ExtractExtraPackages(ctx, extraPackages, rJar)
transitiveRJars = append(transitiveRJars, rJar)
a.rJar = rJar
@ -604,7 +604,7 @@ var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox"
// using Bazel's ResourceProcessorBusyBox tool, which is faster than compiling the R.java files and
// supports producing classes for static dependencies that only include resources from that dependency.
func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, manifest android.Path,
rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool) {
rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool, aaptFlags []string) {
var args []string
var deps android.Paths
@ -621,6 +621,17 @@ func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, ma
args = append(args, "--finalFields=false")
}
for i, arg := range aaptFlags {
const AAPT_CUSTOM_PACKAGE = "--custom-package"
if strings.HasPrefix(arg, AAPT_CUSTOM_PACKAGE) {
pkg := strings.TrimSpace(strings.TrimPrefix(arg, AAPT_CUSTOM_PACKAGE))
if pkg == "" && i+1 < len(aaptFlags) {
pkg = aaptFlags[i+1]
}
args = append(args, "--packageForR "+pkg)
}
}
deps = append(deps, rTxt, manifest)
ctx.Build(pctx, android.BuildParams{
@ -1194,7 +1205,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil, nil)
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, nil)
aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar)