8000 fix: add package_dir compatibility test by alexeagle · Pull Request #5 · bazel-contrib/tar.bzl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: add package_dir compatibility test #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions examples/migrate-rules_pkg/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,48 @@ filegroup(
srcs = ["index.html"],
)

######### strip_prefix, mode, and mtime ##################
pkg_tar(
name = "old",
name = "old1",
srcs = [":static"],
mode = "0755",
)

# -> change to ->
tar(
name = "new",
name = "new1",
srcs = [":static"],
mutate = mutate(
mtime = 946699200,
strip_prefix = package_name(),
),
)

assert_tars_match(
name = "test",
actual = "new",
expected = "old",
########### package_dir ################
pkg_tar(
name = "old2",
srcs = [":static"],
mode = "0755",
package_dir = "/usr/share/nginx/html",
)

# -> change to ->
tar(
name = "new2",
srcs = [":static"],
mutate = mutate(
mtime = 946699200,
package_dir = "/usr/share/nginx/html",
strip_prefix = package_name(),
),
)

########## TEST #################
[
assert_tars_match(
name = "test%s" % i,
actual = "new%s" % i,
expected = "old%s" % i,
)
for i in range(1, 3)
]
20 changes: 20 additions & 0 deletions tar/private/modify_mtree.awk
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ function make_relative_link(path1, path2, i, common, target, relative_path, back
}
}

# Chosen to match rules_pkg
default_time = 946699200
if (mtime != "") {
sub(/time=[0-9\.]+/, "time=" mtime);
default_time = mtime
}

if (owner != "") {
Expand All @@ -96,6 +99,23 @@ function make_relative_link(path1, path2, i, common, target, relative_path, back
}

if (package_dir != "") {
# First ensure parent directories exist
if (!($0 ~ /type=dir/)) {
split(package_dir, dirs, "/")
path = ""
for (i = 1; i <= length(dirs); i++) {
if (path == "") {
path = dirs[i]
} else {
path = path "/" dirs[i]
}
# Only print if we haven't seen this directory before
if (!(path in seen_dirs)) {
print path " type=dir mode=0755 time=" default_time
seen_dirs[path] = 1
}
}
}
sub(/^/, package_dir "/")
}
if (preserve_symlinks != "") {
Expand Down
2 changes: 1 addition & 1 deletion tar/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def _mtree_mutate_impl(ctx):
if ctx.attr.strip_prefix:
args.add("-v strip_prefix={}".format(ctx.attr.strip_prefix))
if ctx.attr.package_dir:
args.add("-v package_dir={}".format(ctx.attr.package_dir))
args.add("-v package_dir={}".format(ctx.attr.package_dir.lstrip("/")))
if ctx.attr.mtime:
args.add("-v mtime={}".format(ctx.attr.mtime))
if ctx.attr.preserve_symlinks:
Expand Down
1 change: 1 addition & 0 deletions tar/tests/expected1.mtree
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test type=dir mode=0755 time=946699200
test/xattr.go type=file mode=0664 size=984 uid=1000 gid=1000 uname=vbatts gname=vbatts time=1512774394.470900767 sha512256digest=a2700b603df30c3b0a91bdcf9045e64aea42f62647b0128ea154f51a0c48991e
test/xattr_test.go type=file mode=0664 size=859 uid=1000 gid=1000 uname=vbatts gname=vbatts time=1512774394.470900767 sha512256digest=91294ea554801b75f6a9e33c268807c9620b531eb813ea24512dd4eeaf0592e4
test/xattr_unsupported.go type=file mode=0664 size=509 uid=1000 gid=1000 uname=vbatts gname=vbatts time=1512774394.470900767 sha512256digest=81ced06a1cdf88c4936d10bbf8d46edc2d42dc26efeed3691ddbeeb469865f8a
Expand Down
Loading
0