Skip to content

Commit

Permalink
refactor depot path helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
fatteneder committed Aug 1, 2023
1 parent 0d1158c commit dd3c5ce
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,24 @@ function init_depot_path()
nothing
end

# replace leading dirname with `@depot, @stdlib` if `path` is located within any of
# DEPOT_PATH or Sys.STDLIB
# replace leading dirname with `@depot, @stdlib` if `path` is located within any of DEPOT_PATH or Sys.STDLIB
# return normalized path otherwise
function replace_depot_path(_path::AbstractString)
path = normpath(_path)
if startswith(path, Sys.STDLIB)
length(path) == 1+length(Sys.STDLIB) && return joinpath("@stdlib", "")
return joinpath("@stdlib", path[2+length(Sys.STDLIB):end])
subpath = path[nextind(path,length(Sys.STDLIB)):end]
if isabspath(subpath)
subpath = subpath[nextind(subpath,1):end]
end
return joinpath("@stdlib", subpath)
end
for depot in DEPOT_PATH
if startswith(path, depot) # joinpath(depot, "compiled"))
subpath = path[1+length(depot):end]
if startswith(subpath, "/")
subpath = subpath[2:end]
if startswith(path, joinpath(depot, "compiled")) || startswith(path, joinpath(depot, "packages"))
subpath = path[nextind(path,length(depot)):end]
if isabspath(subpath)
subpath = subpath[nextind(subpath,1):end]
end
return joinpath("@depot", subpath)
# return joinpath("@depot", path[1+length(depot):end])
end
end
return path
Expand All @@ -143,21 +144,16 @@ end
function resolve_depot_path(_path::AbstractString)
path = normpath(_path)
if startswith(path, "@stdlib")
length(path) == 1+length("@stdlib") && return joinpath(Sys.STDLIB, "")
fullpath = joinpath(Sys.STDLIB, path[2+length("@stdlib"):end])
fullpath = joinpath(Sys.STDLIB, path[nextind(path,length("@stdlib")+1):end])
ispath(fullpath) && return fullpath
throw(ErrorException("Failed to resolve `$path` to a stdlib path in `$(Sys.STDLIB)`."))
elseif startswith(path, joinpath("@depot")) #, "compiled"))
dir = path[2+length("@depot"):end]
throw(ErrorException("Failed to resolve `$path` ($fullpath) to a stdlib path in `$(Sys.STDLIB)`."))
elseif startswith(path, joinpath("@depot"))
dir = path[nextind(path,length("@depot")+1):end]
for depot in DEPOT_PATH
fullpath = joinpath(depot, dir)
ispath(fullpath) && return fullpath
end
# TODO Why IOBuffer here?
io = IOBuffer()
print(io, "Failed to resolve `$path` to a valid path for any depot in `DEPOT_PATH = ",
DEPOT_PATH, "`.")
throw(ErrorException(String(take!(io))))
throw(ErrorException("Failed to resolve `$path` to a valid path for any depot in `DEPOT_PATH`"))
end
return path
end
Expand Down

0 comments on commit dd3c5ce

Please sign in to comment.