Split java_binary modules into common and binary variants
Add a common_first multilib type and use it for java.Binary
so that the java part is compiled as a "common" arch type
but the wrapper script is installed as a "linux_glibc" arch
type. This allows java_binary to be used as a tool dependency
for a genrule.
Bug: 68397812
Test: TestJavaBinary
Change-Id: I809060839ce8878300da3fb76426ceb1ea6b0e8e
diff --git a/java/java_test.go b/java/java_test.go
index 58b27c3..78fbd41 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -62,6 +62,7 @@
ctx := android.NewTestArchContext()
ctx.RegisterModuleType("android_app", android.ModuleFactoryAdaptor(AndroidAppFactory))
+ ctx.RegisterModuleType("java_binary_host", android.ModuleFactoryAdaptor(BinaryHostFactory))
ctx.RegisterModuleType("java_library", android.ModuleFactoryAdaptor(LibraryFactory(true)))
ctx.RegisterModuleType("java_library_host", android.ModuleFactoryAdaptor(LibraryHostFactory))
ctx.RegisterModuleType("java_import", android.ModuleFactoryAdaptor(ImportFactory))
@@ -147,6 +148,8 @@
// For framework-res, which is an implicit dependency for framework
"AndroidManifest.xml": nil,
"build/target/product/security/testkey": nil,
+
+ "build/soong/scripts/jar-wrapper.sh": nil,
}
for k, v := range fs {
@@ -159,6 +162,7 @@
}
func run(t *testing.T, ctx *android.TestContext, config android.Config) {
+ t.Helper()
_, errs := ctx.ParseFileList(".", []string{"Android.bp"})
fail(t, errs)
_, errs = ctx.PrepareBuildActions(config)
@@ -166,6 +170,7 @@
}
func testJava(t *testing.T, bp string) *android.TestContext {
+ t.Helper()
config := testConfig(nil)
ctx := testContext(config, bp, nil)
run(t, ctx, config)
@@ -250,6 +255,35 @@
}
}
+func TestBinary(t *testing.T) {
+ ctx := testJava(t, `
+ java_library_host {
+ name: "foo",
+ srcs: ["a.java"],
+ }
+
+ java_binary_host {
+ name: "bar",
+ srcs: ["b.java"],
+ static_libs: ["foo"],
+ }
+ `)
+
+ buildOS := android.BuildOs.String()
+
+ bar := ctx.ModuleForTests("bar", buildOS+"_common")
+ barJar := bar.Output("bar.jar").Output.String()
+ barWrapper := ctx.ModuleForTests("bar", buildOS+"_x86_64")
+ barWrapperDeps := barWrapper.Output("bar").Implicits.Strings()
+
+ // Test that the install binary wrapper depends on the installed jar file
+ if len(barWrapperDeps) != 1 || barWrapperDeps[0] != barJar {
+ t.Errorf("expected binary wrapper implicits [%q], got %v",
+ barJar, barWrapperDeps)
+ }
+
+}
+
var classpathTestcases = []struct {
name string
moduleType string
@@ -831,6 +865,7 @@
}
func fail(t *testing.T, errs []error) {
+ t.Helper()
if len(errs) > 0 {
for _, err := range errs {
t.Error(err)