Skip to content

Commit

Permalink
Strip trailing slashes in JULIA_DEPOT_PATH when embedding @depot (J…
Browse files Browse the repository at this point in the history
…uliaLang#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.
  • Loading branch information
staticfloat committed Oct 27, 2023
1 parent 8382d51 commit 199cac7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2600,8 +2600,15 @@ end

function replace_depot_path(path::AbstractString)
for depot in DEPOT_PATH
# Skip depots that don't exist
if !isdirpath(depot)
continue
end

# Strip extraneous pathseps through normalization.
depot = dirname(depot)
if startswith(path, depot)
path = replace(path, depot => "@depot")
path = replace(path, depot => "@depot"; count=1)
break
end
end
Expand All @@ -2619,7 +2626,7 @@ function resolve_depot(includes)
end
for depot in DEPOT_PATH
if all(includes) do inc
isfile(replace(inc, r"^@depot" => depot))
isfile(replace(inc, r"^@depot" => depot; count=1))
end
return depot
end
Expand Down Expand Up @@ -2725,7 +2732,7 @@ function parse_cache_header(f::IO, cachefile::AbstractString)
@debug "Missing @depot tag for include dependencies in cache file $cachefile."
else
for inc in includes
inc.filename = replace(inc.filename, r"^@depot" => depot)
inc.filename = replace(inc.filename, r"^@depot" => depot; count=1)
end
end
includes_srcfiles_only = includes[keepidx]
Expand Down
2 changes: 1 addition & 1 deletion test/relocatedepot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if !test_relocated_depot
pkgname = "RelocationTestPkg2"
test_harness() do
push!(LOAD_PATH, @__DIR__)
push!(DEPOT_PATH, @__DIR__)
push!(DEPOT_PATH, string(@__DIR__, "/"))
pkg = Base.identify_package(pkgname)
cachefiles = Base.find_all_in_cache_path(pkg)
rm.(cachefiles, force=true)
Expand Down

0 comments on commit 199cac7

Please sign in to comment.