diff --git a/lib/private/tar.bzl b/lib/private/tar.bzl index 707d17a..f8157cd 100644 --- a/lib/private/tar.bzl +++ b/lib/private/tar.bzl @@ -1,5 +1,7 @@ "Implementation of tar rule" +load("//lib:paths.bzl", "to_repository_relative_path") + TAR_TOOLCHAIN_TYPE = "@aspect_bazel_lib//lib:tar_toolchain_type" # https://www.gnu.org/software/tar/manual/html_section/Compression.html @@ -182,7 +184,7 @@ def _to_rlocation_path(file, workspace): else: return workspace + "/" + file.short_path -def _expand(file, expander, transform = lambda f: f.short_path): +def _expand(file, expander, transform = to_repository_relative_path): expanded = expander.expand(file) lines = [] for e in expanded: diff --git a/lib/tests/tar/BUILD.bazel b/lib/tests/tar/BUILD.bazel index 1325a41..1352eb2 100644 --- a/lib/tests/tar/BUILD.bazel +++ b/lib/tests/tar/BUILD.bazel @@ -279,3 +279,21 @@ assert_tar_listing( "-rwxr-xr-x 0 1000 500 21 Jan 1 2023 lib/tests/tar/src_file", ], ) + +# Case 9: Files from a different repository (#697) +# Note: This test uses an exported file from skylib, so we do not need to create +# an additional workspace just for this test. + +tar( + name = "tar_different_repo", + srcs = ["@bazel_skylib//:LICENSE"], + out = "9.tar", +) + +assert_archive_contains( + name = "test_different_repo", + archive = "9.tar", + expected = [ + "LICENSE", + ], +)