From 77e27d44efe2b5fd390aaaad00b289996175f3a0 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 26 Sep 2024 23:53:58 +0000 Subject: Find matching variant of `required` for `common_first` Both 32-bit and 64-bit variants of native deps were getting installed in Soong-built system image if they were listed in `required` of `java_binary`. java_binary(s) have two variants, a "common" and an arch variant (the first arch). Previously the common variant will create a dependency to both 32-bit and 64-bit variants of their dependencies. With this CL, common variant will not create a dependency on required unless the requested `target` is also the common target. Test: Ran the filelistdiff tool Test: go test ./java -run TestNativeRequiredDepOfJavaBinary Bug: 369678122 Change-Id: Ica97e12eefb45929ca653ec57c3339e4a3b72a76 --- java/java_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'java/java_test.go') diff --git a/java/java_test.go b/java/java_test.go index 641bf4030..e976b081e 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -3132,3 +3132,37 @@ func assertTestOnlyAndTopLevel(t *testing.T, ctx *android.TestResult, expectedTe t.Errorf("top-level: Expected but not found: %v, Found but not expected: %v", left, right) } } + +// Test that a dependency edge is created to the "first" variant of a native library listed in `required` of java_binary +func TestNativeRequiredDepOfJavaBinary(t *testing.T) { + findDepsOfModule := func(ctx *android.TestContext, module android.Module, depName string) []blueprint.Module { + var ret []blueprint.Module + ctx.VisitDirectDeps(module, func(dep blueprint.Module) { + if dep.Name() == depName { + ret = append(ret, dep) + } + }) + return ret + } + + bp := cc.GatherRequiredDepsForTest(android.Android) + ` +java_binary { + name: "myjavabin", + main_class: "com.android.MyJava", + required: ["mynativelib"], +} +cc_library_shared { + name: "mynativelib", +} +` + res, _ := testJava(t, bp) + // The first variant installs the native library via the common variant, so check the deps of both variants. + nativeVariantDepsWithDups := findDepsOfModule(res, res.ModuleForTests("myjavabin", "android_arm64_armv8-a").Module(), "mynativelib") + nativeVariantDepsWithDups = append(nativeVariantDepsWithDups, findDepsOfModule(res, res.ModuleForTests("myjavabin", "android_common").Module(), "mynativelib")...) + + nativeVariantDepsUnique := map[blueprint.Module]bool{} + for _, dep := range nativeVariantDepsWithDups { + nativeVariantDepsUnique[dep] = true + } + android.AssertIntEquals(t, "Create a dep on the first variant", 1, len(nativeVariantDepsUnique)) +} -- cgit v1.2.3-59-g8ed1b