Merge changes from topic "drop_deps_no_srcs" into main am: 5d982b398e
am: cccefd7433
am: 7ccd48617c
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2752995 Change-Id: I8b85af966cb9126b45ed39c97776ed65b0d71409 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -15,7 +15,6 @@
|
|||||||
package bp2build
|
package bp2build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"android/soong/android"
|
"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) {
|
func TestJavaLibraryPlugins(t *testing.T) {
|
||||||
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
runJavaLibraryTestCaseWithRegistrationCtxFunc(t, Bp2buildTestCase{
|
||||||
Blueprint: `java_library {
|
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) {
|
func TestJavaLibraryArchVariantDeps(t *testing.T) {
|
||||||
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
runJavaLibraryTestCase(t, Bp2buildTestCase{
|
||||||
Description: "java_library with arch variant libs",
|
Description: "java_library with arch variant libs",
|
||||||
|
@@ -167,10 +167,7 @@ java_library_static {
|
|||||||
"sdk_version": `"current"`,
|
"sdk_version": `"current"`,
|
||||||
}),
|
}),
|
||||||
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
|
MakeBazelTarget("java_library", "java-protos", AttrNameToString{
|
||||||
"exports": `[
|
"exports": `[":java-protos_java_proto_lite"]`,
|
||||||
":java-protos_java_proto_lite",
|
|
||||||
":java-lib-neverlink",
|
|
||||||
]`,
|
|
||||||
"java_version": `"7"`,
|
"java_version": `"7"`,
|
||||||
"sdk_version": `"current"`,
|
"sdk_version": `"current"`,
|
||||||
}),
|
}),
|
||||||
|
32
java/java.go
32
java/java.go
@@ -2886,9 +2886,8 @@ type javaAidlLibraryAttributes struct {
|
|||||||
// depending on the module type.
|
// depending on the module type.
|
||||||
type bp2BuildJavaInfo struct {
|
type bp2BuildJavaInfo struct {
|
||||||
// separates dependencies into dynamic dependencies and static dependencies.
|
// separates dependencies into dynamic dependencies and static dependencies.
|
||||||
DepLabels *javaDependencyLabels
|
DepLabels *javaDependencyLabels
|
||||||
hasKotlin bool
|
hasKotlin bool
|
||||||
onlyProtoInSrcs bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func javaXsdTargetName(xsd android.XsdConfigBp2buildTargets) string {
|
func javaXsdTargetName(xsd android.XsdConfigBp2buildTargets) string {
|
||||||
@@ -2951,9 +2950,6 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
|
|||||||
|
|
||||||
staticDeps.Append(srcPartitions[xsdSrcPartition])
|
staticDeps.Append(srcPartitions[xsdSrcPartition])
|
||||||
|
|
||||||
_, protoInSrcs := srcPartitions[protoSrcPartition]
|
|
||||||
onlyProtoInSrcs := protoInSrcs && len(srcPartitions) == 1
|
|
||||||
|
|
||||||
if !srcPartitions[logtagSrcPartition].IsEmpty() {
|
if !srcPartitions[logtagSrcPartition].IsEmpty() {
|
||||||
logtagsLibName := m.Name() + "_logtags"
|
logtagsLibName := m.Name() + "_logtags"
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
@@ -3091,9 +3087,8 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bp2BuildInfo := &bp2BuildJavaInfo{
|
bp2BuildInfo := &bp2BuildJavaInfo{
|
||||||
DepLabels: depLabels,
|
DepLabels: depLabels,
|
||||||
hasKotlin: hasKotlin,
|
hasKotlin: hasKotlin,
|
||||||
onlyProtoInSrcs: onlyProtoInSrcs,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return commonAttrs, bp2BuildInfo, true
|
return commonAttrs, bp2BuildInfo, true
|
||||||
@@ -3137,19 +3132,12 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) {
|
|||||||
if !commonAttrs.Srcs.IsEmpty() {
|
if !commonAttrs.Srcs.IsEmpty() {
|
||||||
deps.Append(exports) // we should only append these if there are sources to use them
|
deps.Append(exports) // we should only append these if there are sources to use them
|
||||||
} else if !deps.IsEmpty() {
|
} else if !deps.IsEmpty() {
|
||||||
if bp2BuildInfo.onlyProtoInSrcs {
|
// java_library does not accept deps when there are no srcs because
|
||||||
// java_library does not accept deps when there are no srcs because
|
// there is no compilation happening, but it accepts exports.
|
||||||
// there is no compilation happening, but it accepts exports.
|
// The non-empty deps here are unnecessary as deps on the java_library
|
||||||
// bp2build converts this module to 2 java_libraries + java_xx_proto_library + proto_library
|
// since they aren't being propagated to any dependencies.
|
||||||
// the non-empty deps here are not necessary for compiling the protos, in which case
|
// So we can drop deps here.
|
||||||
// they're unnecessary as deps on the java_library as well since they aren't
|
deps = bazel.LabelListAttribute{}
|
||||||
// being propagated to any dependencies.
|
|
||||||
// so we can put the deps to exports and drop deps here.
|
|
||||||
exports.Append(deps)
|
|
||||||
deps = bazel.LabelListAttribute{}
|
|
||||||
} else {
|
|
||||||
ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var props bazel.BazelTargetModuleProperties
|
var props bazel.BazelTargetModuleProperties
|
||||||
attrs := &javaLibraryAttributes{
|
attrs := &javaLibraryAttributes{
|
||||||
|
Reference in New Issue
Block a user