diff options
| author | Zi Wang <mrziwang@google.com> | 2023-09-13 00:30:39 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-09-13 00:30:39 +0000 |
| commit | c90e1ec78421f7c1b924468a426a52da9d55f611 (patch) | |
| tree | ad14267b93d2f58487297017f07864c9868e51d4 /java/java.go | |
| parent | d753c2e53c39c68dc25b065b9f2904f54f0f90e1 (diff) | |
| parent | 774c6eaf103c3ffd4db54470bd044b621d5a3904 (diff) | |
Merge "Bp2build: handle the case where java_library has only proto srcs" into main
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/java/java.go b/java/java.go index 99bb1b3ee..a81abe61c 100644 --- a/java/java.go +++ b/java/java.go @@ -2885,8 +2885,9 @@ type javaAidlLibraryAttributes struct { // depending on the module type. type bp2BuildJavaInfo struct { // separates dependencies into dynamic dependencies and static dependencies. - DepLabels *javaDependencyLabels - hasKotlin bool + DepLabels *javaDependencyLabels + hasKotlin bool + onlyProtoInSrcs bool } func javaXsdTargetName(xsd android.XsdConfigBp2buildTargets) string { @@ -2949,6 +2950,9 @@ 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( @@ -3086,8 +3090,9 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) } bp2BuildInfo := &bp2BuildJavaInfo{ - DepLabels: depLabels, - hasKotlin: hasKotlin, + DepLabels: depLabels, + hasKotlin: hasKotlin, + onlyProtoInSrcs: onlyProtoInSrcs, } return commonAttrs, bp2BuildInfo, true @@ -3127,16 +3132,29 @@ func javaLibraryBp2Build(ctx android.TopDownMutatorContext, m *Library) { depLabels := bp2BuildInfo.DepLabels deps := depLabels.Deps + exports := depLabels.StaticDeps if !commonAttrs.Srcs.IsEmpty() { - deps.Append(depLabels.StaticDeps) // 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() { - ctx.ModuleErrorf("Module has direct dependencies but no sources. Bazel will not allow this.") + 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 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 attrs := &javaLibraryAttributes{ javaCommonAttributes: commonAttrs, Deps: deps, - Exports: depLabels.StaticDeps, + Exports: exports, } name := m.Name() |
