Skip to content

Commit

Permalink
Change how bare separators are expanded in JULIA_DEPOT_PATH.
Browse files Browse the repository at this point in the history
Instead of expanding to the default (homedir-based) + bundled (bindir-based) depot,
only use the bundled depot, so the env var can be used to select a different depot
while still being able to load bundled cache files.
  • Loading branch information
maleadt committed Sep 28, 2023
1 parent 50146b2 commit 917ffae
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
22 changes: 17 additions & 5 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ See also [`JULIA_DEPOT_PATH`](@ref JULIA_DEPOT_PATH), and
"""
const DEPOT_PATH = String[]

function append_default_depot_path!(DEPOT_PATH)
path = joinpath(homedir(), ".julia")
path in DEPOT_PATH || push!(DEPOT_PATH, path)
function append_bundled_depot_path!(DEPOT_PATH)
path = abspath(Sys.BINDIR, "..", "local", "share", "julia")
path in DEPOT_PATH || push!(DEPOT_PATH, path)
path = abspath(Sys.BINDIR, "..", "share", "julia")
Expand All @@ -100,17 +98,31 @@ function init_depot_path()
empty!(DEPOT_PATH)
if haskey(ENV, "JULIA_DEPOT_PATH")
str = ENV["JULIA_DEPOT_PATH"]

# explicitly setting JULIA_DEPOT_PATH to the empty string means using no depot
isempty(str) && return

# otherwise, populate the depot path with the entries in JULIA_DEPOT_PATH,
# expanding empty strings to the bundled depot
populated = false
for path in eachsplit(str, Sys.iswindows() ? ';' : ':')
if isempty(path)
append_default_depot_path!(DEPOT_PATH)
append_bundled_depot_path!(DEPOT_PATH)
else
path = expanduser(path)
path in DEPOT_PATH || push!(DEPOT_PATH, path)
populated = true
end
end

# backwards compatibility: if JULIA_DEPOT_PATH only contains empty entries
# (e.g., JULIA_DEPOT_PATH=':'), make sure to use the default depot
if !populated
pushfirst!(DEPOT_PATH, joinpath(homedir(), ".julia"))
end
else
append_default_depot_path!(DEPOT_PATH)
push!(DEPOT_PATH, joinpath(homedir(), ".julia"))
append_bundled_depot_path!(DEPOT_PATH)
end
nothing
end
Expand Down
13 changes: 7 additions & 6 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -721,16 +721,17 @@ end
@testset "expansion of JULIA_DEPOT_PATH" begin
s = Sys.iswindows() ? ';' : ':'
tmp = "/this/does/not/exist"
DEFAULT = Base.append_default_depot_path!(String[])
default = joinpath(homedir(), ".julia")
bundled = Base.append_bundled_depot_path!(String[])
cases = Dict{Any,Vector{String}}(
nothing => DEFAULT,
nothing => [default; bundled],
"" => [],
"$s" => DEFAULT,
"$tmp$s" => [tmp; DEFAULT],
"$s$tmp" => [DEFAULT; tmp],
"$s" => [default; bundled],
"$tmp$s" => [tmp; bundled],
"$s$tmp" => [bundled; tmp],
)
for (env, result) in pairs(cases)
script = "DEPOT_PATH == $(repr(result)) || error()"
script = "DEPOT_PATH == $(repr(result)) || error(\"actual depot \" * join(DEPOT_PATH,':') * \" does not match expected depot \" * join($(repr(result)), ':'))"
cmd = `$(Base.julia_cmd()) --startup-file=no -e $script`
cmd = addenv(cmd, "JULIA_DEPOT_PATH" => env)
cmd = pipeline(cmd; stdout, stderr)
Expand Down

0 comments on commit 917ffae

Please sign in to comment.