Allow selective R8 optimization for eng test_suites
Eng builds implicitly run R8 in debug mode. This is typically fine, but test_suites can be built in eng mode, and some tests exercise behavior that may require R8 optimizations. For example, annotation tests that check the effective dex output in the presence of such annotations. Allow a target to override this default behavior by adding "--release" to its dxflags property. Bug: 222468116 Test: atest InternalAnnotationsTests Change-Id: Ie3328f1b56a6fe7c9f331281e6527e40f17f9271
This commit is contained in:
parent
91e0b33f7f
commit
3dbe7196b1
2 changed files with 108 additions and 5 deletions
19
java/dex.go
19
java/dex.go
|
|
@ -220,14 +220,28 @@ func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
|
|||
deps = append(deps, f)
|
||||
}
|
||||
|
||||
var requestReleaseMode bool
|
||||
requestReleaseMode, flags = android.RemoveFromList("--release", flags)
|
||||
|
||||
if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
|
||||
flags = append(flags, "--debug")
|
||||
requestReleaseMode = false
|
||||
}
|
||||
|
||||
if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
|
||||
flags = append(flags,
|
||||
"--debug",
|
||||
"--verbose")
|
||||
requestReleaseMode = false
|
||||
}
|
||||
|
||||
// Don't strip out debug information for eng builds, unless the target
|
||||
// explicitly provided the `--release` build flag. This allows certain
|
||||
// test targets to remain optimized as part of eng test_suites builds.
|
||||
if requestReleaseMode {
|
||||
flags = append(flags, "--release")
|
||||
} else if ctx.Config().Eng() {
|
||||
flags = append(flags, "--debug")
|
||||
}
|
||||
|
||||
// Supplying the platform build flag disables various features like API modeling and desugaring.
|
||||
|
|
@ -384,11 +398,6 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, dexParams *compileDexParams)
|
|||
// TODO(ccross): if this is an instrumentation test of an obfuscated app, use the
|
||||
// dictionary of the app and move the app from libraryjars to injars.
|
||||
|
||||
// Don't strip out debug information for eng builds.
|
||||
if ctx.Config().Eng() {
|
||||
r8Flags = append(r8Flags, "--debug")
|
||||
}
|
||||
|
||||
// TODO(b/180878971): missing classes should be added to the relevant builds.
|
||||
// TODO(b/229727645): do not use true as default for Android platform builds.
|
||||
if proptools.BoolDefault(opt.Ignore_warnings, true) {
|
||||
|
|
|
|||
|
|
@ -713,3 +713,97 @@ android_app {
|
|||
}
|
||||
}`)
|
||||
}
|
||||
|
||||
func TestDebugReleaseFlags(t *testing.T) {
|
||||
bp := `
|
||||
android_app {
|
||||
name: "app",
|
||||
srcs: ["foo.java"],
|
||||
platform_apis: true,
|
||||
dxflags: ["%s"]
|
||||
}
|
||||
`
|
||||
|
||||
testcases := []struct {
|
||||
name string
|
||||
envVar string
|
||||
isEng bool
|
||||
dxFlags string
|
||||
expectedFlags string
|
||||
}{
|
||||
{
|
||||
name: "app_no_optimize_dx",
|
||||
envVar: "NO_OPTIMIZE_DX",
|
||||
expectedFlags: "--debug",
|
||||
},
|
||||
{
|
||||
name: "app_release_no_optimize_dx",
|
||||
envVar: "NO_OPTIMIZE_DX",
|
||||
dxFlags: "--release",
|
||||
// Global env vars override explicit dxflags.
|
||||
expectedFlags: "--debug",
|
||||
},
|
||||
{
|
||||
name: "app_generate_dex_debug",
|
||||
envVar: "GENERATE_DEX_DEBUG",
|
||||
expectedFlags: "--debug",
|
||||
},
|
||||
{
|
||||
name: "app_release_generate_dex_debug",
|
||||
envVar: "GENERATE_DEX_DEBUG",
|
||||
dxFlags: "--release",
|
||||
// Global env vars override explicit dxflags.
|
||||
expectedFlags: "--debug",
|
||||
},
|
||||
{
|
||||
name: "app_eng",
|
||||
isEng: true,
|
||||
expectedFlags: "--debug",
|
||||
},
|
||||
{
|
||||
name: "app_release_eng",
|
||||
isEng: true,
|
||||
dxFlags: "--release",
|
||||
// Eng mode does *not* override explicit dxflags.
|
||||
expectedFlags: "--release",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
fixturePreparer := PrepareForTestWithJavaDefaultModules
|
||||
fixturePreparer = android.GroupFixturePreparers(
|
||||
fixturePreparer,
|
||||
android.FixtureModifyProductVariables(
|
||||
func(variables android.FixtureProductVariables) {
|
||||
variables.Eng = proptools.BoolPtr(tc.isEng)
|
||||
},
|
||||
),
|
||||
)
|
||||
if tc.envVar != "" {
|
||||
fixturePreparer = android.GroupFixturePreparers(
|
||||
fixturePreparer,
|
||||
android.FixtureMergeEnv(map[string]string{
|
||||
tc.envVar: "true",
|
||||
}),
|
||||
)
|
||||
}
|
||||
result := fixturePreparer.RunTestWithBp(t, fmt.Sprintf(bp, tc.dxFlags))
|
||||
|
||||
appR8 := result.ModuleForTests("app", "android_common").Rule("r8")
|
||||
android.AssertStringDoesContain(t, "expected flag in R8 flags",
|
||||
appR8.Args["r8Flags"], tc.expectedFlags)
|
||||
|
||||
var unexpectedFlags string
|
||||
if tc.expectedFlags == "--debug" {
|
||||
unexpectedFlags = "--release"
|
||||
} else if tc.expectedFlags == "--release" {
|
||||
unexpectedFlags = "--debug"
|
||||
}
|
||||
if unexpectedFlags != "" {
|
||||
android.AssertStringDoesNotContain(t, "unexpected flag in R8 flags",
|
||||
appR8.Args["r8Flags"], unexpectedFlags)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue