From 5a86131b14d2a8967141c7eadd3095f1b84a64e1 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 21 Sep 2020 13:04:22 -0400 Subject: [PATCH] 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 * add tests for in_sysimage * Fix typo in test Co-authored-by: Takafumi Arakaki --- base/Base.jl | 4 ++++ test/loading.jl | 3 +++ 2 files changed, 7 insertions(+) diff --git a/base/Base.jl b/base/Base.jl index 057c512887c6c..2fbba2a3468ae 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -381,6 +381,9 @@ include(mapexpr::Function, mod::Module, _path::AbstractString) = _include(mapexp end_base_include = time_ns() +const _sysimage_modules = PkgId[] +in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules + if is_primary_base_module function __init__() # try to ensuremake sure OpenBLAS does not set CPU affinity (#1070, #9639) @@ -405,6 +408,7 @@ function __init__() init_depot_path() init_load_path() init_active_project() + append!(empty!(_sysimage_modules), keys(loaded_modules)) nothing end diff --git a/test/loading.jl b/test/loading.jl index 8c9a200b3daa4..637382d49f8b1 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -57,6 +57,9 @@ let exename = `$(Base.julia_cmd()) --compiled-modules=yes --startup-file=no`, @test !endswith(s_dir, Base.Filesystem.path_separator) end +@test Base.in_sysimage(Base.PkgId(Base.UUID("cf7118a7-6976-5b1a-9a39-7adc72f591a4"), "UUIDs")) +@test Base.in_sysimage(Base.PkgId(Base.UUID("3a7fdc7e-7467-41b4-9f64-ea033d046d5b"), "NotAPackage")) == false + # Issue #5789 and PR #13542: mktempdir() do dir cd(dir) do