Skip to content

Commit 859410b

Browse files
deannagarciacopybara-github
authored andcommitted
Fix bug in _internal_copy_files where the rule would fail in downstream repositories.
Taken from https://github.com/protocolbuffers/upb/blob/main/bazel/protobuf.patch#L42 Fixes #12620. PiperOrigin-RevId: 528586464
1 parent 6be2818 commit 859410b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

python/internal.bzl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
# Internal helpers for building the Python protobuf runtime.
1+
"""
2+
Internal helpers for building the Python protobuf runtime.
3+
"""
4+
5+
def _remove_cross_repo_path(path):
6+
components = path.split("/")
7+
if components[0] == "..":
8+
return "/".join(components[2:])
9+
return path
210

311
def _internal_copy_files_impl(ctx):
412
strip_prefix = ctx.attr.strip_prefix
@@ -7,10 +15,11 @@ def _internal_copy_files_impl(ctx):
715

816
src_dests = []
917
for src in ctx.files.srcs:
10-
if src.short_path[:len(strip_prefix)] != strip_prefix:
18+
short_path = _remove_cross_repo_path(src.short_path)
19+
if short_path[:len(strip_prefix)] != strip_prefix:
1120
fail("Source does not start with %s: %s" %
12-
(strip_prefix, src.short_path))
13-
dest = ctx.actions.declare_file(src.short_path[len(strip_prefix):])
21+
(strip_prefix, short_path))
22+
dest = ctx.actions.declare_file(short_path[len(strip_prefix):])
1423
src_dests.append([src, dest])
1524

1625
if ctx.attr.is_windows:

0 commit comments

Comments
 (0)