py_proto_library: fix for --legacy_external_runfiles=True

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.

This is identical to the change made to rules_python in https://github.com/bazelbuild/rules_python/pull/2516.

Work towards https://github.com/bazelbuild/rules_python/pull/2581.

PiperOrigin-RevId: 722690855
pull/20193/head
Protobuf Team Bot 3 weeks ago committed by Copybara-Service
parent dbd5a1e746
commit 2e2a8653c8
  1. 7
      bazel/py_proto_library.bzl

@ -76,7 +76,12 @@ def _py_proto_aspect_impl(target, ctx):
proto_root = proto_root[len(ctx.bin_dir.path) + 1:]
plugin_output = ctx.bin_dir.path + "/" + proto_root
proto_root = ctx.workspace_name + "/" + proto_root
# Import path within the runfiles tree
if proto_root.startswith("external/"):
proto_root = proto_root[len("external") + 1:]
else:
proto_root = ctx.workspace_name + "/" + proto_root
proto_common.compile(
actions = ctx.actions,

Loading…
Cancel
Save