Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2715,7 +2715,7 @@

# load a serialized file directly from append_bundled_depot_path for uuidkey without stalechecks
"""
require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}=nothing)
require_stdlib(package_uuidkey::PkgId, [ext::String, from::Module])

!!! warning "May load duplicate copies of stdlib packages."

Expand Down Expand Up @@ -2754,7 +2754,8 @@
[1] https://github.com/JuliaLang/Pkg.jl/issues/4017#issuecomment-2377589989
[2] https://github.com/JuliaLang/StyledStrings.jl/issues/91#issuecomment-2379602914
"""
function require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}=nothing)
require_stdlib(package_uuidkey::PkgId) = require_stdlib(package_uuidkey, nothing, Base)
function require_stdlib(package_uuidkey::PkgId, ext::Union{Nothing, String}, from::Module)
if generating_output(#=incremental=#true)
# Otherwise this would lead to awkward dependency issues by loading a package that isn't in the Project/Manifest
error("This interactive function requires a stdlib to be loaded, and package code should instead use it directly from that stdlib.")
Expand All @@ -2766,15 +2767,29 @@
newm = start_loading(this_uuidkey, UInt128(0), true)
newm === nothing || return newm
try
# first since this is a stdlib, try to look there directly first
if ext === nothing
sourcepath = normpath(env, this_uuidkey.name, "src", this_uuidkey.name * ".jl")
else
sourcepath = find_ext_path(normpath(joinpath(env, package_uuidkey.name)), ext)
end
depot_path = append_bundled_depot_path!(empty(DEPOT_PATH))
set_pkgorigin_version_path(this_uuidkey, sourcepath)
newm = _require_search_from_serialized(this_uuidkey, sourcepath, UInt128(0), false; DEPOT_PATH=depot_path)
from_stdlib = true # set to false if `from` is a normal package so we do not want the internal loader for the extension either
if ext isa String
from_uuid = PkgId(from)
from_m = get(loaded_modules, from_uuid, nothing)
if from_m === from
# if from_uuid is either nothing or points to something else, assume we should use require_stdlib
# otherwise check cachepath for from to see if it looks like it is from depot_path, since try_build_ids
cachepath = get(PkgOrigin, pkgorigins, from_uuid).cachepath
entrypath, entryfile = cache_file_entry(from_uuid)
from_stdlib = any(x -> startswith(entrypath, x), depot_path)
end
end
if from_stdlib
# first since this is a stdlib, try to look there directly first
if ext === nothing
sourcepath = normpath(env, this_uuidkey.name, "src", this_uuidkey.name * ".jl")
else
sourcepath = find_ext_path(normpath(joinpath(env, package_uuidkey.name)), ext)
end
set_pkgorigin_version_path(this_uuidkey, sourcepath)
newm = _require_search_from_serialized(this_uuidkey, sourcepath, UInt128(0), false; DEPOT_PATH=depot_path)
end
finally
end_loading(this_uuidkey, newm)
end
Expand All @@ -2784,10 +2799,12 @@
run_package_callbacks(this_uuidkey)
else
# if the user deleted their bundled depot, next try to load it completely normally
# if it is an extension, we first need to indicate where to find its parant via EXT_PRIMED

Check warning on line 2802 in base/loading.jl

View workflow job for this annotation

GitHub Actions / Check for new typos

perhaps "parant" should be "parent".
ext isa String && (EXT_PRIMED[this_uuidkey] = PkgId[package_uuidkey])
newm = _require_prelocked(this_uuidkey)
end
return newm
end
end # release lock
end

# relative-path load
Expand Down
4 changes: 3 additions & 1 deletion stdlib/REPL/src/Pkg_beforeload.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

## Pkg stuff needed before Pkg has loaded

const Pkg_pkgid = Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg")
load_pkg() = Base.require_stdlib(Pkg_pkgid, "REPLExt")
load_pkg() = Base.require_stdlib(Pkg_pkgid, "REPLExt", REPL)

## Below here copied/tweaked from Pkg Types.jl so that the dummy Pkg prompt
# can populate the env correctly before Pkg loads
Expand Down