Bp2build Java libs for java_binary -> java_import edge

Since Bazel's java_import requires a jars attribute to be specified,
the generated neverlink-duplicated module is of type java_library

Change-Id: I14a866dfc583507a9462add50d95060cbfe540c5
Bug: 244210934
Test: m bp2build, go test ./bp2build, manual inspection of generated Build and jar files
This commit is contained in:
Alix
2022-09-27 15:36:01 +00:00
parent 9b019134c2
commit b4e09a0ada
4 changed files with 99 additions and 6 deletions

View File

@@ -29,6 +29,7 @@ func runJavaBinaryHostTestCase(t *testing.T, tc Bp2buildTestCase) {
RunBp2BuildTestCase(t, func(ctx android.RegistrationContext) {
ctx.RegisterModuleType("cc_library_host_shared", cc.LibraryHostSharedFactory)
ctx.RegisterModuleType("java_library", java.LibraryFactory)
ctx.RegisterModuleType("java_import_host", java.ImportFactory)
}, tc)
}
@@ -102,3 +103,34 @@ java_library {
},
})
}
func TestJavaBinaryHostLibs(t *testing.T) {
runJavaBinaryHostTestCase(t, Bp2buildTestCase{
Description: "java_binary_host with srcs, libs.",
Filesystem: fs,
Blueprint: `java_binary_host {
name: "java-binary-host-libs",
libs: ["java-lib-dep-1"],
manifest: "test.mf",
srcs: ["a.java"],
}
java_import_host{
name: "java-lib-dep-1",
jars: ["foo.jar"],
bazel_module: { bp2build_available: false },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_binary", "java-binary-host-libs", AttrNameToString{
"main_class": `"com.android.test.MainClass"`,
"srcs": `["a.java"]`,
"deps": `[":java-lib-dep-1-neverlink"]`,
"target_compatible_with": `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`,
}),
},
})
}