diff --git a/src/Prefix.jl b/src/Prefix.jl index 1d9e61e4..550ae934 100644 --- a/src/Prefix.jl +++ b/src/Prefix.jl @@ -260,14 +260,16 @@ function setup(source::SetupSource{GitSource}, targetdir, verbose) # Chop off the `.git` at the end of the source.path repo_dir = joinpath(targetdir, basename(source.path)[1:end-4]) if verbose - @info "Cloning $(basename(source.path)) to $(basename(targetdir))..." + # Need to strip the trailing separator + path = isdirpath(targetdir) ? dirname(targetdir) : targetdir + @info "Cloning $(basename(source.path)) to $(basename(repo_dir))..." end LibGit2.with(LibGit2.clone(source.path, repo_dir)) do repo LibGit2.checkout!(repo, source.hash) end end -function setup(source::SetupSource{ArchiveSource}, targetdir, verbose) +function setup(source::SetupSource{ArchiveSource}, targetdir, verbose; tar_flags = verbose ? "xvof" : "xof") mkpath(targetdir) # Extract with host tools because it is _much_ faster on e.g. OSX. # If this becomes a compatibility problem, we'll just have to install @@ -277,7 +279,6 @@ function setup(source::SetupSource{ArchiveSource}, targetdir, verbose) if verbose @info "Extracting tarball $(basename(source.path))..." end - tar_flags = verbose ? "xvof" : "xof" run(`tar -$(tar_flags) $(source.path)`) elseif endswith(source.path, ".zip") if verbose diff --git a/test/prefix.jl b/test/prefix.jl index 7cbe9bc0..bfee0e5a 100644 --- a/test/prefix.jl +++ b/test/prefix.jl @@ -185,7 +185,7 @@ end file = joinpath(dir, "file.txt") file_gz = file * ".gz" write(file, lorem) - compress_dir(dir) + @test_logs (:info, r"Compressing files in") compress_dir(dir; verbose=true) # Check that there is only the compressed file @test readdir(dir) == [basename(file_gz)] # Decompress it diff --git a/test/sources.jl b/test/sources.jl index a2882475..754aa782 100644 --- a/test/sources.jl +++ b/test/sources.jl @@ -1,6 +1,6 @@ using Test using BinaryBuilderBase -using BinaryBuilderBase: coerce_source, sourcify, SetupSource +using BinaryBuilderBase: coerce_source, sourcify, SetupSource, setup using JSON @testset "Sources" begin @@ -16,29 +16,50 @@ using JSON @test SetupSource("https://github.com/jedisct1/libsodium.git", "", "", "") isa SetupSource{GitSource} @test SetupSource("https://curl.haxx.se/ca/cacert-2020-01-01.pem", "", "", "") isa SetupSource{FileSource} - @testset "Download" begin + @testset "Download and setup" begin mktempdir() do dir - as = ArchiveSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff") - # Download the source - if VERSION >= v"1.4" - @test_logs (:info, r"^No hash cache found") (:info, r"Calculated hash") download_source(as; verbose = true, downloads_dir = dir) - else - @test_logs (:info, r"^Downloading") (:info, r"^No hash cache found") (:info, r"Calculated hash") download_source(as; verbose = true, downloads_dir = dir) + cd(dir) do + as = ArchiveSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff") + # Download the source + sas = if VERSION >= v"1.4" + @test_logs (:info, r"^No hash cache found") (:info, r"Calculated hash") download_source(as; verbose = true, downloads_dir = dir) + else + @test_logs (:info, r"^Downloading") (:info, r"^No hash cache found") (:info, r"Calculated hash") download_source(as; verbose = true, downloads_dir = dir) + end + # Check that the cache is found + @test @test_logs (:info, r"^Destination file .* already exists") (:info, r"Hash cache is consistent, returning true") download_source(as; verbose = true, downloads_dir = dir) == sas + fs = FileSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff"; filename = "file-source.tar.gz") + # Re-fetch the same tarball, as a `FileSource` this time + sfs = @test_logs (:info, r"^Destination file .* already exists") (:info, r"Hash cache is consistent, returning true") download_source(fs; verbose = true, downloads_dir = dir) + gs = GitSource("https://github.com/ralna/ARCHDefs.git", "fc8c5960c3a6d26970ab245241cfc067fe4ecfdd") + # Clone the repo once + sgs = @test_logs (:info, r"^Cloning") download_source(gs; verbose = true, downloads_dir = dir) + # Fetch again the repo to make sure cache works + @test @test_logs (:info, r"^Cached repository found in") download_source(gs; verbose = true, downloads_dir = dir) == sgs + # Fetch the temp directory as a `DirectorySource` + ds = DirectorySource("./bundled") + patchdir = abspath(joinpath(dir, ds.path, "patches")) + mkpath(patchdir) + write(abspath(joinpath(patchdir, "fix-windows-headers.patch")), "This is a patch file") + sds = @test_logs (:info, r"^Directory .* found") download_source(ds; verbose = true) + # Try to fetch a non-existing directory + @test_throws ErrorException download_source(DirectorySource(joinpath(dir, "does_not_exist")); verbose = true) + + srcdir = joinpath(dir, "srcdir") + target = joinpath(srcdir, as.unpack_target) + @test_logs (:info, r"^Extracting tarball") setup(sas, target, true; tar_flags = "xof") + @test isdir(target) + target = joinpath(srcdir, fs.filename) + @test_logs (:info, r"^Copying") setup(sfs, target, true) + @test isfile(target) + target = joinpath(srcdir, gs.unpack_target) + @test_logs (:info, "Cloning ARCHDefs.git to ARCHDefs...") setup(sgs, target, true) + @test isdir(target) + target = abspath(joinpath(srcdir, "patches")) + @test_logs (:info, "Copying content of bundled in srcdir...") setup(sds, srcdir, true) + @test isdir(target) + @test Set(readdir(srcdir)) == Set(["ARCHDefs", "ARCHDefs-2.0.3x", fs.filename, "patches"]) end - # Check that the cache is found - @test_logs (:info, r"^Destination file .* already exists") (:info, r"Hash cache is consistent, returning true") download_source(as; verbose = true, downloads_dir = dir) - fs = FileSource("https://github.com/ralna/ARCHDefs/archive/v2.0.3x.tar.gz", "6583e27f84338447767bbdf4335514c8836ae4ad54f5e66280307e8b57189cff") - # Re-fetch the same tarball, as a `FileSource` this time - @test_logs (:info, r"^Destination file .* already exists") (:info, r"Hash cache is consistent, returning true") download_source(fs; verbose = true, downloads_dir = dir) - gs = GitSource("https://github.com/ralna/ARCHDefs", "fc8c5960c3a6d26970ab245241cfc067fe4ecfdd") - # Clone the repo once - @test_logs (:info, r"^Cloning") download_source(gs; verbose = true, downloads_dir = dir) - # Fetch again the repo to make sure cache works - @test_logs (:info, r"^Cached repository found in") download_source(gs; verbose = true, downloads_dir = dir) - # Fetch the temp directory as a `DirectorySource` - @test_logs (:info, r"^Directory .* found") download_source(DirectorySource(dir); verbose = true) - # Try to fetch a non-existing directory - @test_throws ErrorException download_source(DirectorySource(joinpath(dir, "does_not_exist")); verbose = true) end end