Make .proto import path computation work with virtual protos in the main repository.

Also fix grammar.
This commit is contained in:
Lukacs T. Berki 2019-07-09 13:41:19 -07:00 committed by Eric Anderson
parent d648e8f2df
commit e341d4c655
1 changed files with 4 additions and 4 deletions

View File

@ -60,11 +60,8 @@ java_rpc_toolchain = rule(
# "repository" here is for Bazel builds that span multiple WORKSPACES. # "repository" here is for Bazel builds that span multiple WORKSPACES.
def _path_ignoring_repository(f): 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 # 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: # need to be 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 # 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 # In that case, the import path of the .proto file is the path relative to
@ -72,6 +69,9 @@ def _path_ignoring_repository(f):
virtual_imports = "/_virtual_imports/" virtual_imports = "/_virtual_imports/"
if virtual_imports in f.path: if virtual_imports in f.path:
return f.path.split(virtual_imports)[1].split("/", 1)[1] return f.path.split(virtual_imports)[1].split("/", 1)[1]
elif len(f.owner.workspace_root) == 0:
# |f| is in the main repository
return f.short_path
else: else:
# If |f| is a generated file, it will have "bazel-out/*/genfiles" prefix # 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" # before "external/workspace", so we need to add the starting index of "external/workspace"