Skip to content

Commit 4652a09

Browse files
topolarityKristofferC
authored andcommitted
trimming: Locate package modules by PkgId (#57672)
As recommended in #57589 (comment) (cherry picked from commit eba2a33)
1 parent e342f1c commit 4652a09

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

contrib/juliac-buildscript.jl

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,11 @@ let mod = Base.include(Base.__toplevel__, inputfile)
208208
end
209209

210210
# Additional method patches depending on whether user code loads certain stdlibs
211-
let loaded = Base.loaded_modules_array()
212-
function find_loaded_module(name)
213-
idx = findfirst((m) -> Symbol(m) === name, loaded)
214-
idx === nothing && return nothing
215-
return loaded[idx]
216-
end
211+
let
212+
find_loaded_root_module(key::Base.PkgId) = Base.maybe_root_module(key)
217213

218-
SparseArrays = find_loaded_module(:SparseArrays)
214+
SparseArrays = find_loaded_root_module(Base.PkgId(
215+
Base.UUID("2f01184e-e22b-5df5-ae63-d93ebab69eaf"), "SparseArrays"))
219216
if SparseArrays !== nothing
220217
@eval SparseArrays.CHOLMOD begin
221218
function __init__()
@@ -231,10 +228,20 @@ let loaded = Base.loaded_modules_array()
231228
end
232229
end
233230

234-
Artifacts = find_loaded_module(:Artifacts)
231+
Artifacts = find_loaded_root_module(Base.PkgId(
232+
Base.UUID("56f22d72-fd6d-98f1-02f0-08ddc0907c33"), "Artifacts"))
235233
if Artifacts !== nothing
236234
@eval Artifacts begin
237-
function _artifact_str(__module__, artifacts_toml, name, path_tail, artifact_dict, hash, platform, _::Val{lazyartifacts}) where lazyartifacts
235+
function _artifact_str(
236+
__module__,
237+
artifacts_toml,
238+
name,
239+
path_tail,
240+
artifact_dict,
241+
hash,
242+
platform,
243+
_::Val{LazyArtifacts}
244+
) where LazyArtifacts
238245
# If the artifact exists, we're in the happy path and we can immediately
239246
# return the path to the artifact:
240247
dirs = artifacts_dirs(bytes2hex(hash.bytes))
@@ -248,28 +255,32 @@ let loaded = Base.loaded_modules_array()
248255
end
249256
end
250257

251-
Pkg = find_loaded_module(:Pkg)
258+
Pkg = find_loaded_root_module(Base.PkgId(
259+
Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
252260
if Pkg !== nothing
253261
@eval Pkg begin
254262
__init__() = rand() #TODO, methods that do nothing don't get codegened
255263
end
256264
end
257265

258-
StyledStrings = find_loaded_module(:StyledStrings)
266+
StyledStrings = find_loaded_root_module(Base.PkgId(
267+
Base.UUID("f489334b-da3d-4c2e-b8f0-e476e12c162b"), "StyledStrings"))
259268
if StyledStrings !== nothing
260269
@eval StyledStrings begin
261270
__init__() = rand()
262271
end
263272
end
264273

265-
Markdown = find_loaded_module(:Markdown)
274+
Markdown = find_loaded_root_module(Base.PkgId(
275+
Base.UUID("d6f4376e-aef5-505a-96c1-9c027394607a"), "Markdown"))
266276
if Markdown !== nothing
267277
@eval Markdown begin
268278
__init__() = rand()
269279
end
270280
end
271281

272-
JuliaSyntaxHighlighting = find_loaded_module(:JuliaSyntaxHighlighting)
282+
JuliaSyntaxHighlighting = find_loaded_root_module(Base.PkgId(
283+
Base.UUID("ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"), "JuliaSyntaxHighlighting"))
273284
if JuliaSyntaxHighlighting !== nothing
274285
@eval JuliaSyntaxHighlighting begin
275286
__init__() = rand()

0 commit comments

Comments
 (0)