Skip to content

Commit

Permalink
Fix well_known_protos issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vam-google committed May 6, 2019
1 parent db7fd70 commit 4c0d9e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
23 changes: 16 additions & 7 deletions bazel/cc_grpc_library.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Generates and compiles C++ grpc stubs from proto_library rules."""

load("//bazel:generate_cc.bzl", "generate_cc")
load("//bazel:protobuf.bzl", "well_known_proto_libs")

def cc_grpc_library(
name,
srcs,
deps,
proto_only = False,
well_known_protos = True,
well_known_protos = False,
generate_mocks = False,
use_external = False,
grpc_only = False,
Expand All @@ -33,27 +34,35 @@ def cc_grpc_library(
provides the compiled code of any message that the services depend on.
proto_only (bool): If True, create only C++ proto classes library,
avoid creating C++ grpc classes library (expect it in deps).
Deprecated, use native cc_proto_library instead.
well_known_protos (bool): Should this library additionally depend on
well known protos.
generate_mocks: when True, Google Mock code for client stub is generated.
use_external: Not used.
grpc_only: if True, generate only grpc library, expecting protobuf
messages library (cc_proto_library target) to be passed as deps.
well known protos. Deprecated, pass well_known_protos
explicitly (proto_library targets in srcs and corresponding
cc_proto_library in deps).
generate_mocks (bool): when True, Google Mock code for client stub is
generated.
use_external (bool): Not used.
grpc_only (bool): if True, generate only grpc library, expecting
protobuf messages library (cc_proto_library target) to be passed as
deps.
**kwargs: rest of arguments, e.g., compatible_with and visibility
"""
if len(srcs) > 1:
fail("Only one srcs value supported", "srcs")
if grpc_only and proto_only:
fail("A mutualy exclusive configuraiton is specified: grpc_only = True and proto_only = True")
fail("A mutualy exclusive configuration is specified: grpc_only = True and proto_only = True")

extra_deps = []
proto_target = None

if not grpc_only:
proto_target = "_" + name + "_only"
cc_proto_target = name if proto_only else "_" + name + "_cc_proto"

proto_deps = ["_" + dep + "_only" for dep in deps if dep.find(":") == -1]
proto_deps += [dep.split(":")[0] + ":" + "_" + dep.split(":")[1] + "_only" for dep in deps if dep.find(":") != -1]
if well_known_protos:
proto_deps += well_known_proto_libs()

native.proto_library(
name = proto_target,
Expand Down
16 changes: 16 additions & 0 deletions bazel/protobuf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

_PROTO_EXTENSION = ".proto"

def well_known_proto_libs():
return [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:api_proto",
"@com_google_protobuf//:compiler_plugin_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:field_mask_proto",
"@com_google_protobuf//:source_context_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:type_proto",
"@com_google_protobuf//:wrappers_proto",
]

def get_proto_root(workspace_root):
"""Gets the root protobuf directory.
Expand Down
17 changes: 0 additions & 17 deletions bazel/python_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,6 @@ def _generate_py(well_known_protos, **kwargs):
else:
__generate_py(**kwargs)

_WELL_KNOWN_PROTO_LIBS = [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:api_proto",
"@com_google_protobuf//:compiler_plugin_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:field_mask_proto",
"@com_google_protobuf//:source_context_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:type_proto",
"@com_google_protobuf//:wrappers_proto",
]

def py_proto_library(
name,
deps,
Expand All @@ -167,8 +152,6 @@ def py_proto_library(
codegen_target = "_{}_codegen".format(name)
codegen_grpc_target = "_{}_grpc_codegen".format(name)

well_known_proto_rules = _WELL_KNOWN_PROTO_LIBS if well_known_protos else []

_generate_py(
name = codegen_target,
deps = deps,
Expand Down

0 comments on commit 4c0d9e2

Please sign in to comment.