Fix well_known_protos issue

pull/18955/head
vam 6 years ago
parent db7fd70166
commit 4c0d9e2f6b
  1. 23
      bazel/cc_grpc_library.bzl
  2. 16
      bazel/protobuf.bzl
  3. 17
      bazel/python_rules.bzl

@ -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,
@ -33,20 +34,26 @@ 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"
@ -54,6 +61,8 @@ def cc_grpc_library(
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,

@ -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.

@ -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,
@ -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,

Loading…
Cancel
Save