Skip to content

Commit 199cac7

Browse files
authored
Strip trailing slashes in JULIA_DEPOT_PATH when embedding @depot (#51892)
The new relocatable cache file work uses simple text substitution when stripping out the depot from a cache file's paths, and when substituting it in again over the `@depot` marker. However, if a user starts julia with `JULIA_DEPOT_PATH=/opt/foo/`, the embedded path for `Foo.jl`'s includes list will look like `@depotpackages/Foo/XYZ/src/Foo.jl`, and if the user then uses `JULIA_DEPOT_PATH=/opt/foo` (which should be equivalent) the cache file will fail to load with the message: ``` Failed to determine depot from srctext files ``` This commit standardizes the serialization format to always contain a trailing `pathsep()`, so that textual substitution is more likely to work regardless of slightly-inconsistent `JULIA_DEPOT_PATH` settings.
1 parent 8382d51 commit 199cac7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

base/loading.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,8 +2600,15 @@ end
26002600

26012601
function replace_depot_path(path::AbstractString)
26022602
for depot in DEPOT_PATH
2603+
# Skip depots that don't exist
2604+
if !isdirpath(depot)
2605+
continue
2606+
end
2607+
2608+
# Strip extraneous pathseps through normalization.
2609+
depot = dirname(depot)
26032610
if startswith(path, depot)
2604-
path = replace(path, depot => "@depot")
2611+
path = replace(path, depot => "@depot"; count=1)
26052612
break
26062613
end
26072614
end
@@ -2619,7 +2626,7 @@ function resolve_depot(includes)
26192626
end
26202627
for depot in DEPOT_PATH
26212628
if all(includes) do inc
2622-
isfile(replace(inc, r"^@depot" => depot))
2629+
isfile(replace(inc, r"^@depot" => depot; count=1))
26232630
end
26242631
return depot
26252632
end
@@ -2725,7 +2732,7 @@ function parse_cache_header(f::IO, cachefile::AbstractString)
27252732
@debug "Missing @depot tag for include dependencies in cache file $cachefile."
27262733
else
27272734
for inc in includes
2728-
inc.filename = replace(inc.filename, r"^@depot" => depot)
2735+
inc.filename = replace(inc.filename, r"^@depot" => depot; count=1)
27292736
end
27302737
end
27312738
includes_srcfiles_only = includes[keepidx]

test/relocatedepot.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ if !test_relocated_depot
3737
pkgname = "RelocationTestPkg2"
3838
test_harness() do
3939
push!(LOAD_PATH, @__DIR__)
40-
push!(DEPOT_PATH, @__DIR__)
40+
push!(DEPOT_PATH, string(@__DIR__, "/"))
4141
pkg = Base.identify_package(pkgname)
4242
cachefiles = Base.find_all_in_cache_path(pkg)
4343
rm.(cachefiles, force=true)

0 commit comments

Comments
 (0)