@@ -17,10 +17,12 @@ function test_harness(@nospecialize(fn); empty_load_path=true, empty_depot_path=
1717 end
1818end
1919
20- # We test relocation with three dummy pkgs:
21- # - RelocationTestPkg1 - no include_dependency
22- # - RelocationTestPkg2 - with include_dependency tracked by `mtime`
23- # - RelocationTestPkg3 - with include_dependency tracked by content
20+ # We test relocation with these dummy pkgs:
21+ # - RelocationTestPkg1 - pkg with no include_dependency
22+ # - RelocationTestPkg2 - pkg with include_dependency tracked by `mtime`
23+ # - RelocationTestPkg3 - pkg with include_dependency tracked by content
24+ # - RelocationTestPkg4 - pkg with no dependencies; will be compiled such that the pkgimage is
25+ # not relocatable, but no repeated recompilation happens upon loading
2426
2527if ! test_relocated_depot
2628
@@ -123,6 +125,23 @@ if !test_relocated_depot
123125 end
124126 end
125127
128+ @testset " precompile RelocationTestPkg4" begin
129+ # test for #52346 and https://github.com/JuliaLang/julia/issues/53859#issuecomment-2027352004
130+ # If a pkgimage is not relocatable, no repeated precompilation should occur.
131+ pkgname = " RelocationTestPkg4"
132+ test_harness (empty_depot_path= false ) do
133+ push! (LOAD_PATH , @__DIR__ )
134+ # skip this dir to make the pkgimage not relocatable
135+ filter! (!= (@__DIR__ ), DEPOT_PATH )
136+ pkg = Base. identify_package (pkgname)
137+ cachefiles = Base. find_all_in_cache_path (pkg)
138+ rm .(cachefiles, force= true )
139+ @test Base. isprecompiled (pkg) == false
140+ Base. require (pkg)
141+ @test Base. isprecompiled (pkg, ignore_loaded= true ) == true
142+ end
143+ end
144+
126145 @testset " #52161" begin
127146 # Take the src files from two pkgs Example1 and Example2,
128147 # which are each located in depot1 and depot2, respectively, and
246265 pkgname = " RelocationTestPkg3"
247266 test_harness () do
248267 push! (LOAD_PATH , joinpath (@__DIR__ , " relocatedepot" ))
249- push! (DEPOT_PATH , joinpath (@__DIR__ , " relocatedepot" ))
268+ push! (DEPOT_PATH , joinpath (@__DIR__ , " relocatedepot" )) # required to find src files
250269 push! (DEPOT_PATH , joinpath (@__DIR__ , " relocatedepot" , " julia" )) # contains cache file
251270 pkg = Base. identify_package (pkgname)
252271 @test Base. isprecompiled (pkg) == true
@@ -257,4 +276,16 @@ else
257276 end
258277 end
259278
279+ @testset " load RelocationTestPkg4 from test/relocatedepot" begin
280+ pkgname = " RelocationTestPkg4"
281+ test_harness () do
282+ push! (LOAD_PATH , @__DIR__ , " relocatedepot" )
283+ push! (DEPOT_PATH , joinpath (@__DIR__ , " relocatedepot" )) # required to find src files
284+ push! (DEPOT_PATH , joinpath (@__DIR__ , " relocatedepot" , " julia" )) # contains cache file
285+ pkg = Base. identify_package (pkgname)
286+ # precompiled but not relocatable
287+ @test Base. isprecompiled (pkg) == true
288+ end
289+ end
290+
260291end
0 commit comments