Skip to content

Commit

Permalink
get rid of some invalidation sources in Artifacts (#37605)
Browse files Browse the repository at this point in the history
* get rid of some invalidation sources in Artifacts

* Update Artifacts.jl

* tweaks

Co-authored-by: Elliot Saba <staticfloat@gmail.com>
  • Loading branch information
KristofferC and staticfloat authored Sep 17, 2020
1 parent 8e3f298 commit 9b81a8a
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions stdlib/Artifacts/src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ the override: overriding to an on-disk location through an absolutet path, and
overriding to another artifact by its content-hash.
"""
const ARTIFACT_OVERRIDES = Ref{Union{Dict{Symbol,Any},Nothing}}(nothing)
function load_overrides(;force::Bool = false)
function load_overrides(;force::Bool = false)::Dict{Symbol, Any}
if ARTIFACT_OVERRIDES[] !== nothing && !force
return ARTIFACT_OVERRIDES[]
end
Expand Down Expand Up @@ -172,11 +172,11 @@ function load_overrides(;force::Bool = false)
end

ARTIFACT_OVERRIDES[] = overrides
return overrides
end

# Helpers to map an override to an actual path
map_override_path(x::String) = x
map_override_path(x::AbstractString) = string(x)
map_override_path(x::AbstractString) = String(x)::String
map_override_path(x::SHA1) = artifact_path(x)
map_override_path(x::Nothing) = nothing

Expand All @@ -186,10 +186,10 @@ map_override_path(x::Nothing) = nothing
Query the loaded `<DEPOT>/artifacts/Overrides.toml` settings for artifacts that should be
redirected to a particular path or another content-hash.
"""
function query_override(hash::SHA1; overrides::Dict = load_overrides())
function query_override(hash::SHA1; overrides::Dict{Symbol,Any} = load_overrides())
return map_override_path(get(overrides[:hash], hash, nothing))
end
function query_override(pkg::Base.UUID, artifact_name::String; overrides::Dict = load_overrides())
function query_override(pkg::Base.UUID, artifact_name::String; overrides::Dict{Symbol,Any} = load_overrides())
if haskey(overrides[:UUID], pkg)
return map_override_path(get(overrides[:UUID][pkg], artifact_name, nothing))
end
Expand Down Expand Up @@ -258,7 +258,8 @@ end
Given an `entry` for the artifact named `name`, located within the file `artifacts_toml`,
returns the `Platform` object that this entry specifies. Returns `nothing` on error.
"""
function unpack_platform(entry::Dict, name::String, artifacts_toml::String)::Union{Nothing,Platform}
function unpack_platform(entry::Dict{String,Any}, name::String,
artifacts_toml::String)::Union{Nothing,Platform}
if !haskey(entry, "os")
@error("Invalid artifacts file at '$(artifacts_toml)': platform-specific artifact entry '$name' missing 'os' key")
return nothing
Expand All @@ -270,7 +271,12 @@ function unpack_platform(entry::Dict, name::String, artifacts_toml::String)::Uni
end

# Collect all String-valued mappings in `entry` and use them as tags
tags = Dict(Symbol(k) => v for (k, v) in entry if isa(v, String))
tags = Dict{Symbol, String}()
for (k, v) in entry
if v isa String
tags[Symbol(k)] = v
end
end
# Removing some known entries that shouldn't be passed through `tags`
delete!(tags, :os)
delete!(tags, :arch)
Expand Down Expand Up @@ -376,8 +382,12 @@ function artifact_meta(name::String, artifact_dict::Dict, artifacts_toml::String
meta = artifact_dict[name]

# If it's an array, find the entry that best matches our current platform
if isa(meta, Array)
dl_dict = Dict{AbstractPlatform,Dict{String,Any}}(unpack_platform(x, name, artifacts_toml) => x for x in meta)
if isa(meta, Vector)
dl_dict = Dict{AbstractPlatform,Dict{String,Any}}()
for x in meta
x::Dict{String}
dl_dict[unpack_platform(x, name, artifacts_toml)] = x
end
meta = select_platform(dl_dict, platform)
# If it's NOT a dict, complain
elseif !isa(meta, Dict)
Expand Down Expand Up @@ -610,24 +620,24 @@ end
# Support `AbstractString`s, but avoid compilers needing to track backedges for callers
# of these functions in case a user defines a new type that is `<: AbstractString`
with_artifacts_directory(f::Function, artifacts_dir::AbstractString) =
with_artifacts_directory(f, string(artifacts_dir))
query_override(pkg::Base.UUID, artifact_name::AbstractString; kwargs...) =
query_override(pkg, string(artifact_name); kwargs...)
with_artifacts_directory(f, String(artifacts_dir)::String)
query_override(pkg::Base.UUID, artifact_name::AbstractString; overrides::Dict=load_overrides()) =
query_override(pkg, String(artifact_name)::String; overrides=convert(Dict{Symbol, Any}(overrides)))
unpack_platform(entry::Dict, name::AbstractString, artifacts_toml::AbstractString) =
unpack_platform(entry, string(name), string(artifacts_toml))
unpack_platform(convert(Dict{String, Any}, entry), String(name)::String, String(artifacts_toml)::String)
load_artifacts_toml(artifacts_toml::AbstractString; kwargs...) =
load_artifacts_toml(string(artifacts_toml); kwargs...)
load_artifacts_toml(String(artifacts_toml)::String; kwargs...)
artifact_meta(name::AbstractString, artifacts_toml::AbstractString; kwargs...) =
artifact_meta(string(name), string(artifacts_toml); kwargs...)
artifact_meta(String(name)::String, String(artifacts_toml)::String; kwargs...)
artifact_meta(name::AbstractString, artifact_dict::Dict, artifacts_toml::AbstractString; kwargs...) =
artifact_meta(string(name), artifact_dict, string(artifacts_toml); kwargs...)
artifact_meta(String(name)::String, artifact_dict, String(artifacts_toml)::String; kwargs...)
artifact_hash(name::AbstractString, artifacts_toml::AbstractString; kwargs...) =
artifact_hash(string(name), string(artifacts_toml); kwargs...)
artifact_hash(String(name)::String, String(artifacts_toml)::String; kwargs...)
find_artifacts_toml(path::AbstractString) =
find_artifacts_toml(string(path))
find_artifacts_toml(String(path)::String)
split_artifact_slash(name::AbstractString) =
split_artifact_slash(string(name))
split_artifact_slash(String(name)::String)
artifact_slash_lookup(name::AbstractString, artifact_dict::Dict, artifacts_toml::AbstractString) =
artifact_slash_lookup(string(name), artifact_dict, string(artifacts_toml))
artifact_slash_lookup(String(name)::String, artifact_dict, String(artifacts_toml)::String)

end # module Artifacts

0 comments on commit 9b81a8a

Please sign in to comment.