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
This commit is contained in:
Jihoon Kang
2023-01-20 19:44:07 +00:00
parent d623192eea
commit 362aa9db12
2 changed files with 107 additions and 9 deletions

View File

@@ -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 {