From 3a4ea5566fb8143054b5c0feb17b340901e7dd15 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Sat, 28 Mar 2020 07:01:43 -0500 Subject: [PATCH] Set path before executing require block (#453) Fixes #442 --- src/pkgs.jl | 16 +++++++++++++++- test/pkgs/Dep442A/Project.toml | 4 ++++ test/pkgs/Dep442A/src/Dep442A.jl | 7 +++++++ test/pkgs/Dep442B/Project.toml | 7 +++++++ test/pkgs/Dep442B/src/Dep442B.jl | 18 ++++++++++++++++++ test/pkgs/Dep442B/src/support_442A.jl | 1 + test/pkgs/Pkg442/Project.toml | 8 ++++++++ test/pkgs/Pkg442/src/Pkg442.jl | 10 ++++++++++ test/runtests.jl | 10 ++++++++++ 9 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 test/pkgs/Dep442A/Project.toml create mode 100644 test/pkgs/Dep442A/src/Dep442A.jl create mode 100644 test/pkgs/Dep442B/Project.toml create mode 100644 test/pkgs/Dep442B/src/Dep442B.jl create mode 100644 test/pkgs/Dep442B/src/support_442A.jl create mode 100644 test/pkgs/Pkg442/Project.toml create mode 100644 test/pkgs/Pkg442/src/Pkg442.jl diff --git a/src/pkgs.jl b/src/pkgs.jl index ae294e23..17a2ec87 100644 --- a/src/pkgs.jl +++ b/src/pkgs.jl @@ -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 diff --git a/test/pkgs/Dep442A/Project.toml b/test/pkgs/Dep442A/Project.toml new file mode 100644 index 00000000..eb42e8c6 --- /dev/null +++ b/test/pkgs/Dep442A/Project.toml @@ -0,0 +1,4 @@ +name = "Dep442A" +uuid = "76238f47-ed95-4e4a-a4d9-95a3fb1630ea" +authors = ["Tim Holy "] +version = "0.1.0" diff --git a/test/pkgs/Dep442A/src/Dep442A.jl b/test/pkgs/Dep442A/src/Dep442A.jl new file mode 100644 index 00000000..6989bba6 --- /dev/null +++ b/test/pkgs/Dep442A/src/Dep442A.jl @@ -0,0 +1,7 @@ +module Dep442A + +export check442A + +check442A() = true + +end # module diff --git a/test/pkgs/Dep442B/Project.toml b/test/pkgs/Dep442B/Project.toml new file mode 100644 index 00000000..038e2192 --- /dev/null +++ b/test/pkgs/Dep442B/Project.toml @@ -0,0 +1,7 @@ +name = "Dep442B" +uuid = "880097ba-c503-4edb-bd3f-4c6394f19e96" +authors = ["Tim Holy "] +version = "0.1.0" + +[deps] +Requires = "ae029012-a4dd-5104-9daa-d747884805df" diff --git a/test/pkgs/Dep442B/src/Dep442B.jl b/test/pkgs/Dep442B/src/Dep442B.jl new file mode 100644 index 00000000..7241444d --- /dev/null +++ b/test/pkgs/Dep442B/src/Dep442B.jl @@ -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 diff --git a/test/pkgs/Dep442B/src/support_442A.jl b/test/pkgs/Dep442B/src/support_442A.jl new file mode 100644 index 00000000..4ceac6a4 --- /dev/null +++ b/test/pkgs/Dep442B/src/support_442A.jl @@ -0,0 +1 @@ +has442A() = true diff --git a/test/pkgs/Pkg442/Project.toml b/test/pkgs/Pkg442/Project.toml new file mode 100644 index 00000000..a42619fe --- /dev/null +++ b/test/pkgs/Pkg442/Project.toml @@ -0,0 +1,8 @@ +name = "Pkg442" +uuid = "753a5fd8-985c-4be4-bc89-999c80d1e0e5" +authors = ["Tim Holy "] +version = "0.1.0" + +[deps] +Dep442A = "76238f47-ed95-4e4a-a4d9-95a3fb1630ea" +Dep442B = "880097ba-c503-4edb-bd3f-4c6394f19e96" diff --git a/test/pkgs/Pkg442/src/Pkg442.jl b/test/pkgs/Pkg442/src/Pkg442.jl new file mode 100644 index 00000000..8dbca00d --- /dev/null +++ b/test/pkgs/Pkg442/src/Pkg442.jl @@ -0,0 +1,10 @@ +module Pkg442 + +using Dep442A +using Dep442B + +export check442 + +check442() = true + +end # module diff --git a/test/runtests.jl b/test/runtests.jl index d9a2cb4e..83b1aaf7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)