From 0ac6ae721d7400e0f5fa6d03f08eca63412390cc Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Mon, 10 Mar 2025 23:03:00 +0000 Subject: 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 --- java/dex_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'java/dex_test.go') 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") +} -- cgit v1.2.3-59-g8ed1b