Always drop deps from java_library with no srcs

This is the follow up from aosp/2750763

Test: CI and added unit test

Bug: 285952385
Change-Id: I64703ee4fa742b718ffb43f2af1b6ab43ddeb606
This commit is contained in:
Zi Wang
2023-09-15 09:46:17 -07:00
parent f038cde8df
commit dd93636f1e
2 changed files with 34 additions and 41 deletions

View File

@@ -15,7 +15,6 @@
package bp2build
import (
"fmt"
"testing"
"android/soong/android"
@@ -143,26 +142,6 @@ java_library {
})
}
func TestJavaLibraryFailsToConvertLibsWithNoSrcs(t *testing.T) {
runJavaLibraryTestCase(t, Bp2buildTestCase{
ExpectedErr: fmt.Errorf("Module has direct dependencies but no sources. Bazel will not allow this."),
Blueprint: `java_library {
name: "java-lib-1",
libs: ["java-lib-2"],
sdk_version: "current",
bazel_module: { bp2build_available: true },
}
java_library {
name: "java-lib-2",
srcs: ["a.java"],
sdk_version: "current",
bazel_module: { bp2build_available: false },
}`,
ExpectedBazelTargets: []string{},
})
}
func TestJavaLibraryPlugins(t *testing.T) {
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
Blueprint: `java_library {
@@ -869,6 +848,30 @@ func TestJavaLibraryKotlinCommonSrcs(t *testing.T) {
})
}
func TestJavaLibraryLibsWithNoSrcs(t *testing.T) {
runJavaLibraryTestCase(t, Bp2buildTestCase{
Description: "java_library that has libs but no srcs",
Blueprint: `java_library {
name: "java-lib-1",
libs: ["java-lib-2"],
sdk_version: "current",
bazel_module: { bp2build_available: true },
}
java_library{
name: "java-lib-2",
bazel_module: { bp2build_available: false },
}
`,
ExpectedBazelTargets: []string{
MakeBazelTarget("java_library", "java-lib-1", AttrNameToString{
"sdk_version": `"current"`,
}),
MakeNeverlinkDuplicateTarget("java_library", "java-lib-1"),
},
})
}
func TestJavaLibraryArchVariantDeps(t *testing.T) {
runJavaLibraryTestCase(t, Bp2buildTestCase{
Description: "java_library with arch variant libs",