From e3e3b2aec8fc7ac45f3b8f7d0adfdb7cdce2bd1f Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Tue, 7 Mar 2017 16:12:56 -0800 Subject: changes for picking up well known protos Add dependency and protoc argument for picking up well known protos from the //third_party/protobuf repo --- bazel/generate_cc.bzl | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'bazel/generate_cc.bzl') diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index d49cbe8d72..f3961f0a41 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -31,8 +31,20 @@ def generate_cc_impl(ctx): arguments += ["-I{0}={0}".format(include.path) for include in includes] arguments += [proto.path for proto in protos] + # create a list of well known proto files if the argument is non-None + 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") + else: + # f points to "external/submodule_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] + ctx.action( - inputs = protos + includes + additional_input, + inputs = protos + includes + additional_input + well_known_proto_files, outputs = out_files, executable = ctx.executable._protoc, arguments = arguments, @@ -56,6 +68,9 @@ generate_cc = rule( mandatory = False, allow_empty = True, ), + "well_known_protos" : attr.label( + mandatory = False, + ), "_protoc": attr.label( default = Label("//external:protocol_compiler"), executable = True, -- cgit v1.2.3