@@ -2715,7 +2715,7 @@ end
2715
2715
2716
2716
# load a serialized file directly from append_bundled_depot_path for uuidkey without stalechecks
2717
2717
"""
2718
- require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}=nothing )
2718
+ require_stdlib(package_uuidkey::PkgId, [ ext::String, from::Module] )
2719
2719
2720
2720
!!! warning "May load duplicate copies of stdlib packages."
2721
2721
@@ -2754,7 +2754,8 @@ end
2754
2754
[1] https://github.com/JuliaLang/Pkg.jl/issues/4017#issuecomment-2377589989
2755
2755
[2] https://github.com/JuliaLang/StyledStrings.jl/issues/91#issuecomment-2379602914
2756
2756
"""
2757
- function require_stdlib (package_uuidkey:: PkgId , ext:: Union{Nothing, String} = nothing )
2757
+ require_stdlib (package_uuidkey:: PkgId ) = require_stdlib (package_uuidkey, nothing , Base)
2758
+ function require_stdlib (package_uuidkey:: PkgId , ext:: Union{Nothing, String} , from:: Module )
2758
2759
if generating_output (#= incremental=# true )
2759
2760
# Otherwise this would lead to awkward dependency issues by loading a package that isn't in the Project/Manifest
2760
2761
error (" This interactive function requires a stdlib to be loaded, and package code should instead use it directly from that stdlib." )
@@ -2766,15 +2767,29 @@ function require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}=noth
2766
2767
newm = start_loading (this_uuidkey, UInt128 (0 ), true )
2767
2768
newm === nothing || return newm
2768
2769
try
2769
- # first since this is a stdlib, try to look there directly first
2770
- if ext === nothing
2771
- sourcepath = normpath (env, this_uuidkey. name, " src" , this_uuidkey. name * " .jl" )
2772
- else
2773
- sourcepath = find_ext_path (normpath (joinpath (env, package_uuidkey. name)), ext)
2774
- end
2775
2770
depot_path = append_bundled_depot_path! (empty (DEPOT_PATH ))
2776
- set_pkgorigin_version_path (this_uuidkey, sourcepath)
2777
- newm = _require_search_from_serialized (this_uuidkey, sourcepath, UInt128 (0 ), false ; DEPOT_PATH = depot_path)
2771
+ from_stdlib = true # set to false if `from` is a normal package so we do not want the internal loader for the extension either
2772
+ if ext isa String
2773
+ from_uuid = PkgId (from)
2774
+ from_m = get (loaded_modules, from_uuid, nothing )
2775
+ if from_m === from
2776
+ # if from_uuid is either nothing or points to something else, assume we should use require_stdlib
2777
+ # otherwise check cachepath for from to see if it looks like it is from depot_path, since try_build_ids
2778
+ cachepath = get (PkgOrigin, pkgorigins, from_uuid). cachepath
2779
+ entrypath, entryfile = cache_file_entry (from_uuid)
2780
+ from_stdlib = any (x -> startswith (entrypath, x), depot_path)
2781
+ end
2782
+ end
2783
+ if from_stdlib
2784
+ # first since this is a stdlib, try to look there directly first
2785
+ if ext === nothing
2786
+ sourcepath = normpath (env, this_uuidkey. name, " src" , this_uuidkey. name * " .jl" )
2787
+ else
2788
+ sourcepath = find_ext_path (normpath (joinpath (env, package_uuidkey. name)), ext)
2789
+ end
2790
+ set_pkgorigin_version_path (this_uuidkey, sourcepath)
2791
+ newm = _require_search_from_serialized (this_uuidkey, sourcepath, UInt128 (0 ), false ; DEPOT_PATH = depot_path)
2792
+ end
2778
2793
finally
2779
2794
end_loading (this_uuidkey, newm)
2780
2795
end
@@ -2784,10 +2799,12 @@ function require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}=noth
2784
2799
run_package_callbacks (this_uuidkey)
2785
2800
else
2786
2801
# if the user deleted their bundled depot, next try to load it completely normally
2802
+ # if it is an extension, we first need to indicate where to find its parant via EXT_PRIMED
2803
+ ext isa String && (EXT_PRIMED[this_uuidkey] = PkgId[package_uuidkey])
2787
2804
newm = _require_prelocked (this_uuidkey)
2788
2805
end
2789
2806
return newm
2790
- end
2807
+ end # release lock
2791
2808
end
2792
2809
2793
2810
# relative-path load
0 commit comments