diff options
author | 2021-09-28 09:19:17 -0400 | |
---|---|---|
committer | 2021-12-02 11:00:46 -0500 | |
commit | 12615dbbca609cd07a8c8345a4fbb89558f224f1 (patch) | |
tree | 75c7836f7e08ca6a8a6525930e0b9a33ab55f48a /cc/proto.go | |
parent | a9351ef6e62c4961c558b33637529a09e4348464 (diff) |
bp2build: support full/lite protos in cc libs
Test: bp2build.sh
Bug: 200601772
Change-Id: I3a7e00546726bc63b5eb8d5604557c5988a5320b
Diffstat (limited to 'cc/proto.go')
-rw-r--r-- | cc/proto.go | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/cc/proto.go b/cc/proto.go index 44661447c..f3410bc2b 100644 --- a/cc/proto.go +++ b/cc/proto.go @@ -16,8 +16,14 @@ package cc import ( "github.com/google/blueprint/pathtools" + "github.com/google/blueprint/proptools" "android/soong/android" + "android/soong/bazel" +) + +const ( + protoTypeDefault = "lite" ) // genProto creates a rule to convert a .proto file to generated .pb.cc and .pb.h files and returns @@ -63,7 +69,7 @@ func protoDeps(ctx DepsContext, deps Deps, p *android.ProtoProperties, static bo var lib string if String(p.Proto.Plugin) == "" { - switch String(p.Proto.Type) { + switch proptools.StringDefault(p.Proto.Type, protoTypeDefault) { case "full": if ctx.useSdk() { lib = "libprotobuf-cpp-full-ndk" @@ -71,7 +77,7 @@ func protoDeps(ctx DepsContext, deps Deps, p *android.ProtoProperties, static bo } else { lib = "libprotobuf-cpp-full" } - case "lite", "": + case "lite": if ctx.useSdk() { lib = "libprotobuf-cpp-lite-ndk" static = true @@ -157,3 +163,69 @@ func protoFlags(ctx ModuleContext, flags Flags, p *android.ProtoProperties) Flag return flags } + +type protoAttributes struct { + Deps bazel.LabelListAttribute +} + +type bp2buildProtoDeps struct { + wholeStaticLib *bazel.LabelAttribute + implementationWholeStaticLib *bazel.LabelAttribute + protoDep *bazel.LabelAttribute +} + +func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs bazel.LabelListAttribute) bp2buildProtoDeps { + var ret bp2buildProtoDeps + + protoInfo, ok := android.Bp2buildProtoProperties(ctx, m, protoSrcs) + if !ok { + return ret + } + + var depName string + typ := proptools.StringDefault(protoInfo.Type, protoTypeDefault) + var rule_class string + suffix := "_cc_proto" + switch typ { + case "lite": + suffix += "_lite" + rule_class = "cc_lite_proto_library" + depName = "libprotobuf-cpp-lite" + case "full": + rule_class = "cc_proto_library" + depName = "libprotobuf-cpp-full" + default: + ctx.PropertyErrorf("proto.type", "cannot handle conversion at this time: %q", typ) + } + + dep := android.BazelLabelForModuleDepSingle(ctx, depName) + ret.protoDep = &bazel.LabelAttribute{Value: &dep} + + protoLabel := bazel.Label{Label: ":" + protoInfo.Name} + 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:cc_proto.bzl", + }, + android.CommonAttributes{Name: name}, + &protoAttrs) + + var privateHdrs bool + if lib, ok := m.linker.(*libraryDecorator); ok { + privateHdrs = !proptools.Bool(lib.Properties.Proto.Export_proto_headers) + } + + labelAttr := &bazel.LabelAttribute{Value: &bazel.Label{Label: ":" + name}} + if privateHdrs { + ret.implementationWholeStaticLib = labelAttr + } else { + ret.wholeStaticLib = labelAttr + } + + return ret +} |