From eb03246f6faaa8d918579a451e7ec346bb3c0786 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 19 Sep 2024 11:12:54 -0700 Subject: [PATCH] Make dexpreopt properties configurable Spurred by ag/27778860 Test: m nothing --no-skip-soong-tests Change-Id: I0e48144172eee1c589f46875cd94e3aa19d43873 --- java/base.go | 8 ++++---- java/dexpreopt.go | 36 +++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/java/base.go b/java/base.go index ff7e06837..86ed0e745 100644 --- a/java/base.go +++ b/java/base.go @@ -1790,14 +1790,14 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath classesJar: outputFile, jarName: jarName, } - if j.GetProfileGuided() && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting() { + if j.GetProfileGuided(ctx) && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting(ctx) { ctx.PropertyErrorf("enable_profile_rewriting", "Enable_profile_rewriting must be true when profile_guided dexpreopt and R8 optimization/obfuscation is turned on. The attached profile should be sourced from an unoptimized/unobfuscated APK.", ) } - if j.EnableProfileRewriting() { - profile := j.GetProfile() - if profile == "" || !j.GetProfileGuided() { + if j.EnableProfileRewriting(ctx) { + profile := j.GetProfile(ctx) + if profile == "" || !j.GetProfileGuided(ctx) { ctx.PropertyErrorf("enable_profile_rewriting", "Profile and Profile_guided must be set when enable_profile_rewriting is true") } params.artProfileInput = &profile diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 4734357ab..63a863497 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -147,25 +147,25 @@ type dexpreopter struct { type DexpreoptProperties struct { Dex_preopt struct { // If false, prevent dexpreopting. Defaults to true. - Enabled *bool + Enabled proptools.Configurable[bool] `android:"replace_instead_of_append"` // If true, generate an app image (.art file) for this module. - App_image *bool + App_image proptools.Configurable[bool] `android:"replace_instead_of_append"` // If true, use a checked-in profile to guide optimization. Defaults to false unless // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR // that matches the name of this module, in which case it is defaulted to true. - Profile_guided *bool + Profile_guided proptools.Configurable[bool] `android:"replace_instead_of_append"` // If set, provides the path to profile relative to the Android.bp file. If not set, // defaults to searching for a file that matches the name of this module in the default // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found. - Profile *string `android:"path"` + Profile proptools.Configurable[string] `android:"path,replace_instead_of_append"` // If set to true, r8/d8 will use `profile` as input to generate a new profile that matches // the optimized dex. // The new profile will be subsequently used as the profile to dexpreopt the dex file. - Enable_profile_rewriting *bool + Enable_profile_rewriting proptools.Configurable[bool] `android:"replace_instead_of_append"` } Dex_preopt_result struct { @@ -244,7 +244,7 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName s return true } - if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) { + if !d.dexpreoptProperties.Dex_preopt.Enabled.GetOrDefault(ctx, true) { return true } @@ -433,12 +433,12 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa if d.inputProfilePathOnHost != nil { profileClassListing = android.OptionalPathForPath(d.inputProfilePathOnHost) - } else if BoolDefault(d.dexpreoptProperties.Dex_preopt.Profile_guided, true) && !forPrebuiltApex(ctx) { + } else if d.dexpreoptProperties.Dex_preopt.Profile_guided.GetOrDefault(ctx, true) && !forPrebuiltApex(ctx) { // If enable_profile_rewriting is set, use the rewritten profile instead of the checked-in profile - if d.EnableProfileRewriting() { + if d.EnableProfileRewriting(ctx) { profileClassListing = android.OptionalPathForPath(d.GetRewrittenProfile()) profileIsTextListing = true - } else if profile := d.GetProfile(); profile != "" { + } else if profile := d.GetProfile(ctx); profile != "" { // If dex_preopt.profile_guided is not set, default it based on the existence of the // dexprepot.profile option or the profile class listing. profileClassListing = android.OptionalPathForPath( @@ -458,6 +458,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa // Use the dexJar to create a unique scope for each dexJarStem := strings.TrimSuffix(dexJarFile.Base(), dexJarFile.Ext()) + appImage := d.dexpreoptProperties.Dex_preopt.App_image.Get(ctx) + // Full dexpreopt config, used to create dexpreopt build rules. dexpreoptConfig := &dexpreopt.ModuleConfig{ Name: libName, @@ -486,8 +488,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa PreoptBootClassPathDexFiles: dexFiles.Paths(), PreoptBootClassPathDexLocations: dexLocations, - NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true), - ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false), + NoCreateAppImage: !appImage.GetOrDefault(true), + ForceCreateAppImage: appImage.GetOrDefault(false), PresignedPrebuilt: d.isPresignedPrebuilt, } @@ -657,16 +659,16 @@ func (d *dexpreopter) disableDexpreopt() { d.shouldDisableDexpreopt = true } -func (d *dexpreopter) EnableProfileRewriting() bool { - return proptools.Bool(d.dexpreoptProperties.Dex_preopt.Enable_profile_rewriting) +func (d *dexpreopter) EnableProfileRewriting(ctx android.BaseModuleContext) bool { + return d.dexpreoptProperties.Dex_preopt.Enable_profile_rewriting.GetOrDefault(ctx, false) } -func (d *dexpreopter) GetProfile() string { - return proptools.String(d.dexpreoptProperties.Dex_preopt.Profile) +func (d *dexpreopter) GetProfile(ctx android.BaseModuleContext) string { + return d.dexpreoptProperties.Dex_preopt.Profile.GetOrDefault(ctx, "") } -func (d *dexpreopter) GetProfileGuided() bool { - return proptools.Bool(d.dexpreoptProperties.Dex_preopt.Profile_guided) +func (d *dexpreopter) GetProfileGuided(ctx android.BaseModuleContext) bool { + return d.dexpreoptProperties.Dex_preopt.Profile_guided.GetOrDefault(ctx, false) } func (d *dexpreopter) GetRewrittenProfile() android.Path {