diff options
author | 2023-09-15 09:46:17 -0700 | |
---|---|---|
committer | 2023-09-15 10:37:16 -0700 | |
commit | dd93636f1e642f75f334d178a13a665f11080900 (patch) | |
tree | b4b01587a411178daa64fe9e011048ed06a1c625 /java/java.go | |
parent | f038cde8df5623a11c0a198378650684e7388080 (diff) |
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
Diffstat (limited to 'java/java.go')
-rw-r--r-- | java/java.go | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/java/java.go b/java/java.go index 3567dbead..48e13feb8 100644 --- a/java/java.go +++ b/java/java.go @@ -2886,9 +2886,8 @@ type javaAidlLibraryAttributes struct { // depending on the module type. type bp2BuildJavaInfo struct { // separates dependencies into dynamic dependencies and static dependencies. - DepLabels *javaDependencyLabels - hasKotlin bool - onlyProtoInSrcs bool + DepLabels *javaDependencyLabels + hasKotlin bool } func javaXsdTargetName(xsd android.XsdConfigBp2buildTargets) string { @@ -2951,9 +2950,6 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) staticDeps.Append(srcPartitions[xsdSrcPartition]) - _, protoInSrcs := srcPartitions[protoSrcPartition] - onlyProtoInSrcs := protoInSrcs && len(srcPartitions) == 1 - if !srcPartitions[logtagSrcPartition].IsEmpty() { logtagsLibName := m.Name() + "_logtags" ctx.CreateBazelTargetModule( @@ -3091,9 +3087,8 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) } bp2BuildInfo := &bp2BuildJavaInfo{ - DepLabels: depLabels, - hasKotlin: hasKotlin, - onlyProtoInSrcs: onlyProtoInSrcs, + DepLabels: depLabels, + hasKotlin: hasKotlin, } return commonAttrs, bp2BuildInfo, true @@ -3137,17 +3132,12 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { if !commonAttrs.Srcs.IsEmpty() { deps.Append(exports) // we should only append these if there are sources to use them } else if !deps.IsEmpty() { - if bp2BuildInfo.onlyProtoInSrcs { - // java_library does not accept deps when there are no srcs because - // there is no compilation happening, but it accepts exports. - // bp2build converts this module to 2 java_libraries + java_xx_proto_library + proto_library - // the non-empty deps here are not necessary for compiling the protos, in which case - // they're unnecessary as deps on the java_library as well since they aren't - // being propagated to any dependencies. So we can drop deps here. - deps = bazel.LabelListAttribute{} - } else { - ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") - } + // java_library does not accept deps when there are no srcs because + // there is no compilation happening, but it accepts exports. + // The non-empty deps here are unnecessary as deps on the java_library + // since they aren't being propagated to any dependencies. + // So we can drop deps here. + deps = bazel.LabelListAttribute{} } var props bazel.BazelTargetModuleProperties attrs := &javaLibraryAttributes{ |