Skip to content

Commit be58fca

Browse files
committed
replace depot path with @depot in .ji files
1 parent 344f1f5 commit be58fca

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed

base/initdefs.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,47 @@ function init_depot_path()
113113
end
114114
end
115115

116+
# replace leading dirname with `@depot, @stdlib` if `path` is located withiin any of
117+
# DEPOT_PATH/compiled or Sys.STDLIB
118+
# return normalized path otherwise
119+
function replace_depot_path(_path::AbstractString)
120+
path = normpath(_path)
121+
if startswith(path, Sys.STDLIB)
122+
length(path) == 1+length(Sys.STDLIB) && return joinpath("@stdlib", "")
123+
return joinpath("@stdlib", path[2+length(Sys.STDLIB):end])
124+
end
125+
for depot in DEPOT_PATH
126+
if startswith(path, joinpath(depot, "compiled"))
127+
return joinpath("@depot", path[2+length(depot):end])
128+
end
129+
end
130+
return path
131+
end
132+
133+
# resolve leading `@depot, @stdlib` alias from `_path` to point to a valid path in any
134+
# of DEPOT_PATH/compiled or Sys.STDLIb
135+
# if `_path` has no leading alias, we return a normalized path
136+
function resolve_depot_path(_path::AbstractString)
137+
path = normpath(_path)
138+
if startswith(path, "@stdlib")
139+
length(path) == 1+length("@stdlib") && return joinpath(Sys.STDLIB, "")
140+
fullpath = joinpath(Sys.STDLIB, path[2+length("@stdlib"):end])
141+
ispath(fullpath) && return fullpath
142+
throw(ErrorException("Failed to resolve `$path` to a stdlib path in `$(Sys.STDLIB)`."))
143+
elseif startswith(path, joinpath("@depot", "compiled"))
144+
dir = path[2+length("@depot"):end]
145+
for depot in DEPOT_PATH
146+
fullpath = joinpath(depot, dir)
147+
ispath(fullpath) && return fullpath
148+
end
149+
io = IOBuffer()
150+
print(io, "Failed to resolve `$path` to a valid path for any depot in `DEPOT_PATH = ",
151+
DEPOT_PATH, "`.")
152+
throw(ErrorException(String(take!(io))))
153+
end
154+
return path
155+
end
156+
116157
## LOAD_PATH & ACTIVE_PROJECT ##
117158

118159
# JULIA_LOAD_PATH: split on `:` (or `;` on Windows)

base/loading.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,8 @@ function _include_dependency(mod::Module, _path::AbstractString)
16021602
end
16031603
if _track_dependencies[]
16041604
@lock require_lock begin
1605-
push!(_require_dependencies, (mod, path, mtime(path)))
1605+
push!(_require_dependencies, (mod, path, mtime(path),
1606+
path[1] == '\0' ? path : replace_depot_path(path)))
16061607
end
16071608
end
16081609
return path, prev
@@ -1707,7 +1708,9 @@ function require(into::Module, mod::Symbol)
17071708
end
17081709
uuidkey, env = uuidkey_env
17091710
if _track_dependencies[]
1710-
push!(_require_dependencies, (into, binpack(uuidkey), 0.0))
1711+
path = binpack(uuidkey)
1712+
push!(_require_dependencies, (into, path, 0.0,
1713+
path[1] == '\0' ? path : replace_depot_path(path)))
17111714
end
17121715
return _require_prelocked(uuidkey, env)
17131716
finally
@@ -2454,6 +2457,8 @@ function parse_cache_header(f::IO)
24542457
end
24552458
if depname[1] == '\0'
24562459
push!(requires, modkey => binunpack(depname))
2460+
elseif depname[1] == '@'
2461+
push!(includes, CacheHeaderIncludes(modkey, resolve_depot_path(depname), mtime, modpath))
24572462
else
24582463
push!(includes, CacheHeaderIncludes(modkey, depname, mtime, modpath))
24592464
end

src/precompile.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void write_srctext(ios_t *f, jl_array_t *udeps, int64_t srctextpos) {
3030
write_uint64(f, posfile);
3131
ios_seek_end(f);
3232
// Each source-text file is written as
33-
// int32: length of abspath
34-
// char*: abspath
33+
// int32: length of depot alias
34+
// char*: depot alias
3535
// uint64: length of src text
3636
// char*: src text
3737
// At the end we write int32(0) as a terminal sentinel.
@@ -50,12 +50,13 @@ void write_srctext(ios_t *f, jl_array_t *udeps, int64_t srctextpos) {
5050
ios_t *srctp = ios_file(&srctext, depstr, 1, 0, 0, 0);
5151
if (!srctp) {
5252
jl_printf(JL_STDERR, "WARNING: could not cache source text for \"%s\".\n",
53-
jl_string_data(dep));
53+
depstr);
5454
continue;
5555
}
56-
size_t slen = jl_string_len(dep);
56+
jl_value_t *depalias = jl_fieldref(deptuple, 3); // file @depot alias
57+
size_t slen = jl_string_len(depalias);
5758
write_int32(f, slen);
58-
ios_write(f, depstr, slen);
59+
ios_write(f, jl_string_data(depalias), slen);
5960
posfile = ios_pos(f);
6061
write_uint64(f, 0); // placeholder for length of this file in bytes
6162
uint64_t filelen = (uint64_t) ios_copyall(f, &srctext);

src/staticdata_utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,10 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t* worklist, jl_array_t
715715
size_t i, l = udeps ? jl_array_len(udeps) : 0;
716716
for (i = 0; i < l; i++) {
717717
jl_value_t *deptuple = jl_array_ptr_ref(udeps, i);
718-
jl_value_t *dep = jl_fieldref(deptuple, 1); // file abspath
719-
size_t slen = jl_string_len(dep);
718+
jl_value_t *depalias = jl_fieldref(deptuple, 3); // file @depot alias
719+
size_t slen = jl_string_len(depalias);
720720
write_int32(s, slen);
721-
ios_write(s, jl_string_data(dep), slen);
721+
ios_write(s, jl_string_data(depalias), slen);
722722
write_float64(s, jl_unbox_float64(jl_fieldref(deptuple, 2))); // mtime
723723
jl_module_t *depmod = (jl_module_t*)jl_fieldref(deptuple, 0); // evaluating module
724724
jl_module_t *depmod_top = depmod;

0 commit comments

Comments
 (0)