Skip to content

Commit

Permalink
Fix bug in _internal_copy_files where the rule would fail in downstre…
Browse files Browse the repository at this point in the history
…am repositories.

Taken from https://github.com/protocolbuffers/upb/blob/main/bazel/protobuf.patch#L42

Fixes #12620.

PiperOrigin-RevId: 528586464
  • Loading branch information
deannagarcia committed May 2, 2023
1 parent ad2dd26 commit b36c392
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions python/internal.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Internal helpers for building the Python protobuf runtime.
"""
Internal helpers for building the Python protobuf runtime.
"""

def _remove_cross_repo_path(path):
components = path.split("/")
if components[0] == "..":
return "/".join(components[2:])
return path

def _internal_copy_files_impl(ctx):
strip_prefix = ctx.attr.strip_prefix
Expand All @@ -7,10 +15,11 @@ def _internal_copy_files_impl(ctx):

src_dests = []
for src in ctx.files.srcs:
if src.short_path[:len(strip_prefix)] != strip_prefix:
short_path = _remove_cross_repo_path(src.short_path)
if short_path[:len(strip_prefix)] != strip_prefix:
fail("Source does not start with %s: %s" %
(strip_prefix, src.short_path))
dest = ctx.actions.declare_file(src.short_path[len(strip_prefix):])
(strip_prefix, short_path))
dest = ctx.actions.declare_file(short_path[len(strip_prefix):])
src_dests.append([src, dest])

if ctx.attr.is_windows:
Expand Down

0 comments on commit b36c392

Please sign in to comment.