Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artifacts: pull out a recursive function from a closure to a stand alone function #49755

Merged
merged 1 commit into from
May 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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