Skip to content

Commit 1a333ce

Browse files
authored
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.
1 parent 89bec57 commit 1a333ce

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

python/private/proto/py_proto_library.bzl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,22 @@ def _py_proto_aspect_impl(target, ctx):
7575
name_mapper = lambda name: name.replace("-", "_").replace(".", "/"),
7676
)
7777

78+
# Handles multiple repository and virtual import cases
79+
proto_root = proto_info.proto_source_root
80+
if proto_root.startswith(ctx.bin_dir.path):
81+
plugin_output = proto_root
82+
else:
83+
plugin_output = ctx.bin_dir.path + "/" + proto_root
84+
85+
if plugin_output == ".":
86+
plugin_output = ctx.bin_dir.path
87+
7888
proto_common.compile(
7989
actions = ctx.actions,
8090
proto_info = proto_info,
8191
proto_lang_toolchain_info = proto_lang_toolchain_info,
8292
generated_files = generated_sources,
83-
plugin_output = ctx.bin_dir.path,
93+
plugin_output = plugin_output,
8494
)
8595

8696
# Generated sources == Python sources

0 commit comments

Comments
 (0)