aboutsummaryrefslogtreecommitdiffhomepage
path: root/bazel
diff options
context:
space:
mode:
authorGravatar Ian Sturdy <sturdy@google.com>2018-03-19 16:12:45 -0700
committerGravatar Ian Sturdy <sturdy@google.com>2018-03-19 16:12:45 -0700
commite6dfa9cd74fe7fa187072b362719d2a1ba386e3e (patch)
tree698bad57be647d8c715fb3a2b1a9cba7fec77a2d /bazel
parent3a8c0d6a192cc969d9f9e5d72a968251d93459a7 (diff)
Fix cross-repository proto includes.
Diffstat (limited to 'bazel')
-rw-r--r--bazel/generate_cc.bzl17
1 files changed, 13 insertions, 4 deletions
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]