Skip to content

Commit

Permalink
Merge pull request #33173 from JuliaLang/tb/cachefile
Browse files Browse the repository at this point in the history
Factor-out logic to determine the path of the precompilation cache file.
  • Loading branch information
maleadt authored Sep 6, 2019
2 parents 784eb57 + 2de79f7 commit 7cafa94
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
33 changes: 21 additions & 12 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,18 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
return io
end

function compilecache_path(pkg::PkgId)::String
entrypath, entryfile = cache_file_entry(pkg)
cachepath = joinpath(DEPOT_PATH[1], entrypath)
isdir(cachepath) || mkpath(cachepath)
if pkg.uuid === nothing
abspath(cachepath, entryfile) * ".ji"
else
project_precompile_slug = slug(_crc32c(something(Base.active_project(), "")), 5)
abspath(cachepath, string(entryfile, "_", project_precompile_slug, ".ji"))
end
end

"""
Base.compilecache(module::PkgId)
Expand All @@ -1240,19 +1252,16 @@ const MAX_NUM_PRECOMPILE_FILES = 10

function compilecache(pkg::PkgId, path::String)
# decide where to put the resulting cache file
entrypath, entryfile = cache_file_entry(pkg)
cachepath = joinpath(DEPOT_PATH[1], entrypath)
isdir(cachepath) || mkpath(cachepath)
if pkg.uuid === nothing
cachefile = abspath(cachepath, entryfile) * ".ji"
else
candidates = filter!(x -> startswith(x, entryfile * "_"), readdir(cachepath))
if length(candidates) >= MAX_NUM_PRECOMPILE_FILES
idx = findmin(mtime.(joinpath.(cachepath, candidates)))[2]
rm(joinpath(cachepath, candidates[idx]))
cachefile = compilecache_path(pkg)
# prune the directory with cache files
if pkg.uuid !== nothing
cachepath = dirname(cachefile)
entrypath, entryfile = cache_file_entry(pkg)
cachefiles = filter!(x -> startswith(x, entryfile * "_"), readdir(cachepath))
if length(cachefiles) >= MAX_NUM_PRECOMPILE_FILES
idx = findmin(mtime.(joinpath.(cachepath, cachefiles)))[2]
rm(joinpath(cachepath, cachefiles[idx]))
end
project_precompile_slug = slug(_crc32c(something(Base.active_project(), "")), 5)
cachefile = abspath(cachepath, string(entryfile, "_", project_precompile_slug, ".ji"))
end
# build up the list of modules that we want the precompile process to preserve
concrete_deps = copy(_concrete_dependencies)
Expand Down
3 changes: 2 additions & 1 deletion test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ try
end
""")

Base.compilecache(Base.PkgId("FooBar"))
cachefile = Base.compilecache(Base.PkgId("FooBar"))
@test cachefile == Base.compilecache_path(Base.PkgId("FooBar"))
@test isfile(joinpath(cachedir, "FooBar.ji"))
@test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Vector
@test !isdefined(Main, :FooBar)
Expand Down

0 comments on commit 7cafa94

Please sign in to comment.