|
| 1 | +using BinaryBuilderBase: archive_artifact, package |
| 2 | +using Pkg.Artifacts: create_artifact, remove_artifact, with_artifacts_directory |
| 3 | +using Pkg: PlatformEngines |
| 4 | + |
| 5 | +@testset "Archive Utils" begin |
| 6 | + @testset "package" begin |
| 7 | + mktempdir() do prefix |
| 8 | + # Create random files |
| 9 | + mkpath(joinpath(prefix, "bin")) |
| 10 | + mkpath(joinpath(prefix, "lib")) |
| 11 | + mkpath(joinpath(prefix, "etc")) |
| 12 | + bar_path = joinpath(prefix, "bin", "bar.sh") |
| 13 | + open(bar_path, "w") do f |
| 14 | + write(f, "#!/bin/sh\n") |
| 15 | + write(f, "echo yolo\n") |
| 16 | + end |
| 17 | + baz_path = joinpath(prefix, "lib", "baz.so") |
| 18 | + open(baz_path, "w") do f |
| 19 | + write(f, "this is not an actual .so\n") |
| 20 | + end |
| 21 | + |
| 22 | + qux_path = joinpath(prefix, "etc", "qux.conf") |
| 23 | + open(qux_path, "w") do f |
| 24 | + write(f, "use_julia=true\n") |
| 25 | + end |
| 26 | + |
| 27 | + mktempdir() do output_dir |
| 28 | + for (format, ext) in [("gzip", "gz"), ("xz", "xz")] |
| 29 | + tarball_path = joinpath(output_dir, "foo.tar.$ext") |
| 30 | + package(prefix, tarball_path; format=format) |
| 31 | + @test isfile(tarball_path) |
| 32 | + |
| 33 | + # Test that we can inspect the contents of the tarball |
| 34 | + contents = PlatformEngines.list_tarball_files(tarball_path) |
| 35 | + @test "bin/bar.sh" in contents |
| 36 | + @test "lib/baz.so" in contents |
| 37 | + @test "etc/qux.conf" in contents |
| 38 | + end |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + @testset "Artifact archival" begin |
| 44 | + mktempdir() do art_dir |
| 45 | + with_artifacts_directory(art_dir) do |
| 46 | + hash = create_artifact(p -> touch(joinpath(p, "foo"))) |
| 47 | + tarball_path = joinpath(art_dir, "foo.tar.gz") |
| 48 | + archive_artifact(hash, tarball_path) |
| 49 | + @test "foo" in PlatformEngines.list_tarball_files(tarball_path) |
| 50 | + rm(tarball_path) |
| 51 | + |
| 52 | + # Test custom `package` function and ensure failure if no `tarball_path` file |
| 53 | + # is created. |
| 54 | + package_alt(src_dir, tarball_path) = nothing |
| 55 | + @test !isfile(tarball_path) |
| 56 | + @test_throws SystemError archive_artifact(hash, tarball_path, package=package_alt) |
| 57 | + |
| 58 | + # Test archiving something that doesn't exist fails |
| 59 | + remove_artifact(hash) |
| 60 | + @test_throws ErrorException archive_artifact(hash, tarball_path) |
| 61 | + end |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments