Skip to content

Commit 5a86131

Browse files
IanButterworthtkf
andauthored
Add in_sysimage(pkgid::PkgId) to check if a package is in the sysimage (#37652)
* add in_sysimage to check if a package is in the sysimage * suggestion to empty _sysimage_modules first Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com> * add tests for in_sysimage * Fix typo in test Co-authored-by: Takafumi Arakaki <takafumi.a@gmail.com>
1 parent 10e2455 commit 5a86131

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

base/Base.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ include(mapexpr::Function, mod::Module, _path::AbstractString) = _include(mapexp
381381

382382
end_base_include = time_ns()
383383

384+
const _sysimage_modules = PkgId[]
385+
in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules
386+
384387
if is_primary_base_module
385388
function __init__()
386389
# try to ensuremake sure OpenBLAS does not set CPU affinity (#1070, #9639)
@@ -405,6 +408,7 @@ function __init__()
405408
init_depot_path()
406409
init_load_path()
407410
init_active_project()
411+
append!(empty!(_sysimage_modules), keys(loaded_modules))
408412
nothing
409413
end
410414

test/loading.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ let exename = `$(Base.julia_cmd()) --compiled-modules=yes --startup-file=no`,
5757
@test !endswith(s_dir, Base.Filesystem.path_separator)
5858
end
5959

60+
@test Base.in_sysimage(Base.PkgId(Base.UUID("cf7118a7-6976-5b1a-9a39-7adc72f591a4"), "UUIDs"))
61+
@test Base.in_sysimage(Base.PkgId(Base.UUID("3a7fdc7e-7467-41b4-9f64-ea033d046d5b"), "NotAPackage")) == false
62+
6063
# Issue #5789 and PR #13542:
6164
mktempdir() do dir
6265
cd(dir) do

0 commit comments

Comments
 (0)