Skip to content

Commit

Permalink
java_grpc_library.bzl: Work with proto_library rules using strip_impo…
Browse files Browse the repository at this point in the history
…rt_prefix / import_prefix

In addition to this welcome functionality, this change also makes it
possible to fix http://github.com/bazelbuild/bazel/issues/7157 by
tolerating proto_library rules using a virtual import directory.
  • Loading branch information
lberki authored and ejona86 committed Jul 8, 2019
1 parent b4e964b commit be57e39
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions java_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ java_rpc_toolchain = rule(
def _path_ignoring_repository(f):
if len(f.owner.workspace_root) == 0:
return f.short_path

# Bazel creates a _virtual_imports directory in case the .proto source files
# need to a accessed at a path that's different from their source path:
# https://github.com/bazelbuild/bazel/blob/0.27.1/src/main/java/com/google/devtools/build/lib/rules/proto/ProtoCommon.java#L289
#
# In that case, the import path of the .proto file is the path relative to
# the virtual imports directory of the rule in question.
virtual_imports = "/_virtual_imports/"
if virtual_imports in f.path:
return f.path.split(virtual_imports)[1].split("/", 1)[1]
else:
# If |f| is a generated file, it will have "bazel-out/*/genfiles" prefix
# before "external/workspace", so we need to add the starting index of "external/workspace"
return f.path[f.path.find(f.owner.workspace_root) + len(f.owner.workspace_root) + 1:]

def _java_rpc_library_impl(ctx):
Expand Down

0 comments on commit be57e39

Please sign in to comment.