aboutsummaryrefslogtreecommitdiffhomepage
path: root/bazel
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2017-05-11 23:24:37 +0200
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2017-05-11 23:24:37 +0200
commiteb36b8ac7700d43ec9dadfffbfa83d0540cbdb27 (patch)
tree24f8d3bd3640dd95a470c52bd718fc8fcb5b087c /bazel
parent0444d98f17c7e742be1463e5714a24cd2eb6f99e (diff)
parent45b89fb11ca3cd524787aeba7a1270f744a1256c (diff)
Merge branch 'master' of https://github.com/grpc/grpc into import
Diffstat (limited to 'bazel')
-rw-r--r--bazel/BUILD2
-rw-r--r--bazel/cc_grpc_library.bzl6
-rw-r--r--bazel/generate_cc.bzl31
-rw-r--r--bazel/grpc_build_system.bzl19
4 files changed, 43 insertions, 15 deletions
diff --git a/bazel/BUILD b/bazel/BUILD
index 9387dddab6..cb2d9d66ae 100644
--- a/bazel/BUILD
+++ b/bazel/BUILD
@@ -35,7 +35,7 @@ load(":cc_grpc_library.bzl", "cc_grpc_library")
proto_library(
name = "well_known_protos_list",
- srcs = ["@submodule_protobuf//:well_known_protos"],
+ srcs = ["@com_google_protobuf//:well_known_protos"],
)
cc_grpc_library(
diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl
index ab1add476e..0600bb9e30 100644
--- a/bazel/cc_grpc_library.bzl
+++ b/bazel/cc_grpc_library.bzl
@@ -2,7 +2,7 @@
load("//:bazel/generate_cc.bzl", "generate_cc")
-def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_external = False, **kwargs):
+def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, generate_mock, use_external = False, **kwargs):
"""Generates C++ grpc classes from a .proto file.
Assumes the generated classes will be used in cc_api_version = 2.
@@ -14,9 +14,10 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_externa
the compiled code of any message that the services depend on.
well_known_protos: The target from protobuf library that exports well
known protos. Currently it will only work if the value is
- "@submodule_protobuf//:well_known_protos"
+ "@com_google_protobuf//:well_known_protos"
use_external: When True the grpc deps are prefixed with //external. This
allows grpc to be used as a dependency in other bazel projects.
+ generate_mock: When true GMOCk code for client stub is generated.
**kwargs: rest of arguments, e.g., compatible_with and visibility.
"""
if len(srcs) > 1:
@@ -54,6 +55,7 @@ def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_externa
srcs = [proto_target],
plugin = plugin,
well_known_protos = well_known_protos,
+ generate_mock = generate_mock,
**kwargs
)
diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl
index f3961f0a41..d05509fc15 100644
--- a/bazel/generate_cc.bzl
+++ b/bazel/generate_cc.bzl
@@ -9,21 +9,26 @@ def generate_cc_impl(ctx):
protos = [f for src in ctx.attr.srcs for f in src.proto.direct_sources]
includes = [f for src in ctx.attr.srcs for f in src.proto.transitive_imports]
outs = []
+ # label_len is length of the path from WORKSPACE root to the location of this build file
+ label_len = len(ctx.label.package) + 1
if ctx.executable.plugin:
- outs += [proto.basename[:-len(".proto")] + ".grpc.pb.h" for proto in protos]
- outs += [proto.basename[:-len(".proto")] + ".grpc.pb.cc" for proto in protos]
+ outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.h" for proto in protos]
+ outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.cc" for proto in protos]
+ if ctx.attr.generate_mock:
+ outs += [proto.path[label_len:-len(".proto")] + "_mock.grpc.pb.h" for proto in protos]
else:
- outs += [proto.basename[:-len(".proto")] + ".pb.h" for proto in protos]
- outs += [proto.basename[:-len(".proto")] + ".pb.cc" for proto in protos]
+ outs += [proto.path[label_len:-len(".proto")] + ".pb.h" for proto in protos]
+ outs += [proto.path[label_len:-len(".proto")] + ".pb.cc" for proto in protos]
out_files = [ctx.new_file(out) for out in outs]
- # The following should be replaced with ctx.configuration.buildout
- # whenever this is added to Skylark.
- dir_out = out_files[0].dirname[:-len(protos[0].dirname)]
+ dir_out = str(ctx.genfiles_dir.path)
arguments = []
if ctx.executable.plugin:
arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path]
- arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
+ flags = list(ctx.attr.flags)
+ if ctx.attr.generate_mock:
+ flags.append("generate_mock_code=true")
+ arguments += ["--PLUGIN_out=" + ",".join(flags) + ":" + dir_out]
additional_input = [ctx.executable.plugin]
else:
arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
@@ -35,10 +40,10 @@ def generate_cc_impl(ctx):
well_known_proto_files = []
if ctx.attr.well_known_protos:
f = ctx.attr.well_known_protos.files.to_list()[0].dirname
- if f != "external/submodule_protobuf/src/google/protobuf":
- print("Error: Only @submodule_protobuf//:well_known_protos is supported")
+ if f != "external/com_google_protobuf/src/google/protobuf":
+ print("Error: Only @com_google_protobuf//:well_known_protos is supported")
else:
- # f points to "external/submodule_protobuf/src/google/protobuf"
+ # f points to "external/com_google_protobuf/src/google/protobuf"
# add -I argument to protoc so it knows where to look for the proto files.
arguments += ["-I{0}".format(f + "/../..")]
well_known_proto_files = [f for f in ctx.attr.well_known_protos.files]
@@ -71,6 +76,10 @@ generate_cc = rule(
"well_known_protos" : attr.label(
mandatory = False,
),
+ "generate_mock" : attr.bool(
+ default = False,
+ mandatory = False,
+ ),
"_protoc": attr.label(
default = Label("//external:protocol_compiler"),
executable = True,
diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl
index 46904450d2..a287e8f525 100644
--- a/bazel/grpc_build_system.bzl
+++ b/bazel/grpc_build_system.bzl
@@ -53,6 +53,22 @@ def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [],
]
)
+def grpc_cc_libraries(name_list, additional_src_list = [], additional_dep_list = [], srcs = [], public_hdrs = [], hdrs = [], external_deps = [], deps = [], standalone = False, language="C++"):
+ names = len(name_list)
+ asl = additional_src_list + [[]]*(names - len(additional_src_list))
+ adl = additional_dep_list + [[]]*(names - len(additional_dep_list))
+ for i in range(names):
+ grpc_cc_library(
+ name = name_list[i],
+ srcs = srcs + asl[i],
+ hdrs = hdrs,
+ public_hdrs = public_hdrs,
+ deps = deps + adl[i],
+ external_deps = external_deps,
+ standalone = standalone,
+ language = language
+ )
+
def grpc_proto_plugin(name, srcs = [], deps = []):
native.cc_binary(
name = name,
@@ -63,7 +79,7 @@ def grpc_proto_plugin(name, srcs = [], deps = []):
load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = None,
- has_services = True, use_external = False):
+ has_services = True, use_external = False, generate_mock = False):
cc_grpc_library(
name = name,
srcs = srcs,
@@ -71,6 +87,7 @@ def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = None,
well_known_protos = well_known_protos,
proto_only = not has_services,
use_external = use_external,
+ generate_mock = generate_mock,
)
def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++"):