bazelbuild / bazelbuild/rules_pkg

question about file ordering in pkg_tar

Open
#828 9 comments 0 reactions 0 assignees View on GitHub
feature-request p4
Dominant language
Starlark
Stars
253
Forks
221
Avg merge
10h 33m
Merged PRs (30d)
1

Description

I'm wondering about the file order in `pkg_tar`. When I create a normal tar file via the linux command line the order of files in the tar is like specified on the command line:
```
touch {a,b}.txt; tar -cvf test.tar {b,a}.txt; tar -tvf test.tar
# output
-rw-rw-r-- luke/luke 0 2024-03-07 08:29 b.txt
-rw-rw-r-- luke/luke 0 2024-03-07 08:29 a.txt
```

However if I do something similar with rules_pkg this doesn't apply:
```
# BUILD.bazel
load("@rules_pkg//:pkg.bzl", "pkg_tar")
pkg_tar(name = "a")
pkg_tar(name = "b")
pkg_tar(
name = "test",
srcs = [":b", ":a"],
)

# building and testing:
bazel build //:test; tar -tvf bazel-bin/test.tar
-r-xr-xr-x 0/0 10240 2000-01-01 01:00 a.tar
-r-xr-xr-x 0/0 10240 2000-01-01 01:00 b.tar
```

Is there any way to make this ordered the same as the srcs are specified?

One workaround I found is to pack a and b into an extra tar and then specify via deps:
```
pkg_tar(name = "a")
pkg_tar(name = "b")
pkg_tar(name = "a_tar", srcs = ["a"])
pkg_tar(name = "b_tar", srcs = ["b"])
pkg_tar(
name = "test2",
deps = [":b_tar", ":a_tar"],
)

# building and testing:
bazel build //:test2; tar -tvf bazel-bin/test2.tar
-r-xr-xr-x 0/0 10240 2000-01-01 01:00 b.tar
-r-xr-xr-x 0/0 10240 2000-01-01 01:00 a.tar
```
however this seems a bit cumbersome.

I assume the order gets lost here when we assign to the map https://github.com/bazelbuild/rules_pkg/blob/61132feb47add139967476401baa49cf4b7c6b2a/pkg/private/pkg_files.bzl#L493
?

is that the expected/desired behavior?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.