diff --git a/src/Artifacts.jl b/src/Artifacts.jl index cc203e9b94..3b79d94b90 100644 --- a/src/Artifacts.jl +++ b/src/Artifacts.jl @@ -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 @@ -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 @@ -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") diff --git a/src/Operations.jl b/src/Operations.jl index bb33aa8c2d..83467119f0 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -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 # @@ -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)" diff --git a/src/Pkg.jl b/src/Pkg.jl index ebd0df5e14..765895f536 100644 --- a/src/Pkg.jl +++ b/src/Pkg.jl @@ -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") diff --git a/src/PlatformEngines.jl b/src/PlatformEngines.jl index 46c8528717..20b08c73e3 100644 --- a/src/PlatformEngines.jl +++ b/src/PlatformEngines.jl @@ -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) @@ -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 @@ -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)") @@ -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. @@ -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 @@ -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) @@ -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,