Skip to content

Commit

Permalink
Artifacts: pull out a recursive function from a closure to a stand al…
Browse files Browse the repository at this point in the history
…one function (#49755)

(cherry picked from commit 6733197)
  • Loading branch information
KristofferC authored and KristofferC committed May 15, 2023
1 parent 5438efb commit 21e90e0
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions stdlib/Artifacts/src/Artifacts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ function artifacts_dirs(args...)
end
end

# Recursive function, let's not make this a closure because it then has to
# be boxed.
function parse_mapping(mapping::String, name::String, override_file::String)
if !isabspath(mapping) && !isempty(mapping)
mapping = tryparse(Base.SHA1, mapping)
if mapping === nothing
@error("Invalid override in '$(override_file)': entry '$(name)' must map to an absolute path or SHA1 hash!")
end
end
return mapping
end
function parse_mapping(mapping::Dict, name::String, override_file::String)
return Dict(k => parse_mapping(v, name, override_file) for (k, v) in mapping)
end
# Fallthrough for invalid Overrides.toml files
parse_mapping(mapping, name::String, override_file::String) = nothing

"""
ARTIFACT_OVERRIDES
Expand Down Expand Up @@ -103,24 +120,9 @@ function load_overrides(;force::Bool = false)::Dict{Symbol, Any}
# Load the toml file
depot_override_dict = parse_toml(override_file)

function parse_mapping(mapping::String, name::String)
if !isabspath(mapping) && !isempty(mapping)
mapping = tryparse(Base.SHA1, mapping)
if mapping === nothing
@error("Invalid override in '$(override_file)': entry '$(name)' must map to an absolute path or SHA1 hash!")
end
end
return mapping
end
function parse_mapping(mapping::Dict, name::String)
return Dict(k => parse_mapping(v, name) for (k, v) in mapping)
end
# Fallthrough for invalid Overrides.toml files
parse_mapping(mapping, name::String) = nothing

for (k, mapping) in depot_override_dict
# First, parse the mapping. Is it an absolute path, a valid SHA1-hash, or neither?
mapping = parse_mapping(mapping, k)
mapping = parse_mapping(mapping, k, override_file)
if mapping === nothing
@error("Invalid override in '$(override_file)': failed to parse entry `$(k)`")
continue
Expand Down Expand Up @@ -743,5 +745,8 @@ artifact_slash_lookup(name::AbstractString, artifact_dict::Dict, artifacts_toml:
precompile(load_artifacts_toml, (String,))
precompile(NamedTuple{(:pkg_uuid,)}, (Tuple{Base.UUID},))
precompile(Core.kwfunc(load_artifacts_toml), (NamedTuple{(:pkg_uuid,), Tuple{Base.UUID}}, typeof(load_artifacts_toml), String))
precompile(parse_mapping, (String, String, String))
precompile(parse_mapping, (Dict{String, Any}, String, String))


end # module Artifacts

0 comments on commit 21e90e0

Please sign in to comment.