Skip to content

Commit 9723de5

Browse files
authored
loading: support extensions for stdlibs (an implicit env) (#52428)
Some groundwork for JuliaStats/Statistics.jl#134 which is bumped (and thus tested) in #52431 that will be merged after this
1 parent bf6c31c commit 9723de5

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

base/loading.jl

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,20 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
668668
return explicit_manifest_uuid_path(project_file, pkg)
669669
elseif project_file
670670
# if env names a directory, search it
671-
return implicit_manifest_uuid_path(env, pkg)
671+
proj = implicit_manifest_uuid_path(env, pkg)
672+
proj === nothing || return proj
673+
# if not found
674+
parentid = get(EXT_PRIMED, pkg, nothing)
675+
if parentid !== nothing
676+
_, parent_project_file = entry_point_and_project_file(env, parentid.name)
677+
if parent_project_file !== nothing
678+
parentproj = project_file_name_uuid(parent_project_file, parentid.name)
679+
if parentproj == parentid
680+
mby_ext = project_file_ext_path(parent_project_file, pkg.name)
681+
mby_ext === nothing || return mby_ext
682+
end
683+
end
684+
end
672685
end
673686
return nothing
674687
end
@@ -1221,11 +1234,19 @@ end
12211234

12221235
function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missing}
12231236
project_file = env_project_file(env)
1224-
if project_file isa String
1237+
if project_file isa String || project_file
1238+
implicit_project_file = project_file
1239+
if !(implicit_project_file isa String)
1240+
# if env names a directory, search it for an implicit project file (for stdlibs)
1241+
path, implicit_project_file = entry_point_and_project_file(env, pkg.name)
1242+
if !(implicit_project_file isa String)
1243+
return nothing
1244+
end
1245+
end
12251246
# Look in project for extensions to insert
1226-
proj_pkg = project_file_name_uuid(project_file, pkg.name)
1247+
proj_pkg = project_file_name_uuid(implicit_project_file, pkg.name)
12271248
if pkg == proj_pkg
1228-
d_proj = parsed_toml(project_file)
1249+
d_proj = parsed_toml(implicit_project_file)
12291250
weakdeps = get(d_proj, "weakdeps", nothing)::Union{Nothing, Vector{String}, Dict{String,Any}}
12301251
extensions = get(d_proj, "extensions", nothing)::Union{Nothing, Dict{String, Any}}
12311252
extensions === nothing && return
@@ -1236,6 +1257,7 @@ function insert_extension_triggers(env::String, pkg::PkgId)::Union{Nothing,Missi
12361257
end
12371258

12381259
# Now look in manifest
1260+
project_file isa String || return nothing
12391261
manifest_file = project_file_manifest_path(project_file)
12401262
manifest_file === nothing && return
12411263
d = get_deps(parsed_toml(manifest_file))
@@ -2371,6 +2393,22 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
23712393
depot_path = map(abspath, DEPOT_PATH)
23722394
dl_load_path = map(abspath, DL_LOAD_PATH)
23732395
load_path = map(abspath, Base.load_path())
2396+
# if pkg is a stdlib, append its parent Project.toml to the load path
2397+
parentid = get(EXT_PRIMED, pkg, nothing)
2398+
if parentid !== nothing
2399+
for env in load_path
2400+
project_file = env_project_file(env)
2401+
if project_file === true
2402+
_, parent_project_file = entry_point_and_project_file(env, parentid.name)
2403+
if parent_project_file !== nothing
2404+
parentproj = project_file_name_uuid(parent_project_file, parentid.name)
2405+
if parentproj == parentid
2406+
push!(load_path, parent_project_file)
2407+
end
2408+
end
2409+
end
2410+
end
2411+
end
23742412
path_sep = Sys.iswindows() ? ';' : ':'
23752413
any(path -> path_sep in path, load_path) &&
23762414
error("LOAD_PATH entries cannot contain $(repr(path_sep))")

0 commit comments

Comments
 (0)