Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: third_party/protobuf/protobuf.bzl

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/protobuf/php/tests/autoload.php ('k') | third_party/protobuf/protobuf.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/protobuf/protobuf.bzl
diff --git a/third_party/protobuf/protobuf.bzl b/third_party/protobuf/protobuf.bzl
index bf748db664b971e933b8ae1cb3dbf0109d47caf8..fbcae0b3242f81dfc9cb58ce090714dafa36935b 100644
--- a/third_party/protobuf/protobuf.bzl
+++ b/third_party/protobuf/protobuf.bzl
@@ -1,17 +1,27 @@
# -*- mode: python; -*- PYTHON-PREPROCESSING-REQUIRED
+def _GetPath(ctx, path):
+ if ctx.label.workspace_root:
+ return ctx.label.workspace_root + '/' + path
+ else:
+ return path
+
def _GenDir(ctx):
if not ctx.attr.includes:
- return ""
+ return ctx.label.workspace_root
if not ctx.attr.includes[0]:
- return ctx.label.package
+ return _GetPath(ctx, ctx.label.package)
if not ctx.label.package:
- return ctx.attr.includes[0]
- return ctx.label.package + '/' + ctx.attr.includes[0]
+ return _GetPath(ctx, ctx.attr.includes[0])
+ return _GetPath(ctx, ctx.label.package + '/' + ctx.attr.includes[0])
-def _CcOuts(srcs):
- return [s[:-len(".proto")] + ".pb.h" for s in srcs] + \
- [s[:-len(".proto")] + ".pb.cc" for s in srcs]
+def _CcOuts(srcs, use_grpc_plugin=False):
+ ret = [s[:-len(".proto")] + ".pb.h" for s in srcs] + \
+ [s[:-len(".proto")] + ".pb.cc" for s in srcs]
+ if use_grpc_plugin:
+ ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs] + \
+ [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
+ return ret
def _PyOuts(srcs):
return [s[:-len(".proto")] + "_pb2.py" for s in srcs]
@@ -36,8 +46,6 @@ def _RelativeOutputPath(path, include):
return path[len(PACKAGE_NAME)+1:]
-
-
def _proto_gen_impl(ctx):
"""General implementation for generating protos"""
srcs = ctx.files.srcs
@@ -59,6 +67,10 @@ def _proto_gen_impl(ctx):
if ctx.attr.gen_py:
args += ["--python_out=" + ctx.var["GENDIR"] + "/" + gen_dir]
+ if ctx.executable.grpc_cpp_plugin:
+ args += ["--plugin=protoc-gen-grpc=" + ctx.executable.grpc_cpp_plugin.path]
+ args += ["--grpc_out=" + ctx.var["GENDIR"] + "/" + gen_dir]
+
if args:
ctx.action(
inputs=srcs + deps,
@@ -86,6 +98,11 @@ _proto_gen = rule(
single_file = True,
mandatory = True,
),
+ "grpc_cpp_plugin": attr.label(
+ cfg = HOST_CFG,
+ executable = True,
+ single_file = True,
+ ),
"gen_cc": attr.bool(),
"gen_py": attr.bool(),
"outs": attr.output_list(),
@@ -100,9 +117,10 @@ def cc_proto_library(
deps=[],
cc_libs=[],
include=None,
- protoc="//google/protobuf:protoc",
+ protoc="//:protoc",
internal_bootstrap_hack=False,
- default_runtime="//google/protobuf:protobuf",
+ use_grpc_plugin=False,
+ default_runtime="//:protobuf",
**kargs):
"""Bazel rule to create a C++ protobuf library from proto source files
@@ -122,6 +140,8 @@ def cc_proto_library(
for bootstraping. When it is set to True, no files will be generated.
The rule will simply be a provider for .proto files, so that other
cc_proto_library can depend on it.
+ use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin
+ when processing the proto files.
default_runtime: the implicitly default runtime which will be depended on by
the generated cc_library target.
**kargs: other keyword arguments that are passed to cc_library.
@@ -149,13 +169,19 @@ def cc_proto_library(
**kargs)
return
- outs = _CcOuts(srcs)
+ grpc_cpp_plugin = None
+ if use_grpc_plugin:
+ grpc_cpp_plugin = "//external:grpc_cpp_plugin"
+
+ outs = _CcOuts(srcs, use_grpc_plugin)
+
_proto_gen(
name=name + "_genproto",
srcs=srcs,
deps=[s + "_genproto" for s in deps],
includes=includes,
protoc=protoc,
+ grpc_cpp_plugin=grpc_cpp_plugin,
gen_cc=1,
outs=outs,
visibility=["//visibility:public"],
@@ -163,6 +189,8 @@ def cc_proto_library(
if default_runtime and not default_runtime in cc_libs:
cc_libs += [default_runtime]
+ if use_grpc_plugin:
+ cc_libs += ["//external:grpc_lib"]
native.cc_library(
name=name,
@@ -172,34 +200,28 @@ def cc_proto_library(
**kargs)
-def internal_copied_filegroup(
- name,
- srcs,
- include,
- **kargs):
- """Bazel rule to fix sources file to workaround with python path issues.
+def internal_gen_well_known_protos_java(srcs):
+ """Bazel rule to generate the gen_well_known_protos_java genrule
Args:
- name: the name of the internal_copied_filegroup rule, which will be the
- name of the generated filegroup.
- srcs: the source files to be copied.
- include: the expected import root of the source.
- **kargs: extra arguments that will be passed into the filegroup.
+ srcs: the well known protos
"""
- outs = [_RelativeOutputPath(s, include) for s in srcs]
-
+ root = Label("%s//protobuf_java" % (REPOSITORY_NAME)).workspace_root
+ if root == "":
+ include = " -Isrc "
+ else:
+ include = " -I%s/src " % root
native.genrule(
- name=name+"_genrule",
- srcs=srcs,
- outs=outs,
- cmd=" && ".join(["cp $(location %s) $(location %s)" %
- (s, _RelativeOutputPath(s, include))
- for s in srcs]))
-
- native.filegroup(
- name=name,
- srcs=outs,
- **kargs)
+ name = "gen_well_known_protos_java",
+ srcs = srcs,
+ outs = [
+ "wellknown.srcjar",
+ ],
+ cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
+ " %s $(SRCS) " % include +
+ " && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
+ tools = [":protoc"],
+ )
def py_proto_library(
@@ -209,8 +231,8 @@ def py_proto_library(
py_libs=[],
py_extra_srcs=[],
include=None,
- default_runtime="//google/protobuf:protobuf_python",
- protoc="//google/protobuf:protoc",
+ default_runtime="//:protobuf_python",
+ protoc="//:protoc",
**kargs):
"""Bazel rule to create a Python protobuf library from proto source files
@@ -250,15 +272,6 @@ def py_proto_library(
visibility=["//visibility:public"],
)
- if include != None:
- # Copy the output files to the desired location to make the import work.
- internal_copied_filegroup_name=name + "_internal_copied_filegroup"
- internal_copied_filegroup(
- name=internal_copied_filegroup_name,
- srcs=outs,
- include=include)
- outs=[internal_copied_filegroup_name]
-
if default_runtime and not default_runtime in py_libs + deps:
py_libs += [default_runtime]
@@ -266,6 +279,7 @@ def py_proto_library(
name=name,
srcs=outs+py_extra_srcs,
deps=py_libs+deps,
+ imports=includes,
**kargs)
def internal_protobuf_py_tests(
@@ -282,8 +296,7 @@ def internal_protobuf_py_tests(
"""
for m in modules:
- s = _RelativeOutputPath(
- "python/google/protobuf/internal/%s.py" % m, "python")
+ s = "python/google/protobuf/internal/%s.py" % m
native.py_test(
name="py_%s" % m,
srcs=[s],
« no previous file with comments | « third_party/protobuf/php/tests/autoload.php ('k') | third_party/protobuf/protobuf.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698