Reapply "Use R8 for resource shrinking"

This reverts commit a9fd59a7f2.

We are moving the resource shinking pipeline into r8 (gennerally, not just for platform)

This disables the usage of the resource shrinker cli from cmd-line tools

There are no changes in this cl compared to the original land, the fix
was done in R8 (to use the same compression for res folder entries as
in the original)

Bug: 308710394
Bug: 309078004
Test: Existing, validated that resource table on SystemUI was byte<>byte equal, validated uncompression

Ignore-AOSP-First: Merge does not apply cleanly

Change-Id: Ib8a6fb128084e994325b975c46a036cb41494654
This commit is contained in:
Rico Wind
2023-11-23 08:41:28 +01:00
parent f24ed7e3a9
commit 20c2010030
6 changed files with 46 additions and 125 deletions

View File

@@ -95,6 +95,8 @@ type dexer struct {
proguardDictionary android.OptionalPath
proguardConfiguration android.OptionalPath
proguardUsageZip android.OptionalPath
resourcesInput android.OptionalPath
resourcesOutput android.OptionalPath
providesTransitiveHeaderJars
}
@@ -161,7 +163,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
"$r8Template": &remoteexec.REParams{
Labels: map[string]string{"type": "compile", "compiler": "r8"},
Inputs: []string{"$implicits", "${config.R8Jar}"},
OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}"},
OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}"},
ExecStrategy: "${config.RER8ExecStrategy}",
ToolchainInputs: []string{"${config.JavaCmd}"},
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
@@ -181,7 +183,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
},
}, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir",
"r8Flags", "zipFlags", "mergeZipsFlags"}, []string{"implicits"})
"r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput"}, []string{"implicits"})
func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
dexParams *compileDexParams) (flags []string, deps android.Paths) {
@@ -350,6 +352,12 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl
r8Flags = append(r8Flags, "-ignorewarnings")
}
if d.resourcesInput.Valid() {
r8Flags = append(r8Flags, "--resource-input", d.resourcesInput.Path().String())
r8Deps = append(r8Deps, d.resourcesInput.Path())
r8Flags = append(r8Flags, "--resource-output", d.resourcesOutput.Path().String())
}
return r8Flags, r8Deps
}
@@ -391,6 +399,8 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam
android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
resourcesOutput := android.PathForModuleOut(ctx, "package-res-shrunken.apk")
d.resourcesOutput = android.OptionalPathForPath(resourcesOutput)
r8Flags, r8Deps := d.r8Flags(ctx, dexParams.flags)
r8Deps = append(r8Deps, commonDeps...)
rule := r8
@@ -409,17 +419,22 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam
rule = r8RE
args["implicits"] = strings.Join(r8Deps.Strings(), ",")
}
implicitOutputs := android.WritablePaths{
proguardDictionary,
proguardUsageZip,
proguardConfiguration}
if d.resourcesInput.Valid() {
implicitOutputs = append(implicitOutputs, resourcesOutput)
args["resourcesOutput"] = resourcesOutput.String()
}
ctx.Build(pctx, android.BuildParams{
Rule: rule,
Description: "r8",
Output: javalibJar,
ImplicitOutputs: android.WritablePaths{
proguardDictionary,
proguardUsageZip,
proguardConfiguration},
Input: dexParams.classesJar,
Implicits: r8Deps,
Args: args,
Rule: rule,
Description: "r8",
Output: javalibJar,
ImplicitOutputs: implicitOutputs,
Input: dexParams.classesJar,
Implicits: r8Deps,
Args: args,
})
} else {
d8Flags, d8Deps := d8Flags(dexParams.flags)