diff --git a/base/initdefs.jl b/base/initdefs.jl index c04a97971eff2..898d6c5fc18cd 100644 --- a/base/initdefs.jl +++ b/base/initdefs.jl @@ -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") @@ -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 diff --git a/test/loading.jl b/test/loading.jl index 72a07835dd339..eccec84dabbaf 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -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)