diff --git a/src/DepotDelivery.jl b/src/DepotDelivery.jl index e02b82d..287e5b4 100644 --- a/src/DepotDelivery.jl +++ b/src/DepotDelivery.jl @@ -2,14 +2,15 @@ module DepotDelivery using Dates, GZip, Pkg, Scratch, Tar +export BuildSpec, build, clear! #-----------------------------------------------------------------------------# __init__ RELEASES::String = "" # default directory to place releases: /RELEASES/$(proj.uuid)/$platform/$predicate.tar DEPOTS::String = "" # default directory to reuse as a depot function __init__() - release_dir = @get_scratch!("RELEASES") - depot_dir = @get_scratch!("DEPOTS") + global RELEASES = @get_scratch!("RELEASES") + global DEPOTS = @get_scratch!("DEPOTS") end #-----------------------------------------------------------------------------# utils @@ -17,12 +18,12 @@ clear!() = clear_scratch!(DepotDelivery) default_drop_patterns = (".git", ".gitignore") -default_predicate(path) = !any(path -> occursin(path, default_drop_patterns), path) +default_predicate(path) = !any(x -> occursin(x, path), default_drop_patterns) #-----------------------------------------------------------------------------# BuildSpec Base.@kwdef struct BuildSpec project_file::String = Base.current_project() - platforms::Vector{Base.BinaryPlatforms.Platform} = [Base.BinaryPlatforms.HostPlatform()] + platforms::Dict{String, Base.BinaryPlatforms.AbstractPlatform} = Dict("host" => Base.BinaryPlatforms.HostPlatform()) tar_predicates::Dict{String, Function} = Dict("default" => default_predicate) end function Base.show(io::IO, b::BuildSpec) @@ -43,20 +44,25 @@ function build(b::BuildSpec) # Load Project.toml proj = Pkg.Types.read_project(b.project_file) + depot = joinpath(DEPOTS, string(proj.uuid)) + releases = joinpath(RELEASES, string(proj.uuid)) - out = Dict{String, String}() + out = Dict{String, Dict{String, String}}(name => Dict{String, String}() for name in keys(b.platforms)) try - for platform in b.platforms - push!(empty!(DEPOT_PATH), DEPOT) + for (platform_name, platform) in pairs(b.platforms) + push!(empty!(DEPOT_PATH), depot) Pkg.instantiate(; platform) - for (predicate_name, predicate) in b.predicates + for (predicate_name, predicate) in b.tar_predicates @info "Creating tarball for platform `$platform` with predicate `$predicate_name`" - path = joinpath(RELEASES, proj.uuid, platform, predicate_name * ".tar") - Tar.create(predicate, DEPOT, path; portable=true) - out["$(proj.uuid) | $platform | $predicate_name"] = path + path = joinpath(releases, platform_name, predicate_name * ".tar") + mkpath(dirname(path)) + Tar.create(predicate, depot, path; portable=true) + out[platform_name][predicate_name] = path end end - catch + catch ex + @warn "An error occured while building tarballs." + rethrow(ex) finally isnothing(_precomp_auto) || (ENV["JULIA_PKG_PRECOMPILE_AUTO"] = _precomp_auto) append!(empty!(DEPOT_PATH), _depot_path)