Skip to content

Commit 51b54a7

Browse files
authored
Merge pull request #114 from JuliaTesting/td-test-env-subprojects
Fix TestEnv for subpackages: precompile only the new test Project, take 2 Like #90, but uses Pkg._auto_precompile instead of Pkg.precompile to respect the JULIA_PKG_PRECOMPILE_AUTO env var.
2 parents 09933b2 + dcc3ee3 commit 51b54a7

10 files changed

Lines changed: 93 additions & 17 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "TestEnv"
22
uuid = "1e6cf692-eddd-4d53-88a5-2d735e33781b"
3-
version = "1.103.4"
3+
version = "1.103.5"
44

55
[deps]
66
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

src/julia-1.11/activate_set.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)
8484
@debug "Using _clean_ dep graph"
8585
end
8686

87+
# Now that we have set up the sandbox environment, precompile all its packages:
88+
# (Reconnect the `io` back to the original context so the caller can see the
89+
# precompilation progress.)
90+
Pkg._auto_precompile(temp_ctx; already_instantiated=true)
91+
8792
write_env(temp_ctx.env; update_undo=false)
8893

8994
return Base.active_project()

src/julia-1.11/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function ctx_and_pkgspec(pkg::AbstractString)
2222
pkgspec = deepcopy(PackageSpec(pkg))
2323
ctx = Context()
2424
isinstalled!(ctx, pkgspec) || throw(TestEnvError("$pkg not installed 👻"))
25-
Pkg.instantiate(ctx)
25+
Pkg.instantiate(ctx; allow_autoprecomp=false)
2626
return ctx, pkgspec
2727
end
2828

src/julia-1.12/activate_set.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)
8484
@debug "Using _clean_ dep graph"
8585
end
8686

87+
# Now that we have set up the sandbox environment, precompile all its packages:
88+
# (Reconnect the `io` back to the original context so the caller can see the
89+
# precompilation progress.)
90+
Pkg._auto_precompile(temp_ctx; already_instantiated=true)
91+
8792
write_env(temp_ctx.env; update_undo=false)
8893

8994
return Base.active_project()

src/julia-1.12/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function ctx_and_pkgspec(pkg::AbstractString)
2222
pkgspec = deepcopy(PackageSpec(pkg))
2323
ctx = Context()
2424
isinstalled!(ctx, pkgspec) || throw(TestEnvError("$pkg not installed 👻"))
25-
Pkg.instantiate(ctx)
25+
Pkg.instantiate(ctx; allow_autoprecomp=false)
2626
return ctx, pkgspec
2727
end
2828

src/julia-1.13/activate_set.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)
8484
@debug "Using _clean_ dep graph"
8585
end
8686

87+
# Now that we have set up the sandbox environment, precompile all its packages:
88+
# (Reconnect the `io` back to the original context so the caller can see the
89+
# precompilation progress.)
90+
Pkg._auto_precompile(temp_ctx; already_instantiated=true)
91+
8792
write_env(temp_ctx.env; update_undo=false)
8893

8994
return Base.active_project()

src/julia-1.13/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function ctx_and_pkgspec(pkg::AbstractString)
2222
pkgspec = deepcopy(PackageSpec(pkg))
2323
ctx = Context()
2424
isinstalled!(ctx, pkgspec) || throw(TestEnvError("$pkg not installed 👻"))
25-
Pkg.instantiate(ctx)
25+
Pkg.instantiate(ctx; allow_autoprecomp=false)
2626
return ctx, pkgspec
2727
end
2828

src/julia-1.9/activate_set.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ function activate(pkg::AbstractString=current_pkg_name(); allow_reresolve=true)
6969
@debug "Using _clean_ dep graph"
7070
end
7171

72+
# Now that we have set up the sandbox environment, precompile all its packages:
73+
# (Reconnect the `io` back to the original context so the caller can see the
74+
# precompilation progress.)
75+
Pkg._auto_precompile(temp_ctx; already_instantiated=true)
76+
7277
write_env(temp_ctx.env; update_undo=false)
7378

7479
return Base.active_project()

src/julia-1.9/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function ctx_and_pkgspec(pkg::AbstractString)
2222
pkgspec = deepcopy(PackageSpec(pkg))
2323
ctx = Context()
2424
isinstalled!(ctx, pkgspec) || throw(TestEnvError("$pkg not installed 👻"))
25-
Pkg.instantiate(ctx)
25+
Pkg.instantiate(ctx; allow_autoprecomp=false)
2626
return ctx, pkgspec
2727
end
2828

