From e30fff0b5c4a8676fb48f14a813ac238217c8937 Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Tue, 14 Feb 2023 20:18:20 +0000 Subject: Add static_libs property in java_api_library soong module Package private stub annotations are not part of any API surfaces, but are included in the `android__stubs_current`. Since these cannot be included in the java_api_library by api_contributions, add static_libs property to statically include jars in the output jar file. Test: m Change-Id: Icb4401f29079ba32df4c192943a7e8814599d9ba --- java/java_test.go | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'java/java_test.go') diff --git a/java/java_test.go b/java/java_test.go index 21993eccf..dc42e9e59 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2128,6 +2128,80 @@ func TestJavaApiLibraryLibsLink(t *testing.T) { } } +func TestJavaApiLibraryStaticLibsLink(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"], + static_libs: ["lib1"], + } + + java_api_library { + name: "bar2", + api_surface: "system", + api_contributions: ["foo1", "foo2"], + static_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 + staticLibJarNames []string + }{ + { + moduleName: "bar1", + staticLibJarNames: []string{"lib1.jar"}, + }, + { + moduleName: "bar2", + staticLibJarNames: []string{"lib1.jar", "lib2.jar", "bar1/android.jar"}, + }, + } + for _, c := range testcases { + m := ctx.ModuleForTests(c.moduleName, "android_common") + mergeZipsCommand := m.Rule("merge_zips").RuleParams.Command + for _, jarName := range c.staticLibJarNames { + if !strings.Contains(mergeZipsCommand, jarName) { + t.Errorf("merge_zips command 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