aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo List <ilist@google.com>2023-06-20 19:36:39 +0200
committerGitHub <noreply@github.com>2023-06-20 17:36:39 +0000
commit1a333cecd73af9916e89b1e1a33fed73d913eb49 (patch)
treef417768ffac0ef71f3d8014ca2208539d9406857
parent89bec57f443b160433d2c6e15ddd874ba21d2ecd (diff)
downloadbazelbuild-rules_python-1a333cecd73af9916e89b1e1a33fed73d913eb49.tar.gz
fix: plugin_output in py_proto_library rule (#1280)
plugin_output was wrong in case multiple repositories are involved and/or _virtual_imports. The code is taken from `cc_proto_library` and has been verified in practice.
-rw-r--r--python/private/proto/py_proto_library.bzl12
1 files changed, 11 insertions, 1 deletions
diff --git a/python/private/proto/py_proto_library.bzl b/python/private/proto/py_proto_library.bzl
index 9885585..9377c85 100644
--- a/python/private/proto/py_proto_library.bzl
+++ b/python/private/proto/py_proto_library.bzl
@@ -75,12 +75,22 @@ def _py_proto_aspect_impl(target, ctx):
name_mapper = lambda name: name.replace("-", "_").replace(".", "/"),
)
+ # Handles multiple repository and virtual import cases
+ proto_root = proto_info.proto_source_root
+ if proto_root.startswith(ctx.bin_dir.path):
+ plugin_output = proto_root
+ else:
+ plugin_output = ctx.bin_dir.path + "/" + proto_root
+
+ if plugin_output == ".":
+ plugin_output = ctx.bin_dir.path
+
proto_common.compile(
actions = ctx.actions,
proto_info = proto_info,
proto_lang_toolchain_info = proto_lang_toolchain_info,
generated_files = generated_sources,
- plugin_output = ctx.bin_dir.path,
+ plugin_output = plugin_output,
)
# Generated sources == Python sources