Skip to content

Commit 012f145

Browse files
committed
fix: py_proto_library: external runfiles
Previously, the import path within the runfiles was only correct for the case --legacy_external_runfiles=True (which copied the runfiles into `$RUNFILES/<main repo>/external/<external repo>/<path>` in addition to `$RUNFILES/<external repo>/<path>`. This flag was flipped to False in Bazel 8.0.0. Fixes #2515. Tested locally against the minimal reproducer in that issue.
1 parent 66a8b5b commit 012f145

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Unreleased changes template.
7070
* (pypi) Using {bzl:obj}`pip_parse.experimental_requirement_cycles` and
7171
{bzl:obj}`pip_parse.use_hub_alias_dependencies` together now works when
7272
using WORKSPACE files.
73+
* (py_proto_library) Fix import paths in Bazel 8.
7374

7475
[pep-695]: https://peps.python.org/pep-0695/
7576

python/private/proto/py_proto_library.bzl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@ def _py_proto_aspect_impl(target, ctx):
9898
proto_root = proto_root[len(ctx.bin_dir.path) + 1:]
9999

100100
plugin_output = ctx.bin_dir.path + "/" + proto_root
101-
proto_root = ctx.workspace_name + "/" + proto_root
101+
# Import path within the runfiles tree
102+
if proto_root.startswith('external/'):
103+
proto_import_path = proto_root[len('external') + 1:]
104+
else:
105+
proto_import_path = ctx.workspace_name + "/" + proto_root
106+
102107

103108
proto_common.compile(
104109
actions = ctx.actions,
@@ -130,7 +135,7 @@ def _py_proto_aspect_impl(target, ctx):
130135
# _virtual_imports. But it's undesirable otherwise, because it
131136
# will put the repo root at the top of the PYTHONPATH, ahead of
132137
# directories added through `imports` attributes.
133-
[proto_root] if "_virtual_imports" in proto_root else [],
138+
[proto_import_path] if "_virtual_imports" in proto_import_path else [],
134139
transitive = [dep[PyInfo].imports for dep in api_deps] + [dep.imports for dep in deps],
135140
),
136141
runfiles_from_proto_deps = runfiles_from_proto_deps,

0 commit comments

Comments
 (0)