Skip to content

Commit

Permalink
use Pkg protocol to get artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Oct 12, 2019
1 parent 6c9518c commit ebccb80
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
18 changes: 16 additions & 2 deletions src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ..GitTools
using ..BinaryPlatforms
import ..TOML
import ..Types: parse_toml, write_env_usage
import ...Pkg: pkg_server
using ..PlatformEngines
using SHA

Expand Down Expand Up @@ -667,8 +668,12 @@ end
Download/install an artifact into the artifact store. Returns `true` on success.
"""
function download_artifact(tree_hash::SHA1, tarball_url::String, tarball_hash::String;
verbose::Bool = false)
function download_artifact(
tree_hash::SHA1,
tarball_url::String,
tarball_hash::Union{String, Nothing} = nothing;
verbose::Bool = false,
)
if artifact_exists(tree_hash)
return true
end
Expand Down Expand Up @@ -791,6 +796,15 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
hash = SHA1(meta["git-tree-sha1"])

if !artifact_exists(hash)
# first try downloading from Pkg server
# TODO: only do this if Pkg server knows about this package
if (server = pkg_server()) !== nothing
url = "$server/artifact/$hash"
if download_artifact(hash, url)
return artifact_path(hash)
end
end

# If this artifact does not exist on-disk already, ensure it has download
# information, then download it!
if !haskey(meta, "download")
Expand Down
9 changes: 2 additions & 7 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ using ..Types, ..Resolve, ..PlatformEngines, ..GitTools, ..Display
import ..depots, ..depots1, ..devdir, ..set_readonly, ..Types.uuid_julia, ..Types.PackageEntry
import ..Artifacts: ensure_all_artifacts_installed, artifact_names
using ..BinaryPlatforms
import ..Pkg

import ...Pkg
import ...Pkg: pkg_server

#########
# Utils #
Expand Down Expand Up @@ -451,11 +451,6 @@ end
# Package installation #
########################

function pkg_server()
server = get(ENV, "JULIA_PKG_SERVER", "127.0.0.1")
return isempty(server) ? nothing : "http://$server:8000"
end

function get_archive_url_for_version(url::String, ref)
if (m = match(r"https://github.com/(.*?)/(.*?).git", url)) != nothing
return "https://api.github.com/repos/$(m.captures[1])/$(m.captures[2])/tarball/$(ref)"
Expand Down
5 changes: 5 additions & 0 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function depots1()
return d[1]
end

function pkg_server()
server = get(ENV, "JULIA_PKG_SERVER", "127.0.0.1")
return isempty(server) ? nothing : "http://$server:8000"
end

logdir(depot = depots1()) = joinpath(depot, "logs")
devdir(depot = depots1()) = get(ENV, "JULIA_PKG_DEVDIR", joinpath(depots1(), "dev"))
envdir(depot = depots1()) = joinpath(depot, "environments")
Expand Down
14 changes: 7 additions & 7 deletions src/PlatformEngines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ function download(url::AbstractString, dest::AbstractString;
end

"""
download_verify(url::AbstractString, hash::AbstractString,
download_verify(url::AbstractString, hash::Union{AbstractString, Nothing},
dest::AbstractString; verbose::Bool = false,
force::Bool = false, quiet_download::Bool = false)
Expand All @@ -609,7 +609,7 @@ set to `false`) the downloading process will be completely silent. If
`verbose` is set to `true`, messages about integrity verification will be
printed in addition to messages regarding downloading.
"""
function download_verify(url::AbstractString, hash::AbstractString,
function download_verify(url::AbstractString, hash::Union{AbstractString, Nothing},
dest::AbstractString; verbose::Bool = false,
force::Bool = false, quiet_download::Bool = true)
# Whether the file existed in the first place
Expand All @@ -623,7 +623,7 @@ function download_verify(url::AbstractString, hash::AbstractString,

# verify download, if it passes, return happy. If it fails, (and
# `force` is `true`, re-download!)
if verify(dest, hash; verbose=verbose)
if hash !== nothing && verify(dest, hash; verbose=verbose)
return true
elseif !force
error("Verification failed, not overwriting $(dest)")
Expand All @@ -635,7 +635,7 @@ function download_verify(url::AbstractString, hash::AbstractString,

# Download the file, optionally continuing
download(url, dest; verbose=verbose || !quiet_download)
if !verify(dest, hash; verbose=verbose)
if hash !== nothing && !verify(dest, hash; verbose=verbose)
# If the file already existed, it's possible the initially downloaded chunk
# was bad. If verification fails after downloading, auto-delete the file
# and start over from scratch.
Expand All @@ -647,7 +647,7 @@ function download_verify(url::AbstractString, hash::AbstractString,

# Download and verify from scratch
download(url, dest; verbose=verbose || !quiet_download)
if !verify(dest, hash; verbose=verbose)
if hash !== nothing && !verify(dest, hash; verbose=verbose)
error("Verification failed")
end
else
Expand Down Expand Up @@ -785,7 +785,7 @@ function package(src_dir::AbstractString, tarball_path::AbstractString)
end

"""
download_verify_unpack(url::AbstractString, hash::AbstractString,
download_verify_unpack(url::AbstractString, hash::Union{AbstractString, Nothing},
dest::AbstractString; tarball_path = nothing,
verbose::Bool = false, ignore_existence::Bool = false,
force::Bool = false)
Expand Down Expand Up @@ -814,7 +814,7 @@ Returns `true` if a tarball was actually unpacked, `false` if nothing was
changed in the destination prefix.
"""
function download_verify_unpack(url::AbstractString,
hash::AbstractString,
hash::Union{AbstractString, Nothing},
dest::AbstractString;
tarball_path = nothing,
ignore_existence::Bool = false,
Expand Down

0 comments on commit ebccb80

Please sign in to comment.