aboutsummaryrefslogtreecommitdiff
path: root/python/private/proto/py_proto_library.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'python/private/proto/py_proto_library.bzl')
-rw-r--r--python/private/proto/py_proto_library.bzl19
1 files changed, 12 insertions, 7 deletions
diff --git a/python/private/proto/py_proto_library.bzl b/python/private/proto/py_proto_library.bzl
index 9377c85..91faa2d 100644
--- a/python/private/proto/py_proto_library.bzl
+++ b/python/private/proto/py_proto_library.bzl
@@ -66,6 +66,7 @@ def _py_proto_aspect_impl(target, ctx):
generated_sources = []
proto_info = target[ProtoInfo]
+ proto_root = proto_info.proto_source_root
if proto_info.direct_sources:
# Generate py files
generated_sources = proto_common.declare_generated_files(
@@ -76,14 +77,11 @@ def _py_proto_aspect_impl(target, ctx):
)
# 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
+ proto_root = proto_root[len(ctx.bin_dir.path) + 1:]
- if plugin_output == ".":
- plugin_output = ctx.bin_dir.path
+ plugin_output = ctx.bin_dir.path + "/" + proto_root
+ proto_root = ctx.workspace_name + "/" + proto_root
proto_common.compile(
actions = ctx.actions,
@@ -109,7 +107,14 @@ def _py_proto_aspect_impl(target, ctx):
return [
_PyProtoInfo(
imports = depset(
- transitive = [dep[PyInfo].imports for dep in api_deps],
+ # Adding to PYTHONPATH so the generated modules can be
+ # imported. This is necessary when there is
+ # strip_import_prefix, the Python modules are generated under
+ # _virtual_imports. But it's undesirable otherwise, because it
+ # will put the repo root at the top of the PYTHONPATH, ahead of
+ # directories added through `imports` attributes.
+ [proto_root] if "_virtual_imports" in proto_root else [],
+ transitive = [dep[PyInfo].imports for dep in api_deps] + [dep.imports for dep in deps],
),
runfiles_from_proto_deps = runfiles_from_proto_deps,
transitive_sources = transitive_sources,