@@ -413,7 +413,9 @@ function locate_package_env(pkg::PkgId, stopenv::Union{String, Nothing}=nothing)
413
413
@goto done
414
414
end
415
415
end
416
- stopenv == env && @goto done
416
+ if ! (loading_extension || precompiling_extension)
417
+ stopenv == env && @goto done
418
+ end
417
419
end
418
420
else
419
421
for env in load_path ()
@@ -428,7 +430,9 @@ function locate_package_env(pkg::PkgId, stopenv::Union{String, Nothing}=nothing)
428
430
path = entry_path (path, pkg. name)
429
431
@goto done
430
432
end
431
- stopenv == env && break
433
+ if ! (loading_extension || precompiling_extension)
434
+ stopenv == env && break
435
+ end
432
436
end
433
437
# Allow loading of stdlibs if the name/uuid are given
434
438
# e.g. if they have been explicitly added to the project/manifest
@@ -619,6 +623,24 @@ function manifest_deps_get(env::String, where::PkgId, name::String)::Union{Nothi
619
623
pkg_uuid = explicit_project_deps_get (project_file, name)
620
624
return PkgId (pkg_uuid, name)
621
625
end
626
+ d = parsed_toml (project_file)
627
+ exts = get (d, " extensions" , nothing ):: Union{Dict{String, Any}, Nothing}
628
+ if exts != = nothing
629
+ # Check if `where` is an extension of the project
630
+ if where . name in keys (exts) && where . uuid == uuid5 (proj. uuid, where . name)
631
+ # Extensions can load weak deps...
632
+ weakdeps = get (d, " weakdeps" , nothing ):: Union{Dict{String, Any}, Nothing}
633
+ if weakdeps != = nothing
634
+ wuuid = get (weakdeps, name, nothing ):: Union{String, Nothing}
635
+ if wuuid != = nothing
636
+ return PkgId (UUID (wuuid), name)
637
+ end
638
+ end
639
+ # ... and they can load same deps as the project itself
640
+ mby_uuid = explicit_project_deps_get (project_file, name)
641
+ mby_uuid === nothing || return PkgId (mby_uuid, name)
642
+ end
643
+ end
622
644
# look for manifest file and `where` stanza
623
645
return explicit_manifest_deps_get (project_file, where , name)
624
646
elseif project_file
@@ -636,6 +658,8 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
636
658
# if `pkg` matches the project, return the project itself
637
659
return project_file_path (project_file)
638
660
end
661
+ mby_ext = project_file_ext_path (project_file, pkg. name)
662
+ mby_ext === nothing || return mby_ext
639
663
# look for manifest file and `where` stanza
640
664
return explicit_manifest_uuid_path (project_file, pkg)
641
665
elseif project_file
@@ -645,6 +669,25 @@ function manifest_uuid_path(env::String, pkg::PkgId)::Union{Nothing,String,Missi
645
669
return nothing
646
670
end
647
671
672
+
673
+ function find_ext_path (project_path:: String , extname:: String )
674
+ extfiledir = joinpath (project_path, " ext" , extname, extname * " .jl" )
675
+ isfile (extfiledir) && return extfiledir
676
+ return joinpath (project_path, " ext" , extname * " .jl" )
677
+ end
678
+
679
+ function project_file_ext_path (project_file:: String , name:: String )
680
+ d = parsed_toml (project_file)
681
+ p = project_file_path (project_file)
682
+ exts = get (d, " extensions" , nothing ):: Union{Dict{String, Any}, Nothing}
683
+ if exts != = nothing
684
+ if name in keys (exts)
685
+ return find_ext_path (p, name)
686
+ end
687
+ end
688
+ return nothing
689
+ end
690
+
648
691
# find project file's top-level UUID entry (or nothing)
649
692
function project_file_name_uuid (project_file:: String , name:: String ):: PkgId
650
693
d = parsed_toml (project_file)
@@ -876,9 +919,7 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No
876
919
error (" failed to find source of parent package: \" $name \" " )
877
920
end
878
921
p = normpath (dirname (parent_path), " .." )
879
- extfiledir = joinpath (p, " ext" , pkg. name, pkg. name * " .jl" )
880
- isfile (extfiledir) && return extfiledir
881
- return joinpath (p, " ext" , pkg. name * " .jl" )
922
+ return find_ext_path (p, pkg. name)
882
923
end
883
924
end
884
925
end
@@ -1126,6 +1167,18 @@ end
1126
1167
function insert_extension_triggers (env:: String , pkg:: PkgId ):: Union{Nothing,Missing}
1127
1168
project_file = env_project_file (env)
1128
1169
if project_file isa String
1170
+ # Look in project for extensions to insert
1171
+ proj_pkg = project_file_name_uuid (project_file, pkg. name)
1172
+ if pkg == proj_pkg
1173
+ d_proj = parsed_toml (project_file)
1174
+ weakdeps = get (d_proj, " weakdeps" , nothing ):: Union{Nothing, Vector{String}, Dict{String,Any}}
1175
+ extensions = get (d_proj, " extensions" , nothing ):: Union{Nothing, Dict{String, Any}}
1176
+ extensions === nothing && return
1177
+ weakdeps === nothing && return
1178
+ return _insert_extension_triggers (pkg, extensions, weakdeps)
1179
+ end
1180
+
1181
+ # Now look in manifest
1129
1182
manifest_file = project_file_manifest_path (project_file)
1130
1183
manifest_file === nothing && return
1131
1184
d = get_deps (parsed_toml (manifest_file))
@@ -1190,6 +1243,7 @@ function _insert_extension_triggers(parent::PkgId, extensions::Dict{String, <:An
1190
1243
end
1191
1244
1192
1245
loading_extension:: Bool = false
1246
+ precompiling_extension:: Bool = false
1193
1247
function run_extension_callbacks (extid:: ExtensionId )
1194
1248
assert_havelock (require_lock)
1195
1249
succeeded = try
@@ -1217,30 +1271,8 @@ function run_extension_callbacks(pkgid::PkgId)
1217
1271
extids === nothing && return
1218
1272
for extid in extids
1219
1273
if extid. ntriggers > 0
1220
- # It is possible that pkgid was loaded in an environment
1221
- # below the one of the parent. This will cause a load failure when the
1222
- # pkg ext tries to load the triggers. Therefore, check this first
1223
- # before loading the pkg ext.
1224
- pkgenv = identify_package_env (extid. id, pkgid. name)
1225
- ext_not_allowed_load = false
1226
- if pkgenv === nothing
1227
- ext_not_allowed_load = true
1228
- else
1229
- pkg, env = pkgenv
1230
- path = locate_package (pkg, env)
1231
- if path === nothing
1232
- ext_not_allowed_load = true
1233
- end
1234
- end
1235
- if ext_not_allowed_load
1236
- @debug " Extension $(extid. id. name) of $(extid. parentid. name) will not be loaded \
1237
- since $(pkgid. name) loaded in environment lower in load path"
1238
- # indicate extid is expected to fail
1239
- extid. ntriggers *= - 1
1240
- else
1241
- # indicate pkgid is loaded
1242
- extid. ntriggers -= 1
1243
- end
1274
+ # indicate pkgid is loaded
1275
+ extid. ntriggers -= 1
1244
1276
end
1245
1277
if extid. ntriggers < 0
1246
1278
# indicate pkgid is loaded
@@ -2066,6 +2098,7 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
2066
2098
# write data over stdin to avoid the (unlikely) case of exceeding max command line size
2067
2099
write (io. in, """
2068
2100
empty!(Base.EXT_DORMITORY) # If we have a custom sysimage with `EXT_DORMITORY` prepopulated
2101
+ Base.precompiling_extension = $(loading_extension)
2069
2102
Base.include_package_for_output($(pkg_str (pkg)) , $(repr (abspath (input))) , $(repr (depot_path)) , $(repr (dl_load_path)) ,
2070
2103
$(repr (load_path)) , $deps , $(repr (source_path (nothing ))) )
2071
2104
""" )
0 commit comments