Skip to content

Commit

Permalink
working?
Browse files Browse the repository at this point in the history
  • Loading branch information
joshday committed Jan 9, 2024
1 parent 60caded commit 597b4d1
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/DepotDelivery.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@ 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
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)
Expand All @@ -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)
Expand Down

0 comments on commit 597b4d1

Please sign in to comment.