Skip to content

Commit eaf22a1

Browse files
authored
[ArchiveUtils] Make tarballs compressed with pigz reproducible (#270)
* [ArchiveUtils] Make tarballs compressed with `pigz` reproducible * Do not run reproducibility test with p7zip/xz * [ArchiveUtils] Pass also `--no-name` to pigz
1 parent ba7f4cd commit eaf22a1

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BinaryBuilderBase"
22
uuid = "7f725544-6523-48cd-82d1-3fa08ff4056e"
33
authors = ["Elliot Saba <[email protected]>"]
4-
version = "1.15.0"
4+
version = "1.16.0"
55

66
[deps]
77
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"

src/ArchiveUtils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function package(src_dir::AbstractString, tarball_path::AbstractString;
169169
# Note: For compressing gzip files we use pigz since it uses threading where as p7zip
170170
# does not.
171171
compress_cmd = if format == "gzip"
172-
pipeline(`$(pigz()) -9`, stdout=tarball_path)
172+
pipeline(`$(pigz()) --no-time --no-name -9`, stdout=tarball_path)
173173
else
174174
pipeline(`$(p7zip()) a -si -t$format -mx9 $tarball_path`, stdout=devnull)
175175
end

test/archive_utils.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BinaryBuilderBase: Prefix, archive_artifact, package, list_tarball_files
22
using Pkg.Artifacts: create_artifact, remove_artifact, with_artifacts_directory
3+
using SHA
34
using Test
45

56
@testset "Archive Utils" begin
@@ -25,11 +26,22 @@ using Test
2526
end
2627

2728
mktempdir() do output_dir
28-
for (format, ext) in [("gzip", "gz"), ("xz", "xz")]
29+
for (format, ext, hash) in (("gzip", "gz", "568f743e965b63d3187b6a2647700a71d1d7520b4596fbf2bfb39ffa67c4bb55"),
30+
# Compressing with p7zip/xz doesn't seem to be fully reproducible, at least not
31+
# across different systems. We'll try to investigate more, but for the time being
32+
# skip the reproducibility test for it.
33+
("xz", "xz", ""))
2934
tarball_path = joinpath(output_dir, "foo.tar.$ext")
3035
package(prefix, tarball_path; format=format)
3136
@test isfile(tarball_path)
3237

38+
if !isempty(hash)
39+
tarball_hash = open(tarball_path, "r") do io
40+
bytes2hex(sha256(io))
41+
end
42+
@test tarball_hash == hash
43+
end
44+
3345
# Test that we can inspect the contents of the tarball
3446
contents = list_tarball_files(tarball_path)
3547
@test "bin/bar.sh" in contents
@@ -52,7 +64,8 @@ using Test
5264

5365
# Create an artifact containing the full source directory
5466
mktempdir() do output_dir
55-
tarball, _, tree_hash = package(Prefix(src_dir), joinpath(output_dir, lib), v"1.2.3")
67+
tarball, tarball_hash, tree_hash = package(Prefix(src_dir), joinpath(output_dir, lib), v"1.2.3")
68+
@test tarball_hash == "46abbba8bf97315ecf3d979fb1c95e2e1a639ab71d8d569736e68e6a2ab4a427"
5669
@test tree_hash == Base.SHA1("b316cc5e582cbd503b2da34bd1b79aaf3941ad80")
5770
contents = list_tarball_files(tarball)
5871
@test libname contents
@@ -61,7 +74,8 @@ using Test
6174

6275
# Create an artifact containing *only* the log file logs/libfoo.gz
6376
mktempdir() do output_dir
64-
tarball, _, tree_hash = package(Prefix(src_dir), joinpath(output_dir, lib), v"1.2.3"; filter=(_, f) -> f == "logs")
77+
tarball, tarball_hash, tree_hash = package(Prefix(src_dir), joinpath(output_dir, lib), v"1.2.3"; filter=(_, f) -> f == "logs")
78+
@test tarball_hash == "6b51bcbed720e98d5eaef43a0b10d5b08e11ff05d05fe3ca9525686871767c4c"
6579
@test tree_hash == Base.SHA1("3a3ccf24312676bdd8c2ec769232dbd3bd1b9857")
6680
contents = list_tarball_files(tarball)
6781
@test libname contents
@@ -77,7 +91,7 @@ using Test
7791
with_artifacts_directory(art_dir) do
7892
hash = create_artifact(p -> touch(joinpath(p, "foo")))
7993
tarball_path = joinpath(art_dir, "foo.tar.gz")
80-
archive_artifact(hash, tarball_path)
94+
@test archive_artifact(hash, tarball_path) == "59f35d4bde88850c3e80d6890770902ca6e9e6c3a3b3e9343df686a7b28e89b0"
8195
@test "foo" in list_tarball_files(tarball_path)
8296
rm(tarball_path)
8397

0 commit comments

Comments
 (0)