summaryrefslogtreecommitdiff
path: root/java/java_test.go
diff options
context:
space:
mode:
author Spandan Das <spandandas@google.com> 2024-09-26 23:53:58 +0000
committer Spandan Das <spandandas@google.com> 2024-09-28 04:36:43 +0000
commit77e27d44efe2b5fd390aaaad00b289996175f3a0 (patch)
treeab8eea27677c53d5c5486fc69caf211fc0032352 /java/java_test.go
parent22ad6c00c7b5ef51687bcde6fcfe4e7988a16d2c (diff)
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
Diffstat (limited to 'java/java_test.go')
-rw-r--r--java/java_test.go34
1 files changed, 34 insertions, 0 deletions
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))
+}