Skip to content

Commit 3d52bd5

Browse files
authored
Unzip and untar .conda packages (#297)
* Unzip and untar .conda packages * Have fake SetupSource{ArchiveSource} use hash and target of original * Add tests for conda packages * Optimization: Only extract the pkg tarball of interest * Switch to a smaller conda package
1 parent 64104c9 commit 3d52bd5

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/Prefix.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,19 @@ function setup(source::SetupSource{ArchiveSource}, targetdir, verbose; tar_flags
335335
@info "Extracting zipball $(basename(source.path))..."
336336
end
337337
run(`unzip -q $(source.path)`)
338+
elseif endswith(source.path, ".conda")
339+
if verbose
340+
@info "Extracting conda package $(basename(source.path))..."
341+
end
342+
# The .conda file contains an archive called pkg-*.tar.zst
343+
# Replace initial hash with pkg, and change the file extension to obtain the name
344+
pkg_name = replace(basename(source.path), r"^[a-z0-9]{64}-" => "pkg-", ".conda" => ".tar.zst")
345+
# First unzip the pkg tarball from .conda file
346+
run(`unzip -q $(source.path) $pkg_name`)
347+
# Second untar the pkg tarball
348+
pkg_source = SetupSource{ArchiveSource}(joinpath(targetdir, pkg_name), source.hash, source.target)
349+
# Run setup again to untar the pkg binaries
350+
setup(pkg_source, targetdir, verbose; tar_flags = tar_flags)
338351
else
339352
error("Unknown archive format")
340353
end

src/Sources.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ArchiveSource(url::String, hash::String; unpack_target::String = "") =
6565
const tar_extensions = [".tar", ".tar.gz", ".tgz", ".tar.bz", ".tar.bz2",
6666
".tar.xz", ".tar.Z", ".txz", ".tar.zst"]
6767
# List of general archives that we know about
68-
const archive_extensions = vcat(tar_extensions, ".zip")
68+
const archive_extensions = vcat(tar_extensions, ".zip", ".conda")
6969

7070
"""
7171
FileSource(url::String, hash::String; filename::String = basename(url))

test/sources.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ using JSON
66
@testset "Sources" begin
77
@test ArchiveSource("https://ftp.gnu.org/gnu/wget/wget-1.20.3.tar.gz", "31cccfc6630528db1c8e3a06f6decf2a370060b982841cfab2b8677400a5092e").unpack_target == ""
88
@test ArchiveSource("https://ftp.gnu.org/gnu/wget/wget-1.20.3.tar.gz", "31cccfc6630528db1c8e3a06f6decf2a370060b982841cfab2b8677400a5092e"; unpack_target = "wget").unpack_target == "wget"
9+
@test ArchiveSource("https://anaconda.org/conda-forge/versionparsing.jl/1.3.0/download/noarch/versionparsing.jl-1.3.0-ha770c72_0.conda",
10+
"89156426aacf3e3230644b2d00aa029984da77d36b54b1b9dc022f1e94aa9bf0";
11+
unpack_target="x86_64-linux-gnu").unpack_target == "x86_64-linux-gnu"
912
@test GitSource("https://github.com/jedisct1/libsodium.git", "5b2ea7d73d3ffef2fb93b82b9f112f009d54c6e6").unpack_target == ""
1013
@test GitSource("https://github.com/jedisct1/libsodium.git", "5b2ea7d73d3ffef2fb93b82b9f112f009d54c6e6"; unpack_target = "libs").unpack_target == "libs"
1114
@test FileSource("https://curl.haxx.se/ca/cacert-2020-01-01.pem", "adf770dfd574a0d6026bfaa270cb6879b063957177a991d453ff1d302c02081f").filename == "cacert-2020-01-01.pem"
@@ -30,6 +33,14 @@ using JSON
3033
sas = @test_logs (:info, r"Downloading .* to.*") download_source(as; verbose = true, downloads_dir = dir)
3134
# Check that the cache is found
3235
@test @test_logs (:info, r"Cached file found in .*") download_source(as; verbose = true, downloads_dir = dir) == sas
36+
# Conda archive source
37+
cas = ArchiveSource("https://anaconda.org/conda-forge/hdf5/1.14.0/download/linux-64/hdf5-1.14.0-nompi_h5231ba7_102.conda",
38+
"d64e2e691205920a0d0f15876d4bcade18f98ef126959d21316a297516476c7c";
39+
unpack_target="x86_64-linux-gnu")
40+
# Download the source
41+
scas = @test_logs (:info, r"Downloading .* to.*") download_source(cas; verbose = true, downloads_dir = dir)
42+
# Check that the cache is found
43+
@test @test_logs (:info, r"Cached file found in .*") download_source(cas; verbose = true, downloads_dir = dir) == scas
3344
fs = FileSource("https://github.com/JuliaBinaryWrappers/libcellml_jll.jl/releases/download/libcellml-v0.4.0%2B0/libcellml-logs.v0.4.0.x86_64-w64-mingw32-cxx03.tar.gz", "237013b20851355c4c1d22ceac7e73207b44d989d38b6874187d333adfc79c77"; filename = "file-source.tar.gz")
3445
# Re-fetch the same tarball, as a `FileSource` this time
3546
sfs = @test_logs (:info, r"Cached file found in .*") download_source(fs; verbose = true, downloads_dir = dir)
@@ -73,6 +84,9 @@ using JSON
7384
target = joinpath(srcdir, as.unpack_target)
7485
@test_logs (:info, r"^Extracting tarball") setup(sas, target, true; tar_flags = "xof")
7586
@test isdir(target)
87+
target = joinpath(srcdir, cas.unpack_target)
88+
@test_logs (:info, r"^Extracting conda package") (:info, r"^Extracting tarball") setup(scas, target, true; tar_flags = "xof")
89+
@test isdir(target)
7690
target = joinpath(srcdir, fs.filename)
7791
@test_logs (:info, r"^Copying") setup(sfs, target, true)
7892
@test isfile(target)
@@ -95,7 +109,7 @@ using JSON
95109
@test islink(joinpath(target, "link.patch"))
96110

97111
# Make sure in srcdir there are all files and directories we expect
98-
@test Set(readdir(srcdir)) == Set(["ARCHDefs", "logs", fs.filename, "patches_follow", "patches_nofollow"])
112+
@test Set(readdir(srcdir)) == Set(["ARCHDefs", "logs", "x86_64-linux-gnu", fs.filename, "patches_follow", "patches_nofollow"])
99113

100114
# Setup the sources with `setup_workspace`
101115
workspace = joinpath(dir, "workspace")

0 commit comments

Comments
 (0)