Skip to content

Commit

Permalink
Set path before executing require block (#453)
Browse files Browse the repository at this point in the history
Fixes #442
  • Loading branch information
timholy committed Mar 28, 2020
1 parent 1c9411d commit 3a4ea55
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/pkgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,21 @@ function add_require(sourcefile, modcaller, idmod, modname, expr)
exsnew = ExprsSigs()
exsnew[expr] = nothing
mexsnew = ModuleExprsSigs(modcaller=>exsnew)
mexsnew, includes = eval_new!(mexsnew, fi.modexsigs)
# Before executing the expression we need to set the load path appropriately
prev = Base.source_path(nothing)
tls = task_local_storage()
tls[:SOURCE_PATH] = sourcefile
# Now execute the expression
mexsnew, includes = try
eval_new!(mexsnew, fi.modexsigs)
finally
if prev === nothing
delete!(tls, :SOURCE_PATH)
else
tls[:SOURCE_PATH] = prev
end
end
# Add any new methods or `include`d files to tracked objects
pkgdata.fileinfos[fileidx] = FileInfo(mexsnew, fi)
maybe_add_includes_to_pkgdata!(pkgdata, filekey, includes)
end
Expand Down
4 changes: 4 additions & 0 deletions test/pkgs/Dep442A/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "Dep442A"
uuid = "76238f47-ed95-4e4a-a4d9-95a3fb1630ea"
authors = ["Tim Holy <[email protected]>"]
version = "0.1.0"
7 changes: 7 additions & 0 deletions test/pkgs/Dep442A/src/Dep442A.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Dep442A

export check442A

check442A() = true

end # module
7 changes: 7 additions & 0 deletions test/pkgs/Dep442B/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = "Dep442B"
uuid = "880097ba-c503-4edb-bd3f-4c6394f19e96"
authors = ["Tim Holy <[email protected]>"]
version = "0.1.0"

[deps]
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
18 changes: 18 additions & 0 deletions test/pkgs/Dep442B/src/Dep442B.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Dep442B

using Requires

export check442B

check442B() = true

function link_442A()
@debug "Loading 442A support into 442B"
include("support_442A.jl")
end

function __init__()
@require Dep442A="76238f47-ed95-4e4a-a4d9-95a3fb1630ea" link_442A()
end

end # module
1 change: 1 addition & 0 deletions test/pkgs/Dep442B/src/support_442A.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
has442A() = true
8 changes: 8 additions & 0 deletions test/pkgs/Pkg442/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name = "Pkg442"
uuid = "753a5fd8-985c-4be4-bc89-999c80d1e0e5"
authors = ["Tim Holy <[email protected]>"]
version = "0.1.0"

[deps]
Dep442A = "76238f47-ed95-4e4a-a4d9-95a3fb1630ea"
Dep442B = "880097ba-c503-4edb-bd3f-4c6394f19e96"
10 changes: 10 additions & 0 deletions test/pkgs/Pkg442/src/Pkg442.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Pkg442

using Dep442A
using Dep442B

export check442

check442() = true

end # module
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2722,6 +2722,16 @@ do_test("New files & Requires.jl") && @testset "New files & Requires.jl" begin
yry()
notified && @test TrackRequires2.othertestfunc() == -2

# Issue #442
push!(LOAD_PATH, joinpath(@__DIR__, "pkgs"))
@eval using Pkg442
sleep(0.01)
@test check442()
@test Pkg442.check442A()
@test Pkg442.check442B()
@test Pkg442.Dep442B.has442A()
pop!(LOAD_PATH)

rm_precompile("TrackRequires")
rm_precompile("TrackRequires2")
pop!(LOAD_PATH)
Expand Down

0 comments on commit 3a4ea55

Please sign in to comment.