@@ -308,6 +308,21 @@ function find_package(arg) # ::Union{Nothing,String}
308308 return locate_package (pkg, env)
309309end
310310
311+ # is there a better/faster ground truth?
312+ function is_stdlib (pkgid:: PkgId )
313+ pkgid. name in readdir (Sys. STDLIB) || return false
314+ stdlib_root = joinpath (Sys. STDLIB, pkgid. name)
315+ project_file = locate_project_file (stdlib_root)
316+ if project_file isa String
317+ d = parsed_toml (project_file)
318+ uuid = get (d, " uuid" , nothing )
319+ if uuid != = nothing
320+ return UUID (uuid) == pkgid. uuid
321+ end
322+ end
323+ return false
324+ end
325+
311326"""
312327 Base.identify_package_env(name::String)::Union{Tuple{PkgId, String}, Nothing}
313328 Base.identify_package_env(where::Union{Module,PkgId}, name::String)::Union{Tuple{PkgId, Union{String, Nothing}}, Nothing}
@@ -336,6 +351,12 @@ function identify_package_env(where::PkgId, name::String)
336351 end
337352 break # found in implicit environment--return "not found"
338353 end
354+ if pkg_env === nothing && is_stdlib (where )
355+ # if not found it could be that manifests are from a different julia version/commit
356+ # where stdlib dependencies have changed, so look up deps based on the stdlib Project.toml
357+ # as a fallback
358+ pkg_env = identify_stdlib_project_dep (where , name)
359+ end
339360 end
340361 if cache != = nothing
341362 cache. identified_where[(where , name)] = pkg_env
@@ -362,6 +383,22 @@ function identify_package_env(name::String)
362383 return pkg_env
363384end
364385
386+ function identify_stdlib_project_dep (stdlib:: PkgId , depname:: String )
387+ @debug """
388+ Stdlib $(repr (" text/plain" , stdlib)) is trying to load `$depname `
389+ which is not listed as a dep in the load path manifests, so resorting to search
390+ in the stdlib Project.tomls for true deps"""
391+ stdlib_projfile = locate_project_file (joinpath (Sys. STDLIB, stdlib. name))
392+ stdlib_projfile === nothing && return nothing
393+ found = explicit_project_deps_get (stdlib_projfile, depname)
394+ if found != = nothing
395+ @debug " $(repr (" text/plain" , stdlib)) indeed depends on $depname in project $stdlib_projfile "
396+ pkgid = PkgId (found, depname)
397+ return pkgid, stdlib_projfile
398+ end
399+ return nothing
400+ end
401+
365402_nothing_or_first (x) = x === nothing ? nothing : first (x)
366403
367404"""
0 commit comments