test/activate_set.jl

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
Pkg.add(PackageSpec(name="ChainRulesCore", version="1.0.2"))
66

77
orig_project_toml_path = Base.active_project()
8+
orig_load_path = copy(LOAD_PATH)
89
push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing
9-
orig_load_path = Base.LOAD_PATH
1010
try
1111
TestEnv.activate("ChainRulesCore")
1212
new_project_toml_path = Base.active_project()
1313
@test new_project_toml_path != orig_project_toml_path
14-
@test orig_load_path == Base.LOAD_PATH
1514

1615
@eval using StaticArrays # From ChainRulesCore [extras] Project.toml
1716
@test Base.invokelatest(isdefined, @__MODULE__, :StaticArrays)
@@ -22,6 +21,8 @@
2221
Pkg.activate(orig_project_toml_path)
2322
# No longer is enviroment active
2423
@test_throws ArgumentError @eval using OffsetArrays
24+
pop!(LOAD_PATH)
25+
@test orig_load_path == LOAD_PATH
2526
end
2627
end
2728
end
@@ -34,8 +35,8 @@
3435
Pkg.add(PackageSpec(name="YAXArrays", version="0.1.3"))
3536

3637
orig_project_toml_path = Base.active_project()
38+
orig_load_path = copy(LOAD_PATH)
3739
push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing
38-
orig_load_path = Base.LOAD_PATH
3940
try
4041
# YAXArrays has a test/Project.toml, which contains CSV
4142
if VERSION >= v"1.8-"
@@ -46,20 +47,21 @@
4647
TestEnv.activate("YAXArrays"; kw...)
4748
new_project_toml_path = Base.active_project()
4849
@test new_project_toml_path != orig_project_toml_path
49-
@test orig_load_path == Base.LOAD_PATH
5050

5151
@eval using CSV
5252
@test Base.invokelatest(isdefined, @__MODULE__, :CSV)
5353

5454
finally
5555
Pkg.activate(orig_project_toml_path)
56+
pop!(LOAD_PATH)
57+
@test orig_load_path == LOAD_PATH
5658
end
5759
elseif VERSION >= v"1.2-"
5860
Pkg.add(PackageSpec(name="ConstraintSolver", version="0.6.10"))
5961

6062
orig_project_toml_path = Base.active_project()
63+
orig_load_path = copy(LOAD_PATH)
6164
push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing
62-
orig_load_path = Base.LOAD_PATH
6365
try
6466
# ConstraintSolver has a test/Project.toml, which contains CSV
6567
if VERSION >= v"1.8-"
@@ -70,13 +72,14 @@
7072
TestEnv.activate("ConstraintSolver"; kw...)
7173
new_project_toml_path = Base.active_project()
7274
@test new_project_toml_path != orig_project_toml_path
73-
@test orig_load_path == Base.LOAD_PATH
7475

7576
@eval using JSON
7677
@test Base.invokelatest(isdefined, @__MODULE__, :JSON)
7778

7879
finally
7980
Pkg.activate(orig_project_toml_path)
81+
pop!(LOAD_PATH)
82+
@test orig_load_path == LOAD_PATH
8083
end
8184
end
8285
end
@@ -90,56 +93,109 @@
9093
if VERSION >= v"1.11"
9194
@testset "activate with [sources]" begin
9295
orig_project_toml_path = Base.active_project()
96+
orig_load_path = copy(LOAD_PATH)
9397
push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing
94-
orig_load_path = Base.LOAD_PATH
9598
try
9699
Pkg.activate(joinpath(@__DIR__, "sources", "MainEnv"))
97100
TestEnv.activate()
98101
new_project_toml_path = Base.active_project()
99102
@test new_project_toml_path != orig_project_toml_path
100-
@test orig_load_path == Base.LOAD_PATH
101103
@eval using MainEnv
102104
@test isdefined(@__MODULE__, :MainEnv)
103105
@test MainEnv.bar() == 42
104106
finally
105107
Pkg.activate(orig_project_toml_path)
108+
pop!(LOAD_PATH)
109+
@test orig_load_path == LOAD_PATH
106110
end
107111
end
108112
@testset "activate with [sources] and two Project.toml approach" begin
109113
orig_project_toml_path = Base.active_project()
114+
orig_load_path = copy(LOAD_PATH)
110115
push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing
111-
orig_load_path = Base.LOAD_PATH
112116
try
113117
Pkg.activate(joinpath(@__DIR__, "sources", "MainTestProjectEnv"))
114118
TestEnv.activate()
115119
new_project_toml_path = Base.active_project()
116120
@test new_project_toml_path != orig_project_toml_path
117-
@test orig_load_path == Base.LOAD_PATH
118121
@eval using MainTestProjectEnv
119122
@test isdefined(@__MODULE__, :MainTestProjectEnv)
120123
@test MainTestProjectEnv.bar() == 42
121124
finally
122125
Pkg.activate(orig_project_toml_path)
126+
pop!(LOAD_PATH)
127+
@test orig_load_path == LOAD_PATH
123128
end
124129
end
125130
end
126131

