summaryrefslogtreecommitdiff
path: root/java/proto.go
diff options
context:
space:
mode:
author Sam Delmerico <delmerico@google.com> 2022-02-04 21:01:20 +0000
committer Sam Delmerico <delmerico@google.com> 2022-02-15 21:04:59 +0000
commitc768102bce5d64f93559a75783edb5509669f58c (patch)
treea97f73fda34be89600ae76b5db867ad7bdac144b /java/proto.go
parent5ee913f527829e0f3465c50a13825e1a7065288f (diff)
convert java proto libraries with bp2build
Allow java_libraries that depend on protobufs to be converted with bp2build. Bug: 215230097 Test: build/bazel/ci/bp2build.sh Change-Id: I3ce52389e7e4e82755605ee277c1e527a6aebc6b
Diffstat (limited to 'java/proto.go')
-rw-r--r--java/proto.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/java/proto.go b/java/proto.go
index 8d2380322..5ba486fd6 100644
--- a/java/proto.go
+++ b/java/proto.go
@@ -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}
+}