Skip to content

Commit 0174e43

Browse files
committed
normalize depot paths just before inserting @depot tag
1 parent 8c6d7db commit 0174e43

File tree

3 files changed

+42
-21
lines changed

3 files changed

+42
-21
lines changed

base/loading.jl

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,17 +3176,8 @@ mutable struct CacheHeaderIncludes
31763176
const modpath::Vector{String} # seemingly not needed in Base, but used by Revise
31773177
end
31783178

3179-
# This method is only called from src/precompile.c and from within a precompilation process.
3180-
# Upon call it is safe to assume that `path` and elements of `DEPOT_PATH` are absolute and normalized.
3181-
function replace_depot_path(path::AbstractString)
3182-
for depot in DEPOT_PATH
3183-
!isdir(depot) && continue
3184-
3185-
# Strip extraneous pathseps through normalization.
3186-
if isdirpath(depot)
3187-
depot = dirname(depot)
3188-
end
3189-
3179+
function replace_depot_path(path::AbstractString, depots::Vector{String}=normalize_depots_for_relocation())
3180+
for depot in depots
31903181
if startswith(path, string(depot, Filesystem.pathsep())) || path == depot
31913182
path = replace(path, depot => "@depot"; count=1)
31923183
break
@@ -3195,6 +3186,19 @@ function replace_depot_path(path::AbstractString)
31953186
return path
31963187
end
31973188

3189+
function normalize_depots_for_relocation()
3190+
depots = String[]
3191+
sizehint!(depots, length(DEPOT_PATH))
3192+
for d in DEPOT_PATH
3193+
isdir(d) || continue
3194+
if isdirpath(d)
3195+
d = dirname(d)
3196+
end
3197+
push!(depots, d)
3198+
end
3199+
return depots
3200+
end
3201+
31983202
function restore_depot_path(path::AbstractString, depot::AbstractString)
31993203
replace(path, r"^@depot" => depot; count=1)
32003204
end

src/precompile.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ void write_srctext(ios_t *f, jl_array_t *udeps, int64_t srctextpos) {
3939
static jl_value_t *replace_depot_func = NULL;
4040
if (!replace_depot_func)
4141
replace_depot_func = jl_get_global(jl_base_module, jl_symbol("replace_depot_path"));
42+
static jl_value_t *normalize_depots_func = NULL;
43+
if (!normalize_depots_func)
44+
normalize_depots_func = jl_get_global(jl_base_module, jl_symbol("normalize_depots_for_relocation"));
4245
ios_t srctext;
43-
jl_value_t *deptuple = NULL;
44-
JL_GC_PUSH2(&deptuple, &udeps);
46+
jl_value_t *deptuple = NULL, *depots = NULL;
47+
JL_GC_PUSH3(&deptuple, &udeps, &depots);
48+
jl_task_t *ct = jl_current_task;
49+
size_t last_age = ct->world_age;
50+
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
51+
depots = jl_apply(&normalize_depots_func, 1);
52+
ct->world_age = last_age;
4553
for (size_t i = 0; i < len; i++) {
4654
deptuple = jl_array_ptr_ref(udeps, i);
4755
jl_value_t *depmod = jl_fieldref(deptuple, 0); // module
@@ -60,13 +68,14 @@ void write_srctext(ios_t *f, jl_array_t *udeps, int64_t srctextpos) {
6068
}
6169

6270
jl_value_t **replace_depot_args;
63-
JL_GC_PUSHARGS(replace_depot_args, 2);
71+
JL_GC_PUSHARGS(replace_depot_args, 3);
6472
replace_depot_args[0] = replace_depot_func;
6573
replace_depot_args[1] = abspath;
74+
replace_depot_args[2] = depots;
6675
jl_task_t *ct = jl_current_task;
6776
size_t last_age = ct->world_age;
6877
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
69-
jl_value_t *depalias = (jl_value_t*)jl_apply(replace_depot_args, 2);
78+
jl_value_t *depalias = (jl_value_t*)jl_apply(replace_depot_args, 3);
7079
ct->world_age = last_age;
7180
JL_GC_POP();
7281

src/staticdata_utils.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,16 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t* worklist, jl_array_t
752752
static jl_value_t *replace_depot_func = NULL;
753753
if (!replace_depot_func)
754754
replace_depot_func = jl_get_global(jl_base_module, jl_symbol("replace_depot_path"));
755+
static jl_value_t *normalize_depots_func = NULL;
756+
if (!normalize_depots_func)
757+
normalize_depots_func = jl_get_global(jl_base_module, jl_symbol("normalize_depots_for_relocation"));
758+
759+
jl_value_t *depots = NULL, *prefs_hash = NULL, *prefs_list = NULL;
760+
JL_GC_PUSH2(&depots, &prefs_list);
761+
last_age = ct->world_age;
762+
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
763+
depots = jl_apply(&normalize_depots_func, 1);
764+
ct->world_age = last_age;
755765

756766
// write a placeholder for total size so that we can quickly seek past all of the
757767
// dependencies if we don't need them
@@ -764,13 +774,14 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t* worklist, jl_array_t
764774

765775
if (replace_depot_func) {
766776
jl_value_t **replace_depot_args;
767-
JL_GC_PUSHARGS(replace_depot_args, 2);
777+
JL_GC_PUSHARGS(replace_depot_args, 3);
768778
replace_depot_args[0] = replace_depot_func;
769779
replace_depot_args[1] = deppath;
780+
replace_depot_args[2] = depots;
770781
ct = jl_current_task;
771782
size_t last_age = ct->world_age;
772783
ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
773-
deppath = (jl_value_t*)jl_apply(replace_depot_args, 2);
784+
deppath = (jl_value_t*)jl_apply(replace_depot_args, 3);
774785
ct->world_age = last_age;
775786
JL_GC_POP();
776787
}
@@ -803,9 +814,6 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t* worklist, jl_array_t
803814
write_int32(s, 0); // terminator, for ease of reading
804815

805816
// Calculate Preferences hash for current package.
806-
jl_value_t *prefs_hash = NULL;
807-
jl_value_t *prefs_list = NULL;
808-
JL_GC_PUSH1(&prefs_list);
809817
if (jl_base_module) {
810818
// Toplevel module is the module we're currently compiling, use it to get our preferences hash
811819
jl_value_t * toplevel = (jl_value_t*)jl_get_global(jl_base_module, jl_symbol("__toplevel__"));
@@ -852,7 +860,7 @@ static int64_t write_dependency_list(ios_t *s, jl_array_t* worklist, jl_array_t
852860
write_int32(s, 0);
853861
write_uint64(s, 0);
854862
}
855-
JL_GC_POP(); // for prefs_list
863+
JL_GC_POP(); // for depots, prefs_list
856864

857865
// write a dummy file position to indicate the beginning of the source-text
858866
pos = ios_pos(s);

0 commit comments

Comments
 (0)