Skip to content

Commit 9b81a8a

Browse files
get rid of some invalidation sources in Artifacts (#37605)
* get rid of some invalidation sources in Artifacts * Update Artifacts.jl * tweaks Co-authored-by: Elliot Saba <staticfloat@gmail.com>
1 parent 8e3f298 commit 9b81a8a

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

stdlib/Artifacts/src/Artifacts.jl

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ the override: overriding to an on-disk location through an absolutet path, and
7676
overriding to another artifact by its content-hash.
7777
"""
7878
const ARTIFACT_OVERRIDES = Ref{Union{Dict{Symbol,Any},Nothing}}(nothing)
79-
function load_overrides(;force::Bool = false)
79+
function load_overrides(;force::Bool = false)::Dict{Symbol, Any}
8080
if ARTIFACT_OVERRIDES[] !== nothing && !force
8181
return ARTIFACT_OVERRIDES[]
8282
end
@@ -172,11 +172,11 @@ function load_overrides(;force::Bool = false)
172172
end
173173

174174
ARTIFACT_OVERRIDES[] = overrides
175+
return overrides
175176
end
176177

177178
# Helpers to map an override to an actual path
178-
map_override_path(x::String) = x
179-
map_override_path(x::AbstractString) = string(x)
179+
map_override_path(x::AbstractString) = String(x)::String
180180
map_override_path(x::SHA1) = artifact_path(x)
181181
map_override_path(x::Nothing) = nothing
182182

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

272273
# Collect all String-valued mappings in `entry` and use them as tags
273-
tags = Dict(Symbol(k) => v for (k, v) in entry if isa(v, String))
274+
tags = Dict{Symbol, String}()
275+
for (k, v) in entry
276+
if v isa String
277+
tags[Symbol(k)] = v
278+
end
279+
end
274280
# Removing some known entries that shouldn't be passed through `tags`
275281
delete!(tags, :os)
276282
delete!(tags, :arch)
@@ -376,8 +382,12 @@ function artifact_meta(name::String, artifact_dict::Dict, artifacts_toml::String
376382
meta = artifact_dict[name]
377383

378384
# If it's an array, find the entry that best matches our current platform
379-
if isa(meta, Array)
380-
dl_dict = Dict{AbstractPlatform,Dict{String,Any}}(unpack_platform(x, name, artifacts_toml) => x for x in meta)
385+
if isa(meta, Vector)
386+
dl_dict = Dict{AbstractPlatform,Dict{String,Any}}()
387+
for x in meta
388+
x::Dict{String}
389+
dl_dict[unpack_platform(x, name, artifacts_toml)] = x
390+
end
381391
meta = select_platform(dl_dict, platform)
382392
# If it's NOT a dict, complain
383393
elseif !isa(meta, Dict)
@@ -610,24 +620,24 @@ end
610620
# Support `AbstractString`s, but avoid compilers needing to track backedges for callers
611621
# of these functions in case a user defines a new type that is `<: AbstractString`
612622
with_artifacts_directory(f::Function, artifacts_dir::AbstractString) =
613-
with_artifacts_directory(f, string(artifacts_dir))
614-
query_override(pkg::Base.UUID, artifact_name::AbstractString; kwargs...) =
615-
query_override(pkg, string(artifact_name); kwargs...)
623+
with_artifacts_directory(f, String(artifacts_dir)::String)
624+
query_override(pkg::Base.UUID, artifact_name::AbstractString; overrides::Dict=load_overrides()) =
625+
query_override(pkg, String(artifact_name)::String; overrides=convert(Dict{Symbol, Any}(overrides)))
616626
unpack_platform(entry::Dict, name::AbstractString, artifacts_toml::AbstractString) =
617-
unpack_platform(entry, string(name), string(artifacts_toml))
627+
unpack_platform(convert(Dict{String, Any}, entry), String(name)::String, String(artifacts_toml)::String)
618628
load_artifacts_toml(artifacts_toml::AbstractString; kwargs...) =
619-
load_artifacts_toml(string(artifacts_toml); kwargs...)
629+
load_artifacts_toml(String(artifacts_toml)::String; kwargs...)
620630
artifact_meta(name::AbstractString, artifacts_toml::AbstractString; kwargs...) =
621-
artifact_meta(string(name), string(artifacts_toml); kwargs...)
631+
artifact_meta(String(name)::String, String(artifacts_toml)::String; kwargs...)
622632
artifact_meta(name::AbstractString, artifact_dict::Dict, artifacts_toml::AbstractString; kwargs...) =
623-
artifact_meta(string(name), artifact_dict, string(artifacts_toml); kwargs...)
633+
artifact_meta(String(name)::String, artifact_dict, String(artifacts_toml)::String; kwargs...)
624634
artifact_hash(name::AbstractString, artifacts_toml::AbstractString; kwargs...) =
625-
artifact_hash(string(name), string(artifacts_toml); kwargs...)
635+
artifact_hash(String(name)::String, String(artifacts_toml)::String; kwargs...)
626636
find_artifacts_toml(path::AbstractString) =
627-
find_artifacts_toml(string(path))
637+
find_artifacts_toml(String(path)::String)
628638
split_artifact_slash(name::AbstractString) =
629-
split_artifact_slash(string(name))
639+
split_artifact_slash(String(name)::String)
630640
artifact_slash_lookup(name::AbstractString, artifact_dict::Dict, artifacts_toml::AbstractString) =
631-
artifact_slash_lookup(string(name), artifact_dict, string(artifacts_toml))
641+
artifact_slash_lookup(String(name)::String, artifact_dict, String(artifacts_toml)::String)
632642

633643
end # module Artifacts

0 commit comments

Comments
 (0)