-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make precompile files relocatable (#49866)
String replacement with `@depot` when serializing out happens with any paths that are located inside a `DEPOT_PATH` (first match wins). If no match, then we emit the absolute file path as before. Right now we only emit one token `@depot`. String replacement of `@depot` when loading happens now on a `.ji` file basis and only if all the listed include dependencies can be resolved to files located in one and the same depot on `DEPOT_PATH` (again, first match wins). If we can't resolve, then the cache is invalided with `stale_cachefile`.
- Loading branch information
1 parent
d432821
commit f2df1b4
Showing
18 changed files
with
360 additions
and
91 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
/ccalltest | ||
/ccalltest.s | ||
/libccalltest.* | ||
/relocatedepot | ||
/RelocationTestPkg2/src/foo.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = "RelocationTestPkg1" | ||
uuid = "854e1adb-5a97-46bf-a391-1cfe05ac726d" | ||
authors = ["flo "] | ||
version = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module RelocationTestPkg1 | ||
|
||
greet() = print("Hello World!") | ||
|
||
end # module RelocationTestPkg1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name = "RelocationTestPkg2" | ||
uuid = "8d933983-b090-4b0b-a37e-c34793f459d1" | ||
authors = ["flo "] | ||
version = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module RelocationTestPkg2 | ||
|
||
include_dependency("foo.txt") | ||
greet() = print("Hello World!") | ||
|
||
end # module RelocationTestPkg2 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using Test | ||
using Logging | ||
|
||
|
||
include("testenv.jl") | ||
|
||
|
||
function test_harness(@nospecialize(fn)) | ||
load_path = copy(LOAD_PATH) | ||
depot_path = copy(DEPOT_PATH) | ||
try | ||
fn() | ||
finally | ||
copy!(LOAD_PATH, load_path) | ||
copy!(DEPOT_PATH, depot_path) | ||
end | ||
end | ||
|
||
|
||
if !test_relocated_depot | ||
|
||
@testset "precompile RelocationTestPkg1" begin | ||
pkgname = "RelocationTestPkg1" | ||
test_harness() do | ||
push!(LOAD_PATH, @__DIR__) | ||
push!(DEPOT_PATH, @__DIR__) | ||
pkg = Base.identify_package(pkgname) | ||
cachefiles = Base.find_all_in_cache_path(pkg) | ||
rm.(cachefiles, force=true) | ||
@test Base.isprecompiled(pkg) == false | ||
Base.require(pkg) # precompile | ||
@test Base.isprecompiled(pkg, ignore_loaded=true) == true | ||
end | ||
end | ||
|
||
@testset "precompile RelocationTestPkg2 (contains include_dependency)" begin | ||
pkgname = "RelocationTestPkg2" | ||
test_harness() do | ||
push!(LOAD_PATH, @__DIR__) | ||
push!(DEPOT_PATH, @__DIR__) | ||
pkg = Base.identify_package(pkgname) | ||
cachefiles = Base.find_all_in_cache_path(pkg) | ||
rm.(cachefiles, force=true) | ||
@test Base.isprecompiled(pkg) == false | ||
touch(joinpath(@__DIR__, pkgname, "src", "foo.txt")) | ||
Base.require(pkg) # precompile | ||
@info "SERS OIDA" | ||
@test Base.isprecompiled(pkg, ignore_loaded=true) == true | ||
end | ||
end | ||
|
||
else | ||
|
||
# must come before any of the load tests, because the will recompile and generate new cache files | ||
@testset "attempt loading precompiled pkgs when depot is missing" begin | ||
test_harness() do | ||
empty!(LOAD_PATH) | ||
push!(LOAD_PATH, joinpath(@__DIR__, "relocatedepot")) | ||
for pkgname in ("RelocationTestPkg1", "RelocationTestPkg2") | ||
pkg = Base.identify_package(pkgname) | ||
cachefile = only(Base.find_all_in_cache_path(pkg)) | ||
@info cachefile | ||
@test_throws ArgumentError(""" | ||
Failed to determine depot from srctext files in cache file $cachefile. | ||
- Make sure you have adjusted DEPOT_PATH in case you relocated depots.""") Base.isprecompiled(pkg) | ||
end | ||
end | ||
end | ||
|
||
@testset "load stdlib from test/relocatedepot" begin | ||
test_harness() do | ||
push!(LOAD_PATH, joinpath(@__DIR__, "relocatedepot")) | ||
push!(DEPOT_PATH, joinpath(@__DIR__, "relocatedepot")) | ||
# stdlib should be already precompiled | ||
pkg = Base.identify_package("DelimitedFiles") | ||
@test Base.isprecompiled(pkg) == true | ||
end | ||
end | ||
|
||
@testset "load RelocationTestPkg1 from test/relocatedepot" begin | ||
pkgname = "RelocationTestPkg1" | ||
test_harness() do | ||
push!(LOAD_PATH, joinpath(@__DIR__, "relocatedepot")) | ||
push!(DEPOT_PATH, joinpath(@__DIR__, "relocatedepot")) | ||
pkg = Base.identify_package(pkgname) | ||
@test Base.isprecompiled(pkg) == true | ||
Base.require(pkg) # re-precompile | ||
@test Base.isprecompiled(pkg) == true | ||
end | ||
end | ||
|
||
@testset "load RelocationTestPkg2 (contains include_dependency) from test/relocatedepot" begin | ||
pkgname = "RelocationTestPkg2" | ||
test_harness() do | ||
push!(LOAD_PATH, joinpath(@__DIR__, "relocatedepot")) | ||
push!(DEPOT_PATH, joinpath(@__DIR__, "relocatedepot")) | ||
pkg = Base.identify_package(pkgname) | ||
@test Base.isprecompiled(pkg) == false # moving depot changes mtime of include_dependency | ||
Base.require(pkg) # re-precompile | ||
@test Base.isprecompiled(pkg) == true | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters