Merge "convert java proto libraries with bp2build" am: bc83b504ff am: 4dc3df7be7 am: 0d8dd4692b

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1975287

Change-Id: Ie93ce69b956aedbd4999283886ef9340d88fe530
This commit is contained in:
Sam Delmerico
2022-02-23 17:57:13 +00:00
committed by Automerger Merge Worker
7 changed files with 229 additions and 31 deletions

View File

@@ -2013,8 +2013,16 @@ type javaLibraryAttributes struct {
func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext) *javaLibraryAttributes {
//TODO(b/209577426): Support multiple arch variants
srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrcExcludes(ctx, m.properties.Srcs, m.properties.Exclude_srcs))
javaSrcPartition := "java"
protoSrcPartition := "proto"
srcPartitions := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
javaSrcPartition: bazel.LabelPartition{Extensions: []string{".java"}, Keep_remainder: true},
protoSrcPartition: android.ProtoSrcLabelPartition,
})
attrs := &javaLibraryAttributes{
Srcs: srcs,
Srcs: srcPartitions[javaSrcPartition],
}
if m.properties.Javacflags != nil {
@@ -2029,6 +2037,12 @@ func (m *Library) convertLibraryAttrsBp2Build(ctx android.TopDownMutatorContext)
//TODO(b/217236083) handle static libs similarly to Soong
deps.Append(android.BazelLabelForModuleDeps(ctx, m.properties.Static_libs))
}
protoDeps := bp2buildProto(ctx, &m.Module, srcPartitions[protoSrcPartition])
if protoDeps != nil {
deps.Add(protoDeps)
}
attrs.Deps = bazel.MakeLabelListAttribute(deps)
return attrs

View File

@@ -19,6 +19,13 @@ import (
"strconv"
"android/soong/android"
"android/soong/bazel"
"github.com/google/blueprint/proptools"
)
const (
protoTypeDefault = "lite"
)
func genProto(ctx android.ModuleContext, protoFiles android.Paths, flags android.ProtoFlags) android.Paths {
@@ -134,3 +141,52 @@ func protoFlags(ctx android.ModuleContext, j *CommonProperties, p *android.Proto
return flags
}
type protoAttributes struct {
Deps bazel.LabelListAttribute
}
func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs bazel.LabelListAttribute) *bazel.Label {
protoInfo, ok := android.Bp2buildProtoProperties(ctx, &m.ModuleBase, protoSrcs)
if !ok {
return nil
}
typ := proptools.StringDefault(protoInfo.Type, protoTypeDefault)
var rule_class string
suffix := "_java_proto"
switch typ {
case "nano":
suffix += "_nano"
rule_class = "java_nano_proto_library"
case "micro":
suffix += "_micro"
rule_class = "java_micro_proto_library"
case "lite":
suffix += "_lite"
rule_class = "java_lite_proto_library"
case "stream":
suffix += "_stream"
rule_class = "java_stream_proto_library"
case "full":
rule_class = "java_proto_library"
default:
ctx.PropertyErrorf("proto.type", "cannot handle conversion at this time: %q", typ)
}
protoLabel := bazel.Label{Label: ":" + m.Name() + "_proto"}
var protoAttrs protoAttributes
protoAttrs.Deps.SetValue(bazel.LabelList{Includes: []bazel.Label{protoLabel}})
name := m.Name() + suffix
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{
Rule_class: rule_class,
Bzl_load_location: "//build/bazel/rules/java:proto.bzl",
},
android.CommonAttributes{Name: name},
&protoAttrs)
return &bazel.Label{Label: ":" + name}
}