From 362aa9db1236f6cf09a01c6295b2f401fc483d7c Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Fri, 20 Jan 2023 19:44:07 +0000 Subject: Add libs property to java_api_library module Module Lib API surface takes modules that are not part of the API surface as classpath during compilation of the JAR file. Thus, add libs property to add deps in bp module definition. Test: m Change-Id: I8967d53430fa4cc8e4aa431770ba4e97893f8c61 --- java/java_test.go | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 5 deletions(-) (limited to 'java/java_test.go') diff --git a/java/java_test.go b/java/java_test.go index 49adefbde..ae77842a5 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -1895,22 +1895,26 @@ func TestJavaApiLibraryAndProviderLink(t *testing.T) { } func TestJavaApiLibraryAndDefaultsLink(t *testing.T) { - provider_bp_a := `java_api_contribution { + provider_bp_a := ` + java_api_contribution { name: "foo1", api_file: "foo1.txt", } ` - provider_bp_b := `java_api_contribution { + provider_bp_b := ` + java_api_contribution { name: "foo2", api_file: "foo2.txt", } ` - provider_bp_c := `java_api_contribution { + provider_bp_c := ` + java_api_contribution { name: "foo3", api_file: "foo3.txt", } ` - provider_bp_d := `java_api_contribution { + provider_bp_d := ` + java_api_contribution { name: "foo4", api_file: "foo4.txt", } @@ -1989,7 +1993,8 @@ func TestJavaApiLibraryJarGeneration(t *testing.T) { api_file: "foo1.txt", } ` - provider_bp_b := `java_api_contribution { + provider_bp_b := ` + java_api_contribution { name: "foo2", api_file: "foo2.txt", } @@ -2034,6 +2039,81 @@ func TestJavaApiLibraryJarGeneration(t *testing.T) { } } +func TestJavaApiLibraryLibsLink(t *testing.T) { + provider_bp_a := ` + java_api_contribution { + name: "foo1", + api_file: "foo1.txt", + } + ` + provider_bp_b := ` + java_api_contribution { + name: "foo2", + api_file: "foo2.txt", + } + ` + lib_bp_a := ` + java_library { + name: "lib1", + srcs: ["Lib.java"], + } + ` + lib_bp_b := ` + java_library { + name: "lib2", + srcs: ["Lib.java"], + } + ` + + ctx, _ := testJavaWithFS(t, ` + java_api_library { + name: "bar1", + api_surface: "public", + api_contributions: ["foo1"], + libs: ["lib1"], + } + + java_api_library { + name: "bar2", + api_surface: "system", + api_contributions: ["foo1", "foo2"], + libs: ["lib1", "lib2", "bar1"], + } + `, + map[string][]byte{ + "a/Android.bp": []byte(provider_bp_a), + "b/Android.bp": []byte(provider_bp_b), + "c/Android.bp": []byte(lib_bp_a), + "c/Lib.java": {}, + "d/Android.bp": []byte(lib_bp_b), + "d/Lib.java": {}, + }) + + testcases := []struct { + moduleName string + classPathJarNames []string + }{ + { + moduleName: "bar1", + classPathJarNames: []string{"lib1.jar"}, + }, + { + moduleName: "bar2", + classPathJarNames: []string{"lib1.jar", "lib2.jar", "bar1/android.jar"}, + }, + } + for _, c := range testcases { + m := ctx.ModuleForTests(c.moduleName, "android_common") + javacRules := m.Rule("javac") + classPathArgs := javacRules.Args["classpath"] + for _, jarName := range c.classPathJarNames { + if !strings.Contains(classPathArgs, jarName) { + t.Errorf("Module output does not contain expected jar %s", jarName) + } + } + } +} + func TestTradefedOptions(t *testing.T) { result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, ` java_test_host { -- cgit v1.2.3-59-g8ed1b