diff options
author | 2025-03-10 23:03:00 +0000 | |
---|---|---|
committer | 2025-03-11 22:40:57 +0000 | |
commit | 0ac6ae721d7400e0f5fa6d03f08eca63412390cc (patch) | |
tree | 4a3816f5e69ef46b4fa2a887a452180b728e3056 /java/dex_test.go | |
parent | 6a3b2d08fdef380fbced31156e27dea01d35ccd2 (diff) |
Add a trace_references_from dex optimization property
Introduce a new property `trace_references_from` in the optimize block.
This field allows specifying a set of downstream targets from which to
trace references when optimizing the current target.
In practice, this requires explicit breaking of any cycles that might
occur. A follow-up effort will explore doing this dynamically and
implicitly for `libs` references onto an optimized target that
enables this feature.
Bug: 212737576
Test: m nothing
Test: go test ./java
Flag: EXEMPT bugfix
Change-Id: I088bd8bf89403661a084a43b2822a6efbbc0294d
Diffstat (limited to 'java/dex_test.go')
-rw-r--r-- | java/dex_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/java/dex_test.go b/java/dex_test.go index 66d801dcc..e94864bbc 100644 --- a/java/dex_test.go +++ b/java/dex_test.go @@ -866,3 +866,46 @@ func TestDebugReleaseFlags(t *testing.T) { }) } } + +func TestTraceReferences(t *testing.T) { + t.Parallel() + bp := ` + android_app { + name: "app", + libs: ["lib.impl"], + srcs: ["foo.java"], + platform_apis: true, + } + + java_library { + name: "lib", + optimize: { + enabled: true, + trace_references_from: ["app"], + }, + srcs: ["bar.java"], + static_libs: ["lib.impl"], + installable: true, + } + + java_library { + name: "lib.impl", + srcs: ["baz.java"], + } + ` + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + ).RunTestWithBp(t, bp) + + appJar := result.ModuleForTests(t, "app", "android_common").Output("combined/app.jar").Output + libJar := result.ModuleForTests(t, "lib", "android_common").Output("combined/lib.jar").Output + libTraceRefs := result.ModuleForTests(t, "lib", "android_common").Rule("traceReferences") + libR8 := result.ModuleForTests(t, "lib", "android_common").Rule("r8") + + android.AssertStringDoesContain(t, "expected trace reference source from app jar", + libTraceRefs.Args["sources"], "--source "+appJar.String()) + android.AssertStringEquals(t, "expected trace reference target into lib jar", + libJar.String(), libTraceRefs.Input.String()) + android.AssertStringDoesContain(t, "expected trace reference proguard flags in lib r8 flags", + libR8.Args["r8Flags"], "trace_references.flags") +} |