Skip to content

Commit

Permalink
fix #697: use to_repository_relative_path in mtree_spec (#696)
Browse files Browse the repository at this point in the history
* Reproduction for mtree_spec behaving different in other repo

* Fix the bug (but not the test)

* Fix the test

* Rename mtree_spec e2e dir to tar

* Fix bzlmod tests

* Remove unnecessary skylib dependency from e2e repos

* Add e2e tests to matrix

* Replace e2e test with a normal test

To do this, we somewhat abuse the skylib dependency, but that's
probalby OK.
  • Loading branch information
gzm0 authored and gregmagolan committed Mar 23, 2024
1 parent 1383167 commit d9c7cb7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/private/tar.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
61 changes: 61 additions & 0 deletions lib/tests/tar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,64 @@ assert_tar_listing(
"-rwxr-xr-x 0 0 0 0 Jan 1 2023 lib/tests/tar/treeartifact/pkg",
],
)

# Case 8: setting owner of files
_SRCS8 = [
":fixture1",
"src_file",
]

mtree_spec(
name = "mtree8",
srcs = _SRCS8,
)

# This is a very simple way to mutate the mtree specification, just using regex.
# See docs on tar about future directions for mtree mutation
genrule(
name = "change_owner",
srcs = ["mtree8"],
outs = ["mtree8.mutated"],
# Modify uid and gid, e.g.
# lib/tests/tar/a uid=0 gid=0 time=1672560000 mode=0755 type=file content=bazel-out/darwin_arm64-opt/bin/lib/tests/tar/a
# ->
# lib/tests/tar/a uid=1000 gid=500 time=1672560000 mode=0755 type=file content=bazel-out/darwin_arm64-opt/bin/lib/tests/tar/a
cmd = "sed 's/uid=0/uid=1000/;s/gid=0/gid=500/' <$< >$@",
)

tar(
name = "tar_change_owner",
srcs = _SRCS8,
out = "8.tar",
mtree = "change_owner",
)

assert_tar_listing(
name = "test_change_owner",
actual = "tar_change_owner",
expected = [
"drwxr-xr-x 0 1000 500 0 Jan 1 2023 lib/",
"drwxr-xr-x 0 1000 500 0 Jan 1 2023 lib/tests/",
"drwxr-xr-x 0 1000 500 0 Jan 1 2023 lib/tests/tar/",
"-rwxr-xr-x 0 1000 500 7 Jan 1 2023 lib/tests/tar/a",
"-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",
],
)

0 comments on commit d9c7cb7

Please sign in to comment.