Skip to content

Commit

Permalink
allow extensions to be loaded from non top level env (#48352)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jan 19, 2023
1 parent b029fbf commit 4cab76c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
1 change: 0 additions & 1 deletion base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,6 @@ function insert_extension_triggers(pkg::PkgId)
pkg.uuid === nothing && return
for env in load_path()
insert_extension_triggers(env, pkg)
break # For now, only insert triggers for packages in the first load_path.
end
end

Expand Down
43 changes: 28 additions & 15 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1000,24 +1000,37 @@ end
try
tmp = mktempdir()
push!(empty!(DEPOT_PATH), joinpath(tmp, "depot"))

proj = joinpath(@__DIR__, "project", "Extensions", "HasDepWithExtensions.jl")
for compile in (`--compiled-modules=no`, ``, ``) # Once when requiring precomilation, once where it is already precompiled
cmd = `$(Base.julia_cmd()) $compile --project=$proj --startup-file=no -e '
begin
using HasExtensions
# Base.get_extension(HasExtensions, :Extension) === nothing || error("unexpectedly got an extension")
HasExtensions.ext_loaded && error("ext_loaded set")
using HasDepWithExtensions
# Base.get_extension(HasExtensions, :Extension).extvar == 1 || error("extvar in Extension not set")
HasExtensions.ext_loaded || error("ext_loaded not set")
HasExtensions.ext_folder_loaded && error("ext_folder_loaded set")
HasDepWithExtensions.do_something() || error("do_something errored")
using ExtDep2
HasExtensions.ext_folder_loaded || error("ext_folder_loaded not set")

function gen_extension_cmd(compile)
```$(Base.julia_cmd()) $compile --startup-file=no -e '
begin
using HasExtensions
# Base.get_extension(HasExtensions, :Extension) === nothing || error("unexpectedly got an extension")
HasExtensions.ext_loaded && error("ext_loaded set")
using HasDepWithExtensions
# Base.get_extension(HasExtensions, :Extension).extvar == 1 || error("extvar in Extension not set")
HasExtensions.ext_loaded || error("ext_loaded not set")
HasExtensions.ext_folder_loaded && error("ext_folder_loaded set")
HasDepWithExtensions.do_something() || error("do_something errored")
using ExtDep2
HasExtensions.ext_folder_loaded || error("ext_folder_loaded not set")
end
'`
'
```
end

for compile in (`--compiled-modules=no`, ``, ``) # Once when requiring precomilation, once where it is already precompiled
cmd = gen_extension_cmd(compile)
withenv("JULIA_LOAD_PATH" => proj) do
@test success(cmd)
end
end

# 48351
sep = Sys.iswindows() ? ';' : ':'
withenv("JULIA_LOAD_PATH" => join([mktempdir(), proj], sep)) do
cmd = gen_extension_cmd(``)
@test success(cmd)
end
finally
Expand Down

0 comments on commit 4cab76c

Please sign in to comment.