Merge "Make dexpreopt properties configurable" into main am: 37842ac3b1 am: 3927f7aef3

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

Change-Id: If970a73050fa657f4f14a63e20ca6fbc2eca16e7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2024-09-19 19:20:02 +00:00
committed by Automerger Merge Worker
2 changed files with 23 additions and 21 deletions

View File

@@ -1790,14 +1790,14 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
classesJar: outputFile, classesJar: outputFile,
jarName: jarName, jarName: jarName,
} }
if j.GetProfileGuided() && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting() { if j.GetProfileGuided(ctx) && j.optimizeOrObfuscateEnabled() && !j.EnableProfileRewriting(ctx) {
ctx.PropertyErrorf("enable_profile_rewriting", 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.", "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() { if j.EnableProfileRewriting(ctx) {
profile := j.GetProfile() profile := j.GetProfile(ctx)
if profile == "" || !j.GetProfileGuided() { if profile == "" || !j.GetProfileGuided(ctx) {
ctx.PropertyErrorf("enable_profile_rewriting", "Profile and Profile_guided must be set when enable_profile_rewriting is true") ctx.PropertyErrorf("enable_profile_rewriting", "Profile and Profile_guided must be set when enable_profile_rewriting is true")
} }
params.artProfileInput = &profile params.artProfileInput = &profile

View File

@@ -147,25 +147,25 @@ type dexpreopter struct {
type DexpreoptProperties struct { type DexpreoptProperties struct {
Dex_preopt struct { Dex_preopt struct {
// If false, prevent dexpreopting. Defaults to true. // 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. // 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 // 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 // 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. // 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, // 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 // 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 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 // If set to true, r8/d8 will use `profile` as input to generate a new profile that matches
// the optimized dex. // the optimized dex.
// The new profile will be subsequently used as the profile to dexpreopt the dex file. // 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 { Dex_preopt_result struct {
@@ -244,7 +244,7 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName s
return true return true
} }
if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) { if !d.dexpreoptProperties.Dex_preopt.Enabled.GetOrDefault(ctx, true) {
return true return true
} }
@@ -433,12 +433,12 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa
if d.inputProfilePathOnHost != nil { if d.inputProfilePathOnHost != nil {
profileClassListing = android.OptionalPathForPath(d.inputProfilePathOnHost) 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 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()) profileClassListing = android.OptionalPathForPath(d.GetRewrittenProfile())
profileIsTextListing = true 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 // If dex_preopt.profile_guided is not set, default it based on the existence of the
// dexprepot.profile option or the profile class listing. // dexprepot.profile option or the profile class listing.
profileClassListing = android.OptionalPathForPath( 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 // Use the dexJar to create a unique scope for each
dexJarStem := strings.TrimSuffix(dexJarFile.Base(), dexJarFile.Ext()) 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. // Full dexpreopt config, used to create dexpreopt build rules.
dexpreoptConfig := &dexpreopt.ModuleConfig{ dexpreoptConfig := &dexpreopt.ModuleConfig{
Name: libName, Name: libName,
@@ -486,8 +488,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJa
PreoptBootClassPathDexFiles: dexFiles.Paths(), PreoptBootClassPathDexFiles: dexFiles.Paths(),
PreoptBootClassPathDexLocations: dexLocations, PreoptBootClassPathDexLocations: dexLocations,
NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true), NoCreateAppImage: !appImage.GetOrDefault(true),
ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false), ForceCreateAppImage: appImage.GetOrDefault(false),
PresignedPrebuilt: d.isPresignedPrebuilt, PresignedPrebuilt: d.isPresignedPrebuilt,
} }
@@ -657,16 +659,16 @@ func (d *dexpreopter) disableDexpreopt() {
d.shouldDisableDexpreopt = true d.shouldDisableDexpreopt = true
} }
func (d *dexpreopter) EnableProfileRewriting() bool { func (d *dexpreopter) EnableProfileRewriting(ctx android.BaseModuleContext) bool {
return proptools.Bool(d.dexpreoptProperties.Dex_preopt.Enable_profile_rewriting) return d.dexpreoptProperties.Dex_preopt.Enable_profile_rewriting.GetOrDefault(ctx, false)
} }
func (d *dexpreopter) GetProfile() string { func (d *dexpreopter) GetProfile(ctx android.BaseModuleContext) string {
return proptools.String(d.dexpreoptProperties.Dex_preopt.Profile) return d.dexpreoptProperties.Dex_preopt.Profile.GetOrDefault(ctx, "")
} }
func (d *dexpreopter) GetProfileGuided() bool { func (d *dexpreopter) GetProfileGuided(ctx android.BaseModuleContext) bool {
return proptools.Bool(d.dexpreoptProperties.Dex_preopt.Profile_guided) return d.dexpreoptProperties.Dex_preopt.Profile_guided.GetOrDefault(ctx, false)
} }
func (d *dexpreopter) GetRewrittenProfile() android.Path { func (d *dexpreopter) GetRewrittenProfile() android.Path {