From e6dfa9cd74fe7fa187072b362719d2a1ba386e3e Mon Sep 17 00:00:00 2001 From: Ian Sturdy Date: Mon, 19 Mar 2018 16:12:45 -0700 Subject: Fix cross-repository proto includes. --- bazel/generate_cc.bzl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'bazel') diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index 11affaa4c7..96610d873e 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -42,10 +42,19 @@ def generate_cc_impl(ctx): else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] additional_input = [] - # Import protos relative to the workspace root so that protoc prints the right - # include paths. - arguments += ["--proto_path=" + (ctx.label.workspace_root or ".")] - # A second include so that protoc puts the generated code in the right directory. + + # Import protos relative to their workspace root so that protoc prints the + # right include paths. + for include in includes: + directory = include.path + if directory.startswith("external"): + external_sep = directory.find("/") + repository_sep = directory.find("/", external_sep + 1) + arguments += ["--proto_path=" + directory[:repository_sep]] + else: + arguments += ["--proto_path=."] + # Include the output directory so that protoc puts the generated code in the + # right directory. arguments += ["--proto_path={0}{1}".format(dir_out, proto_root)] arguments += [proto.path for proto in protos] -- cgit v1.2.3