Merge "Capture list of unused methods when shrinking in R8"
This commit is contained in:
@@ -313,3 +313,15 @@ func replaceDepsOnOverridingModuleMutator(ctx BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ModuleNameWithPossibleOverride returns the name of the OverrideModule that overrides the current
|
||||||
|
// variant of this OverridableModule, or ctx.ModuleName() if this module is not an OverridableModule
|
||||||
|
// or if this variant is not overridden.
|
||||||
|
func ModuleNameWithPossibleOverride(ctx ModuleContext) string {
|
||||||
|
if overridable, ok := ctx.Module().(OverridableModule); ok {
|
||||||
|
if o := overridable.GetOverriddenBy(); o != "" {
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ctx.ModuleName()
|
||||||
|
}
|
||||||
|
@@ -127,9 +127,8 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...)
|
entries.AddStrings("LOCAL_ADDITIONAL_CHECKED_MODULE", library.additionalCheckedModules.Strings()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
if library.dexer.proguardDictionary.Valid() {
|
entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", library.dexer.proguardDictionary)
|
||||||
entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", library.dexer.proguardDictionary.Path())
|
entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", library.dexer.proguardUsageZip)
|
||||||
}
|
|
||||||
entries.SetString("LOCAL_MODULE_STEM", library.Stem())
|
entries.SetString("LOCAL_MODULE_STEM", library.Stem())
|
||||||
|
|
||||||
entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
|
entries.SetOptionalPaths("LOCAL_SOONG_LINT_REPORTS", library.linter.reports)
|
||||||
@@ -332,9 +331,8 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
if app.jacocoReportClassesFile != nil {
|
if app.jacocoReportClassesFile != nil {
|
||||||
entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", app.jacocoReportClassesFile)
|
entries.SetPath("LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR", app.jacocoReportClassesFile)
|
||||||
}
|
}
|
||||||
if app.dexer.proguardDictionary.Valid() {
|
entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_DICT", app.dexer.proguardDictionary)
|
||||||
entries.SetPath("LOCAL_SOONG_PROGUARD_DICT", app.dexer.proguardDictionary.Path())
|
entries.SetOptionalPath("LOCAL_SOONG_PROGUARD_USAGE_ZIP", app.dexer.proguardUsageZip)
|
||||||
}
|
|
||||||
|
|
||||||
if app.Name() == "framework-res" {
|
if app.Name() == "framework-res" {
|
||||||
entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
|
entries.SetString("LOCAL_MODULE_PATH", "$(TARGET_OUT_JAVA_LIBRARIES)")
|
||||||
|
31
java/dex.go
31
java/dex.go
@@ -72,6 +72,7 @@ type dexer struct {
|
|||||||
// list of extra proguard flag files
|
// list of extra proguard flag files
|
||||||
extraProguardFlagFiles android.Paths
|
extraProguardFlagFiles android.Paths
|
||||||
proguardDictionary android.OptionalPath
|
proguardDictionary android.OptionalPath
|
||||||
|
proguardUsageZip android.OptionalPath
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dexer) effectiveOptimizeEnabled() bool {
|
func (d *dexer) effectiveOptimizeEnabled() bool {
|
||||||
@@ -109,13 +110,17 @@ var d8, d8RE = remoteexec.MultiCommandStaticRules(pctx, "d8",
|
|||||||
var r8, r8RE = remoteexec.MultiCommandStaticRules(pctx, "r8",
|
var r8, r8RE = remoteexec.MultiCommandStaticRules(pctx, "r8",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||||
`rm -f "$outDict" && ` +
|
`rm -f "$outDict" && rm -rf "${outUsageDir}" && ` +
|
||||||
|
`mkdir -p $$(dirname ${outUsage}) && ` +
|
||||||
`$r8Template${config.R8Cmd} ${config.DexFlags} -injars $in --output $outDir ` +
|
`$r8Template${config.R8Cmd} ${config.DexFlags} -injars $in --output $outDir ` +
|
||||||
`--force-proguard-compatibility ` +
|
`--force-proguard-compatibility ` +
|
||||||
`--no-data-resources ` +
|
`--no-data-resources ` +
|
||||||
`-printmapping $outDict ` +
|
`-printmapping ${outDict} ` +
|
||||||
|
`-printusage ${outUsage} ` +
|
||||||
`$r8Flags && ` +
|
`$r8Flags && ` +
|
||||||
`touch "$outDict" && ` +
|
`touch "${outDict}" "${outUsage}" && ` +
|
||||||
|
`${config.SoongZipCmd} -o ${outUsageZip} -C ${outUsageDir} -f ${outUsage} && ` +
|
||||||
|
`rm -rf ${outUsageDir} && ` +
|
||||||
`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
|
`$zipTemplate${config.SoongZipCmd} $zipFlags -o $outDir/classes.dex.jar -C $outDir -f "$outDir/classes*.dex" && ` +
|
||||||
`${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
|
`${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`,
|
||||||
CommandDeps: []string{
|
CommandDeps: []string{
|
||||||
@@ -138,7 +143,15 @@ var r8, r8RE = remoteexec.MultiCommandStaticRules(pctx, "r8",
|
|||||||
ExecStrategy: "${config.RER8ExecStrategy}",
|
ExecStrategy: "${config.RER8ExecStrategy}",
|
||||||
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
|
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
|
||||||
},
|
},
|
||||||
}, []string{"outDir", "outDict", "r8Flags", "zipFlags"}, []string{"implicits"})
|
"$zipUsageTemplate": &remoteexec.REParams{
|
||||||
|
Labels: map[string]string{"type": "tool", "name": "soong_zip"},
|
||||||
|
Inputs: []string{"${config.SoongZipCmd}", "${outUsage}"},
|
||||||
|
OutputFiles: []string{"${outUsageZip}"},
|
||||||
|
ExecStrategy: "${config.RER8ExecStrategy}",
|
||||||
|
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
|
||||||
|
},
|
||||||
|
}, []string{"outDir", "outDict", "outUsage", "outUsageZip", "outUsageDir",
|
||||||
|
"r8Flags", "zipFlags"}, []string{"implicits"})
|
||||||
|
|
||||||
func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion sdkSpec) []string {
|
func (d *dexer) dexCommonFlags(ctx android.ModuleContext, minSdkVersion sdkSpec) []string {
|
||||||
flags := d.dexProperties.Dxflags
|
flags := d.dexProperties.Dxflags
|
||||||
@@ -259,12 +272,20 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
if useR8 {
|
if useR8 {
|
||||||
proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
|
proguardDictionary := android.PathForModuleOut(ctx, "proguard_dictionary")
|
||||||
d.proguardDictionary = android.OptionalPathForPath(proguardDictionary)
|
d.proguardDictionary = android.OptionalPathForPath(proguardDictionary)
|
||||||
|
proguardUsageDir := android.PathForModuleOut(ctx, "proguard_usage")
|
||||||
|
proguardUsage := proguardUsageDir.Join(ctx, ctx.Namespace().Path,
|
||||||
|
android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
|
||||||
|
proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
|
||||||
|
d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
|
||||||
r8Flags, r8Deps := d.r8Flags(ctx, flags)
|
r8Flags, r8Deps := d.r8Flags(ctx, flags)
|
||||||
rule := r8
|
rule := r8
|
||||||
args := map[string]string{
|
args := map[string]string{
|
||||||
"r8Flags": strings.Join(append(commonFlags, r8Flags...), " "),
|
"r8Flags": strings.Join(append(commonFlags, r8Flags...), " "),
|
||||||
"zipFlags": zipFlags,
|
"zipFlags": zipFlags,
|
||||||
"outDict": proguardDictionary.String(),
|
"outDict": proguardDictionary.String(),
|
||||||
|
"outUsageDir": proguardUsageDir.String(),
|
||||||
|
"outUsage": proguardUsage.String(),
|
||||||
|
"outUsageZip": proguardUsageZip.String(),
|
||||||
"outDir": outDir.String(),
|
"outDir": outDir.String(),
|
||||||
}
|
}
|
||||||
if ctx.Config().IsEnvTrue("RBE_R8") {
|
if ctx.Config().IsEnvTrue("RBE_R8") {
|
||||||
@@ -275,7 +296,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
Rule: rule,
|
Rule: rule,
|
||||||
Description: "r8",
|
Description: "r8",
|
||||||
Output: javalibJar,
|
Output: javalibJar,
|
||||||
ImplicitOutput: proguardDictionary,
|
ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip},
|
||||||
Input: classesJar,
|
Input: classesJar,
|
||||||
Implicits: r8Deps,
|
Implicits: r8Deps,
|
||||||
Args: args,
|
Args: args,
|
||||||
|
Reference in New Issue
Block a user