127132
if VERSION >= v"1.12-"
128133
@testset "activate [workspace] test env" begin
129134
orig_project_toml_path = Base.active_project()
135+
orig_load_path = copy(LOAD_PATH)
130136
push!(LOAD_PATH, mktempdir()) # put something weird in LOAD_PATH for testing
131-
orig_load_path = Base.LOAD_PATH
132137
try
133138
Pkg.activate(joinpath(@__DIR__, "sources", "WorkspaceTestEnv"))
134139
TestEnv.activate()
135140
new_project_toml_path = Base.active_project()
136141
@test new_project_toml_path != orig_project_toml_path
137-
@test orig_load_path == Base.LOAD_PATH
138142
@eval using WorkspaceTestEnv
139143
@test isdefined(@__MODULE__, :WorkspaceTestEnv)
140144
@test WorkspaceTestEnv.foo() == 42
141145
finally
142146
Pkg.activate(orig_project_toml_path)
147+
pop!(LOAD_PATH)
148+
@test orig_load_path == LOAD_PATH
149+
end
150+
end
151+
end
152+
153+
if VERSION >= v"1.6" # JULIA_PKG_PRECOMPILE_AUTO was introduced in 1.6
154+
@testset "JULIA_PKG_PRECOMPILE_AUTO compatibility" begin
155+
mktempdir() do p
156+
withenv("JULIA_PKG_PRECOMPILE_AUTO" => "0") do
157+
orig_load_path = copy(LOAD_PATH)
158+
push!(empty!(LOAD_PATH), p)
159+
160+
# Restrict the depot path to avoid grabbing a precompiled version from a
161+
# stacked environment
162+
orig_depot_path = copy(DEPOT_PATH)
163+
push!(empty!(DEPOT_PATH), mkdir(joinpath(p, ".julia")))
164+
165+
try
166+
Pkg.activate(p)
167+
orig_project_toml_path = Base.active_project()
168+
try
169+
Pkg.develop(PackageSpec(path=pkgdir(TestEnv)))
170+
Pkg.add(PackageSpec(name="Example"))
171+
try
172+
TestEnv.activate("Example")
173+
if VERSION < v"1.10" # Base.isprecompiled was added in 1.10
174+
cache_dir = Base.compilecache_dir(Base.identify_package("Example"))
175+
@test !isdir(cache_dir) || isempty(readdir(cache_dir))
176+
else
177+
@test !Base.isprecompiled(Base.identify_package("Example"))
178+
end
179+
catch e
180+
@error "Error during TestEnv.activate/isprecompiled check" exception=(e, catch_backtrace())
181+
@test false
182+
end
183+
new_project_toml_path = Base.active_project()
184+
@test new_project_toml_path != orig_project_toml_path
185+
finally
186+
Pkg.activate(orig_project_toml_path)
187+
end
188+
finally
189+
if isdefined(@__MODULE__, :orig_load_path)
190+
pop!(LOAD_PATH)
191+
append!(LOAD_PATH, orig_load_path)
192+
end
193+
if isdefined(@__MODULE__, :orig_depot_path)
194+
pop!(DEPOT_PATH)
195+
append!(DEPOT_PATH, orig_depot_path)
196+
end
197+
end
198+
end
143199
end
144200
end
145201
end

0 commit comments

Comments
 (0)