diff --git a/base/initdefs.jl b/base/initdefs.jl index ea456907a17a8..3dfd6aed39015 100644 --- a/base/initdefs.jl +++ b/base/initdefs.jl @@ -101,7 +101,6 @@ function and `using` and `import` statements to consider when loading code. """ const LOAD_PATH = Any[] -const LOAD_CACHE_PATH = String[] function parse_load_path(str::String) envs = Any[split(str, Sys.iswindows() ? ';' : ':');] diff --git a/base/loading.jl b/base/loading.jl index d1056ee208623..1aa230ab1a4ea 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -638,15 +638,17 @@ function find_source_file(path::AbstractString) return isfile(base_path) ? base_path : nothing end -cache_file_entry(pkg::PkgId) = - pkg.uuid === nothing ? "$(pkg.name).ji" : - joinpath(pkg.name, "$(package_slug(pkg.uuid)).ji") +cache_file_entry(pkg::PkgId) = joinpath( + "compiled", + "v$(VERSION.major).$(VERSION.minor)", + pkg.uuid === nothing ? "$(pkg.name).ji" : joinpath(pkg.name, "$(package_slug(pkg.uuid)).ji") +) function find_all_in_cache_path(pkg::PkgId) paths = String[] - suffix = cache_file_entry(pkg) - for prefix in LOAD_CACHE_PATH - path = joinpath(prefix, suffix) + entry = cache_file_entry(pkg) + for depot in DEPOT_PATH + path = joinpath(depot, entry) isfile_casesensitive(path) && push!(paths, path) end return paths @@ -1133,8 +1135,6 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof( append!(Base.LOAD_PATH, $(repr(LOAD_PATH, context=:module=>nothing))) empty!(Base.DEPOT_PATH) append!(Base.DEPOT_PATH, $(repr(DEPOT_PATH))) - empty!(Base.LOAD_CACHE_PATH) - append!(Base.LOAD_CACHE_PATH, $(repr(LOAD_CACHE_PATH))) empty!(Base.DL_LOAD_PATH) append!(Base.DL_LOAD_PATH, $(repr(DL_LOAD_PATH))) Base._track_dependencies[] = true @@ -1173,11 +1173,9 @@ end """ Base.compilecache(module::PkgId) -Creates a precompiled cache file for -a module and all of its dependencies. +Creates a precompiled cache file for a module and all of its dependencies. This can be used to reduce package load times. Cache files are stored in -`LOAD_CACHE_PATH[1]`, which defaults to `~/.julia/lib/VERSION`. See -[Module initialization and precompilation](@ref) +`DEPOT_PATH[1]/compiled`. See [Module initialization and precompilation](@ref) for important notes. """ function compilecache(pkg::PkgId) @@ -1186,7 +1184,7 @@ function compilecache(pkg::PkgId) path = locate_package(pkg) path === nothing && throw(ArgumentError("$name not found in path")) # decide where to put the resulting cache file - cachefile = abspath(LOAD_CACHE_PATH[1], cache_file_entry(pkg)) + cachefile = abspath(DEPOT_PATH[1], cache_file_entry(pkg)) cachepath = dirname(cachefile) isdir(cachepath) || mkpath(cachepath) # build up the list of modules that we want the precompile process to preserve diff --git a/doc/src/manual/modules.md b/doc/src/manual/modules.md index bb7c0f28e2b4f..1442f898bcb53 100644 --- a/doc/src/manual/modules.md +++ b/doc/src/manual/modules.md @@ -221,7 +221,7 @@ versions of modules to reduce this time. To create an incremental precompiled module file, add `__precompile__()` at the top of your module file (before the `module` starts). This will cause it to be automatically compiled the first time it is imported. Alternatively, you can manually call `Base.compilecache(modulename)`. The resulting -cache files will be stored in `Base.LOAD_CACHE_PATH[1]`. Subsequently, the module is automatically +cache files will be stored in `DEPOT_PATH[1]/compiled/`. Subsequently, the module is automatically recompiled upon `import` whenever any of its dependencies change; dependencies are modules it imports, the Julia build, files it includes, or explicit dependencies declared by `include_dependency(path)` in the module file(s). diff --git a/stdlib/Pkg/src/Pkg.jl b/stdlib/Pkg/src/Pkg.jl index 88cd02050ba98..55a7098ade83c 100644 --- a/stdlib/Pkg/src/Pkg.jl +++ b/stdlib/Pkg/src/Pkg.jl @@ -89,7 +89,6 @@ init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) = Di function __init__() vers = "v$(VERSION.major).$(VERSION.minor)" push!(Base.LOAD_PATH, dir) - pushfirst!(Base.LOAD_CACHE_PATH, abspath(Dir._pkgroot(), "lib", vers)) end """ diff --git a/stdlib/Pkg/src/entry.jl b/stdlib/Pkg/src/entry.jl index 21a9cbd982fb9..5534e57caaaad 100644 --- a/stdlib/Pkg/src/entry.jl +++ b/stdlib/Pkg/src/entry.jl @@ -588,8 +588,6 @@ function build(pkg::AbstractString, build_file::AbstractString, errfile::Abstrac append!(Base.LOAD_PATH, $(repr(LOAD_PATH, context=:module=>nothing))) empty!(Base.DEPOT_PATH) append!(Base.DEPOT_PATH, $(repr(DEPOT_PATH))) - empty!(Base.LOAD_CACHE_PATH) - append!(Base.LOAD_CACHE_PATH, $(repr(Base.LOAD_CACHE_PATH))) empty!(Base.DL_LOAD_PATH) append!(Base.DL_LOAD_PATH, $(repr(Base.DL_LOAD_PATH))) open("$(escape_string(errfile))", "a") do f diff --git a/test/compile.jl b/test/compile.jl index 6412abf3f4b1b..a67a2f5c014af 100644 --- a/test/compile.jl +++ b/test/compile.jl @@ -16,7 +16,7 @@ using .ConflictingBindings dir = mktempdir() dir2 = mktempdir() insert!(LOAD_PATH, 1, dir) -insert!(Base.LOAD_CACHE_PATH, 1, dir) +insert!(DEPOT_PATH, 1, dir) try Foo_file = joinpath(dir, "$Foo_module.jl") Foo2_file = joinpath(dir, "$Foo2_module.jl") @@ -166,7 +166,9 @@ try @test Foo.override(UInt(1)) == 2 end - cachefile = joinpath(dir, "$Foo_module.ji") + cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)") + cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)") + cachefile = joinpath(cachedir, "$Foo_module.ji") # use _require_from_serialized to ensure that the test fails if # the module doesn't reload from the image: @test_logs (:warn, "Replacing module `$Foo_module`") begin @@ -293,36 +295,36 @@ try """) Base.compilecache(Base.PkgId("FooBar")) - @test isfile(joinpath(dir, "FooBar.ji")) - @test Base.stale_cachefile(FooBar_file, joinpath(dir, "FooBar.ji")) isa Vector + @test isfile(joinpath(cachedir, "FooBar.ji")) + @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Vector @test !isdefined(Main, :FooBar) @test !isdefined(Main, :FooBar1) relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl") - @test Base.stale_cachefile(relFooBar_file, joinpath(dir, "FooBar.ji")) isa (Sys.iswindows() ? Vector : Bool) # `..` is not a symlink on Windows + @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa (Sys.iswindows() ? Vector : Bool) # `..` is not a symlink on Windows mkdir(joinpath(dir, "subfolder")) - @test Base.stale_cachefile(relFooBar_file, joinpath(dir, "FooBar.ji")) isa Vector + @test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Vector @eval using FooBar fb_uuid = Base.module_build_id(FooBar) sleep(2); touch(FooBar_file) - insert!(Base.LOAD_CACHE_PATH, 1, dir2) - @test Base.stale_cachefile(FooBar_file, joinpath(dir, "FooBar.ji")) === true + insert!(DEPOT_PATH, 1, dir2) + @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) === true @eval using FooBar1 - @test !isfile(joinpath(dir2, "FooBar.ji")) - @test !isfile(joinpath(dir, "FooBar1.ji")) - @test isfile(joinpath(dir2, "FooBar1.ji")) - @test Base.stale_cachefile(FooBar_file, joinpath(dir, "FooBar.ji")) === true - @test Base.stale_cachefile(FooBar1_file, joinpath(dir2, "FooBar1.ji")) isa Vector + @test !isfile(joinpath(cachedir2, "FooBar.ji")) + @test !isfile(joinpath(cachedir, "FooBar1.ji")) + @test isfile(joinpath(cachedir2, "FooBar1.ji")) + @test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) === true + @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Vector @test fb_uuid == Base.module_build_id(FooBar) fb_uuid1 = Base.module_build_id(FooBar1) @test fb_uuid != fb_uuid1 # test checksum - open(joinpath(dir2, "FooBar1.ji"), "a") do f + open(joinpath(cachedir2, "FooBar1.ji"), "a") do f write(f, 0x076cac96) # append 4 random bytes end - @test Base.stale_cachefile(FooBar1_file, joinpath(dir2, "FooBar1.ji")) === true + @test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true # test behavior of precompile modules that throw errors FooBar2_file = joinpath(dir, "FooBar2.jl") @@ -373,10 +375,10 @@ try end """) rm(FooBarT_file) - @test Base.stale_cachefile(FooBarT2_file, joinpath(dir2, "FooBarT2.ji")) === true + @test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true @test Base.require(Main, :FooBarT2) isa Module finally - splice!(Base.LOAD_CACHE_PATH, 1:2) + splice!(DEPOT_PATH, 1:2) splice!(LOAD_PATH, 1) rm(dir, recursive=true) rm(dir2, recursive=true) @@ -398,7 +400,7 @@ let dir = mktempdir(), eval(quote insert!(LOAD_PATH, 1, $(dir)) - insert!(Base.LOAD_CACHE_PATH, 1, $(dir)) + insert!(DEPOT_PATH, 1, $(dir)) Base.compilecache(Base.PkgId("Time4b3a94a1a081a8cb")) end) @@ -406,7 +408,7 @@ let dir = mktempdir(), testcode = """ insert!(LOAD_PATH, 1, $(repr(dir))) - insert!(Base.LOAD_CACHE_PATH, 1, $(repr(dir))) + insert!(DEPOT_PATH, 1, $(repr(dir))) using $Time_module getfield($Time_module, :time) """ @@ -421,7 +423,7 @@ let dir = mktempdir(), @test parse(Float64, t1_no) < parse(Float64, t2_no) finally - splice!(Base.LOAD_CACHE_PATH, 1) + splice!(DEPOT_PATH, 1) splice!(LOAD_PATH, 1) rm(dir, recursive=true) end @@ -448,7 +450,7 @@ let dir = mktempdir() testcode = """ insert!(LOAD_PATH, 1, $(repr(dir))) - insert!(Base.LOAD_CACHE_PATH, 1, $(repr(dir))) + insert!(DEPOT_PATH, 1, $(repr(dir))) using $Test_module """ @@ -481,7 +483,7 @@ end let dir = mktempdir() try insert!(LOAD_PATH, 1, dir) - insert!(Base.LOAD_CACHE_PATH, 1, dir) + insert!(DEPOT_PATH, 1, dir) loaded_modules = Channel{Symbol}(32) callback = (mod::Base.PkgId) -> put!(loaded_modules, Symbol(mod.name)) @@ -521,7 +523,7 @@ let dir = mktempdir() @test take!(loaded_modules) == Test3_module finally pop!(Base.package_callbacks) - splice!(Base.LOAD_CACHE_PATH, 1) + splice!(DEPOT_PATH, 1) splice!(LOAD_PATH, 1) rm(dir, recursive=true) end @@ -563,7 +565,7 @@ end @everywhere test_workers begin pushfirst!(LOAD_PATH, $load_path) - pushfirst!(Base.LOAD_CACHE_PATH, $load_cache_path) + pushfirst!(DEPOT_PATH, $load_cache_path) end try @eval using $ModuleB @@ -579,7 +581,7 @@ end finally @everywhere test_workers begin popfirst!(LOAD_PATH) - popfirst!(Base.LOAD_CACHE_PATH) + popfirst!(DEPOT_PATH) end end finally @@ -594,7 +596,7 @@ end (f -> f())() do # wrap in function scope, so we can test world errors dir = mktempdir() insert!(LOAD_PATH, 1, dir) -insert!(Base.LOAD_CACHE_PATH, 1, dir) +insert!(DEPOT_PATH, 1, dir) try A_module = :Aedb164bd3a126418 B_module = :Bedb164bd3a126418 @@ -642,7 +644,7 @@ try @test Base.invokelatest(B.bnopc, 1) == Base.invokelatest(B.bnopc, 1.0) == 2 finally popfirst!(LOAD_PATH) - popfirst!(Base.LOAD_CACHE_PATH) + popfirst!(DEPOT_PATH) rm(dir, recursive=true) end @@ -662,7 +664,7 @@ let """) pushfirst!(LOAD_PATH, load_path) - pushfirst!(Base.LOAD_CACHE_PATH, load_cache_path) + pushfirst!(DEPOT_PATH, load_cache_path) l0 = length(Base.package_callbacks) @eval using $ModuleA @@ -700,7 +702,7 @@ let """) pushfirst!(LOAD_PATH, load_path) - pushfirst!(Base.LOAD_CACHE_PATH, load_cache_path) + pushfirst!(DEPOT_PATH, load_cache_path) Base.compilecache(Base.PkgId("A25604")) @test_nowarn @eval using A25604 diff --git a/test/embedding/embedding.c b/test/embedding/embedding.c index dff95a69dc08f..12dde4be3bde8 100644 --- a/test/embedding/embedding.c +++ b/test/embedding/embedding.c @@ -163,10 +163,6 @@ int main() // locate files relative to the "embedding" executable " stdlib = filter(env -> startswith(Base.find_package(Base, \"Distributed\"), env), Base.load_path())[end]\n" " push!(empty!(LOAD_PATH), dir, stdlib)\n" - // this directory needs to be writable for the example, - // although in real code it usually wouldn't necessarily be used that way - " empty!(Base.LOAD_CACHE_PATH)\n" - " push!(Base.LOAD_CACHE_PATH, tempdir())\n" "end" ); checked_eval_string("import LocalModule");