227227end
228228
229229
230+ # Setup to rm a depot. On Windows, this needs to be delayed as in-use DLLs cannot be removed.
231+ if Sys. iswindows ()
232+ const DEPOTS_TOREMOVE = String[]
233+ atexit () do # launch a process that will rm the depots
234+ rmcmd = """
235+ for _ in 1:3600 # wait up to 1h from atexit() until the julia testing process dies
236+ sleep(1)
237+ ccall(:uv_kill, Cint, (Cuint, Cint), $(getpid ()) , 0) == Base.UV_ESRCH && break
238+ end
239+ for path in $DEPOTS_TOREMOVE
240+ try
241+ rm(path, force=true, recursive=true)
242+ catch
243+ end
244+ end
245+ """
246+ cmd = Cmd (` $(Base. julia_cmd ()) --startup-file=no -e $rmcmd ` ; ignorestatus= true , detach= true )
247+ run (cmd; wait= false )
248+ end
249+ end
250+ function rmdepot (depot)
251+ try
252+ @static if Sys. iswindows ()
253+ push! (DEPOTS_TOREMOVE, depot)
254+ else
255+ rm (depot, force= true , recursive= true )
256+ end
257+ catch err
258+ @show err
259+ end
260+ end
261+
262+ function mkdepottempdir (f:: Function , parent= tempdir (); prefix= " jltestdepot_" )
263+ tmpdir = mktempdir (parent; prefix, cleanup= false )
264+ try
265+ f (tmpdir)
266+ finally
267+ rmdepot (tmpdir)
268+ end
269+ end
270+ mkdepottempdir (parent= tempdir (); prefix= " jltestdepot_" ) = mktempdir (parent; prefix, cleanup= ! Sys. iswindows ())
271+
272+
230273# # functional testing of package identification, location & loading ##
231274
232275saved_load_path = copy (LOAD_PATH )
@@ -237,7 +280,8 @@ push!(Base.active_project_callbacks, () -> watcher_counter[] += 1)
237280push! (Base. active_project_callbacks, () -> error (" broken" ))
238281
239282push! (empty! (LOAD_PATH ), joinpath (@__DIR__ , " project" ))
240- append! (empty! (DEPOT_PATH ), [mktempdir (), joinpath (@__DIR__ , " depot" )])
283+ const testdefaultdepot = mkdepottempdir ()
284+ append! (empty! (DEPOT_PATH ), [testdefaultdepot, joinpath (@__DIR__ , " depot" )])
241285@test watcher_counter[] == 0
242286@test_logs (:error , r" active project callback .* failed" ) Base. set_active_project (nothing )
243287@test watcher_counter[] == 1
@@ -374,6 +418,8 @@ module NotPkgModule; end
374418
375419end
376420
421+ rmdepot (testdefaultdepot)
422+
377423# # systematic generation of test environments ##
378424
379425const M = 3 # number of node names
@@ -461,7 +507,7 @@ function make_env(flat, root, roots, graph, paths, dummies)
461507 )
462508end
463509
464- const depots = [mktempdir () for _ = 1 : 3 ]
510+ const depots = [mkdepottempdir () for _ = 1 : 3 ]
465511const envs = Dict {String,Any} ()
466512
467513append! (empty! (DEPOT_PATH ), depots)
@@ -756,11 +802,7 @@ for env in keys(envs)
756802 rm (env, force= true , recursive= true )
757803end
758804for depot in depots
759- try
760- rm (depot, force= true , recursive= true )
761- catch err
762- @show err
763- end
805+ rmdepot (depot)
764806end
765807
766808append! (empty! (LOAD_PATH ), saved_load_path)
@@ -1043,7 +1085,7 @@ end
10431085 _pkgversion == pkgversion(parent) || error("unexpected extension \$ ext version: \$ _pkgversion")
10441086 end
10451087 """
1046- depot_path = mktempdir ()
1088+ depot_path = mkdepottempdir ()
10471089 try
10481090 proj = joinpath (@__DIR__ , " project" , " Extensions" , " HasDepWithExtensions.jl" )
10491091
@@ -1155,7 +1197,7 @@ end
11551197
11561198 # Extension-to-extension dependencies
11571199
1158- mktempdir () do depot # Parallel pre-compilation
1200+ mkdepottempdir () do depot # Parallel pre-compilation
11591201 code = """
11601202 Base.disable_parallel_precompile = false
11611203 using ExtToExtDependency
@@ -1171,7 +1213,7 @@ end
11711213 )
11721214 @test occursin (" Hello ext-to-ext!" , String (read (cmd)))
11731215 end
1174- mktempdir () do depot # Serial pre-compilation
1216+ mkdepottempdir () do depot # Serial pre-compilation
11751217 code = """
11761218 Base.disable_parallel_precompile = true
11771219 using ExtToExtDependency
@@ -1188,7 +1230,7 @@ end
11881230 @test occursin (" Hello ext-to-ext!" , String (read (cmd)))
11891231 end
11901232
1191- mktempdir () do depot # Parallel pre-compilation
1233+ mkdepottempdir () do depot # Parallel pre-compilation
11921234 code = """
11931235 Base.disable_parallel_precompile = false
11941236 using CrossPackageExtToExtDependency
@@ -1204,7 +1246,7 @@ end
12041246 )
12051247 @test occursin (" Hello x-package ext-to-ext!" , String (read (cmd)))
12061248 end
1207- mktempdir () do depot # Serial pre-compilation
1249+ mkdepottempdir () do depot # Serial pre-compilation
12081250 code = """
12091251 Base.disable_parallel_precompile = true
12101252 using CrossPackageExtToExtDependency
@@ -1224,7 +1266,7 @@ end
12241266 # Extensions for "parent" dependencies
12251267 # (i.e. an `ExtAB` where A depends on / loads B, but B provides the extension)
12261268
1227- mktempdir () do depot # Parallel pre-compilation
1269+ mkdepottempdir () do depot # Parallel pre-compilation
12281270 code = """
12291271 Base.disable_parallel_precompile = false
12301272 using Parent
@@ -1239,7 +1281,7 @@ end
12391281 )
12401282 @test occursin (" Hello parent!" , String (read (cmd)))
12411283 end
1242- mktempdir () do depot # Serial pre-compilation
1284+ mkdepottempdir () do depot # Serial pre-compilation
12431285 code = """
12441286 Base.disable_parallel_precompile = true
12451287 using Parent
@@ -1256,11 +1298,7 @@ end
12561298 end
12571299
12581300 finally
1259- try
1260- rm (depot_path, force= true , recursive= true )
1261- catch err
1262- @show err
1263- end
1301+ rmdepot (depot_path)
12641302 end
12651303end
12661304
@@ -1364,7 +1402,7 @@ end
13641402end
13651403
13661404@testset " relocatable upgrades #51989" begin
1367- mktempdir () do depot
1405+ mkdepottempdir () do depot
13681406 # realpath is needed because Pkg is used for one of the precompile paths below, and Pkg calls realpath on the
13691407 # project path so the cache file slug will be different if the tempdir is given as a symlink
13701408 # (which it often is on MacOS) which would break the test.
@@ -1438,7 +1476,7 @@ end
14381476end
14391477
14401478@testset " code coverage disabled during precompilation" begin
1441- mktempdir () do depot
1479+ mkdepottempdir () do depot
14421480 cov_test_dir = joinpath (@__DIR__ , " project" , " deps" , " CovTest.jl" )
14431481 cov_cache_dir = joinpath (depot, " compiled" , " v$(VERSION . major) .$(VERSION . minor) " , " CovTest" )
14441482 function rm_cov_files ()
@@ -1482,7 +1520,7 @@ end
14821520end
14831521
14841522@testset " command-line flags" begin
1485- mktempdir () do depot_path mktempdir () do dir
1523+ mkdepottempdir () do depot_path mktempdir () do dir
14861524 # generate a Parent.jl and Child.jl package, with Parent depending on Child
14871525 open (joinpath (dir, " Child.jl" ), " w" ) do io
14881526 println (io, """
@@ -1565,7 +1603,7 @@ end
15651603end
15661604
15671605@testset " including non-existent file throws proper error #52462" begin
1568- mktempdir () do depot
1606+ mkdepottempdir () do depot
15691607 project_path = joinpath (depot, " project" )
15701608 mkpath (project_path)
15711609
@@ -1707,7 +1745,7 @@ end
17071745end
17081746
17091747@testset " require_stdlib loading duplication" begin
1710- depot_path = mktempdir ()
1748+ depot_path = mkdepottempdir ()
17111749 oldBase64 = nothing
17121750 try
17131751 push! (empty! (DEPOT_PATH ), depot_path)
@@ -1731,7 +1769,7 @@ end
17311769 finally
17321770 oldBase64 === nothing || Base. register_root_module (oldBase64)
17331771 copy! (DEPOT_PATH , original_depot_path)
1734- rm (depot_path, force = true , recursive = true )
1772+ rmdepot (depot_path)
17351773 end
17361774end
17371775
0 commit comments