Skip to content

Commit 081355e

Browse files
authored
[Prefix] Support user-supplied compression format for the tarball (#431)
1 parent eea82df commit 081355e

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
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 <staticfloat@gmail.com>"]
4-
version = "1.38.0"
4+
version = "1.39.0"
55

66
[deps]
77
Bzip2_jll = "6e34b625-4abd-537c-b88f-471c36dfa7a0"

src/ArchiveUtils.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Base: SHA1
22
using Downloads, Tar, p7zip_jll, pigz_jll, SimpleBufferStream, SHA
33
using Pkg.Artifacts: artifact_exists, artifact_path, query_override
4+
using XZ_jll: xz
45

56
export unpack, list_tarball_files, verify, download_verify
67

@@ -146,14 +147,16 @@ end
146147
# function
147148
function archive_artifact(hash::SHA1, tarball_path::String;
148149
honor_overrides::Bool=false,
149-
package::Function=package)
150+
package::Function=package,
151+
compression_format::String="gzip",
152+
)
150153

151154
if !artifact_exists(hash)
152155
error("Unable to archive artifact $(bytes2hex(hash.bytes)): does not exist!")
153156
end
154157

155158
# Package it up
156-
package(artifact_path(hash), tarball_path)
159+
package(artifact_path(hash), tarball_path; format=compression_format)
157160

158161
# Calculate its sha256 and return that
159162
return open(tarball_path, "r") do io
@@ -170,6 +173,8 @@ function package(src_dir::AbstractString, tarball_path::AbstractString;
170173
# does not.
171174
compress_cmd = if format == "gzip"
172175
pipeline(`$(pigz()) --no-time --no-name -9`, stdout=tarball_path)
176+
elseif format == "xz"
177+
pipeline(`$(xz()) -T0 -9`; stdout=tarball_path)
173178
else
174179
pipeline(`$(p7zip()) a -si -t$format -mx9 $tarball_path`, stdout=devnull)
175180
end

src/Prefix.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ end
122122
version::VersionNumber;
123123
platform::AbstractPlatform = HostPlatform(),
124124
verbose::Bool = false, force::Bool = false,
125-
filter = Returns(true))
125+
filter = Returns(true),
126+
compression_format::String = "gzip",
127+
)
126128
127129
Build a tarball of the `prefix`, storing the tarball at `output_base`, appending the version
128130
number `version`, a platform-dependent suffix and a file extension. If `platform` is not
@@ -137,7 +139,8 @@ The are additional keyword arguments:
137139
should be packaged, and `false` otherwise. The arguments are `(prefix, path)`, where
138140
`prefix` is the directory where the prefix is stored, and `path` is the path, within the
139141
prefix, of the file or directory. This keyword allows you to filter out from the tarball
140-
certain files or directories.
142+
certain files or directories
143+
* `compression_format` specifies the compression format used for the tarball.
141144
"""
142145
function package(prefix::Prefix,
143146
output_base::AbstractString,
@@ -146,9 +149,19 @@ function package(prefix::Prefix,
146149
verbose::Bool = false,
147150
force::Bool = false,
148151
filter = Returns(true),
152+
compression_format::String = "gzip",
149153
)
150154
# Calculate output path
151-
out_path = "$(output_base).v$(version).$(triplet(platform)).tar.gz"
155+
extension = if compression_format == "gzip"
156+
"gz"
157+
elseif compression_format == "xz"
158+
"xz"
159+
elseif compression_format == "bzip2"
160+
"bz2"
161+
else
162+
error("Unsupported compression format $(compression_format)")
163+
end
164+
out_path = "$(output_base).v$(version).$(triplet(platform)).tar.$(extension)"
152165

153166
if isfile(out_path)
154167
if force

test/archive_utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ using Test
9797

9898
# Test custom `package` function and ensure failure if no `tarball_path` file
9999
# is created.
100-
package_alt(src_dir, tarball_path) = nothing
100+
package_alt(src_dir, tarball_path; format=nothing) = nothing
101101
@test !isfile(tarball_path)
102102
@test_throws SystemError archive_artifact(hash, tarball_path, package=package_alt)
103103

test/prefix.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,25 @@ end
6969
write(f, "use_julia=true\n")
7070
end
7171

72-
# Next, package it up as a .tar.gz file
73-
tarball_path, tarball_hash = @test_logs (:info, r"^Tree hash of contents of") (:info, r"^SHA256 of") begin
74-
package(prefix, "./libfoo", v"1.0.0"; verbose=true)
72+
for compression_format in ("gzip", "xz", "bzip2")
73+
# Next, package it up as a tarball
74+
tarball_path, tarball_hash = @test_logs (:info, r"^Tree hash of contents of") (:info, r"^SHA256 of") begin
75+
package(prefix, "./libfoo", v"1.0.0"; verbose=true, compression_format)
76+
end
77+
@test isfile(tarball_path)
78+
79+
# Check that we are calculating the hash properly
80+
tarball_hash_check = open(tarball_path, "r") do f
81+
bytes2hex(sha256(f))
82+
end
83+
@test tarball_hash_check == tarball_hash
7584
end
76-
@test isfile(tarball_path)
77-
78-
# Check that we are calculating the hash properly
79-
tarball_hash_check = open(tarball_path, "r") do f
80-
bytes2hex(sha256(f))
81-
end
82-
@test tarball_hash_check == tarball_hash
8385

8486
# Test that packaging into a file that already exists fails
8587
@test_throws ErrorException package(prefix, "./libfoo", v"1.0.0")
88+
89+
# Test error path with unsupported compression format
90+
@test_throws ErrorException package(prefix, "./libfoo-new", v"1.0.0"; compression_format="unknown")
8691
end
8792

8893
# Test that we can inspect the contents of the tarball

0 commit comments

Comments
 (0)