Merge "Use per-app package list to avoid unnecessary dexpreopt." am: fbc62cfd74 am: 0f39aeae9d am: 19f78bc543 am: b75734b94f am: 81826f0140 am: c7ca76c392

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2637193

Change-Id: I0d508100d1b1187f6dcbac0a73bb86f94c3c3c67
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jiakai Zhang
2023-06-29 21:05:55 +00:00
committed by Automerger Merge Worker
5 changed files with 60 additions and 24 deletions

View File

@@ -2697,7 +2697,7 @@ func TestUsesLibraries(t *testing.T) {
cmd := app.Rule("dexpreopt").RuleParams.Command
android.AssertStringDoesContain(t, "dexpreopt app cmd context", cmd, "--context-json=")
android.AssertStringDoesContain(t, "dexpreopt app cmd product_packages", cmd,
"--product-packages=out/soong/target/product/test_device/product_packages.txt")
"--product-packages=out/soong/.intermediates/app/android_common/dexpreopt/product_packages.txt")
}
func TestDexpreoptBcp(t *testing.T) {

View File

@@ -16,6 +16,7 @@ package java
import (
"path/filepath"
"sort"
"strings"
"android/soong/android"
@@ -390,11 +391,37 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
// "product_packages.txt" is generated by `build/make/core/Makefile`.
// The root "product_packages.txt" is generated by `build/make/core/Makefile`. It contains a list
// of all packages that are installed on the device. We use `grep` to filter the list by the app's
// dependencies to create a per-app list, and use `rsync --checksum` to prevent the file's mtime
// from being changed if the contents don't change. This avoids unnecessary dexpreopt reruns.
productPackages := android.PathForModuleInPartitionInstall(ctx, "", "product_packages.txt")
appProductPackages := android.PathForModuleOut(ctx, "dexpreopt", "product_packages.txt")
appProductPackagesStaging := appProductPackages.ReplaceExtension(ctx, "txt.tmp")
clcNames, _ := dexpreopt.ComputeClassLoaderContextDependencies(dexpreoptConfig.ClassLoaderContexts)
sort.Strings(clcNames) // The order needs to be deterministic.
productPackagesRule := android.NewRuleBuilder(pctx, ctx)
if len(clcNames) > 0 {
productPackagesRule.Command().
Text("grep -F -x").
FlagForEachArg("-e ", clcNames).
Input(productPackages).
FlagWithOutput("> ", appProductPackagesStaging).
Text("|| true")
} else {
productPackagesRule.Command().
Text("rm -f").Output(appProductPackagesStaging).
Text("&&").
Text("touch").Output(appProductPackagesStaging)
}
productPackagesRule.Command().
Text("rsync --checksum").
Input(appProductPackagesStaging).
Output(appProductPackages)
productPackagesRule.Restat().Build("product_packages", "dexpreopt product_packages")
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(
ctx, globalSoong, global, dexpreoptConfig, productPackages)
ctx, globalSoong, global, dexpreoptConfig, appProductPackages)
if err != nil {
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
return