From 256c3896087394948d0feeba8112cabc9e79a999 Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Tue, 26 Sep 2023 05:51:40 +0000 Subject: [PATCH] Improve optimize bp2build conditional. Follow up from https://android-review.git.corp.google.com/c/platform/build/soong/+/2757255/comment/fdcf5795_943a04d5/ Test: soong unit tests Change-Id: I63334bfd19469060673e9a9a239050590934b089 --- java/app.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/java/app.go b/java/app.go index 10ffa7a3f..ed1c1072d 100755 --- a/java/app.go +++ b/java/app.go @@ -1689,16 +1689,12 @@ func convertWithBp2build(ctx android.Bp2buildMutatorContext, a *AndroidApp) (boo // // TODO(b/192032291): Disable android_test_helper_app optimization by // default after auditing downstream usage. - if a.dexProperties.Optimize.Enabled == nil { - // Property was not explicitly defined. - a.dexProperties.Optimize.Enabled = &a.dexProperties.Optimize.EnabledByDefault + if a.dexProperties.Optimize.EnabledByDefault != a.dexer.effectiveOptimizeEnabled() { + // Property is explicitly defined by default from default, so emit the Bazel attribute. + appAttrs.Optimize = proptools.BoolPtr(a.dexer.effectiveOptimizeEnabled()) } - if Bool(a.dexProperties.Optimize.Enabled) { - if !a.dexProperties.Optimize.EnabledByDefault { - // explicitly enable optimize for module types that disable it by default - appAttrs.Optimize = proptools.BoolPtr(true) - } + if a.dexer.effectiveOptimizeEnabled() { handCraftedFlags := "" if Bool(a.dexProperties.Optimize.Ignore_warnings) { handCraftedFlags += "-ignorewarning " @@ -1728,9 +1724,6 @@ func convertWithBp2build(ctx android.Bp2buildMutatorContext, a *AndroidApp) (boo }) appAttrs.Proguard_specs.Add(bazel.MakeLabelAttribute(":" + generatedFlagFileRuleName)) } - } else if a.dexProperties.Optimize.EnabledByDefault { - // explicitly disable optimize for module types that enable it by default - appAttrs.Optimize = proptools.BoolPtr(false) } commonAttrs, bp2BuildInfo, supported := a.convertLibraryAttrsBp2Build(ctx)