Skip to content

Commit

Permalink
hook up CacheFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Feb 15, 2024
1 parent bdf7902 commit 7279a85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,9 @@ end

function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool=false,
strict::Bool=false, warn_loaded = true, already_instantiated = false, timing::Bool = false,
_from_loading::Bool=false, flags::Cmd=``, kwargs...)
_from_loading::Bool=false, flags_cacheflags::Pair{Cmd, Base.CacheFlags}=(``=>Base.CacheFlags()), kwargs...)
Context!(ctx; kwargs...)
flags, cacheflags = flags_cacheflags
if !already_instantiated
instantiate(ctx; allow_autoprecomp=false, kwargs...)
@debug "precompile: instantiated"
Expand Down Expand Up @@ -1717,7 +1718,7 @@ function maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::
# wait until the lock is available
FileWatching.mkpidlock(pidfile; stale_age) do
# double-check in case the other process crashed or the lock expired
if Base.isprecompiled(pkg; ignore_loaded=true) # don't use caches for this as the env state will have changed
if Base.isprecompiled(pkg; ignore_loaded=true, flags=cacheflags) # don't use caches for this as the env state will have changed
return nothing # returning nothing indicates a process waited for another
else
delete!(pkgspidlocked, pkg)
Expand Down
17 changes: 14 additions & 3 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,17 @@ function gen_subprocess_flags(source_path::String; coverage, julia_args)
```
end

function gen_subprocess_cacheflags()
session_flags = Base.CacheFlags()
Base.CacheFlags(
session_flags.use_pkgimages,
session_flags.debug_level,
1, # `--checkbounds=yes`
Bool(Base.JLOptions().can_inline),
session_flags.debug_level
)
end

function with_temp_env(fn::Function, temp_env::String)
load_path = copy(LOAD_PATH)
active_project = Base.ACTIVE_PROJECT[]
Expand Down Expand Up @@ -1979,19 +1990,19 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
test_fn !== nothing && test_fn()
sandbox_ctx = Context(;io=ctx.io)
status(sandbox_ctx.env, sandbox_ctx.registries; mode=PKGMODE_COMBINED, io=sandbox_ctx.io, ignore_indent = false, show_usagetips = false)
flags = gen_subprocess_flags(source_path; coverage, julia_args)

if should_autoprecompile()
flags = gen_subprocess_flags(source_path; coverage, julia_args)
cacheflags = gen_subprocess_cacheflags()
# Allow to fail?
Pkg.activate(sandbox_ctx.env.project_file; #=io=devnull=#) do
Pkg.precompile(sandbox_ctx; io=sandbox_ctx.io, flags)
Pkg.precompile(sandbox_ctx; io=sandbox_ctx.io, flags_cacheflags = flags => cacheflags)
end
end

printpkgstyle(ctx.io, :Testing, "Running tests...")
flush(ctx.io)
code = gen_test_code(source_path; test_args)
flags = gen_subprocess_flags(source_path; coverage, julia_args)
cmd = `$(Base.julia_cmd()) --project=$(testdir(source_path)) $(flags) --eval $code`
p, interrupted = subprocess_handler(cmd, ctx, sandbox_ctx, "Tests interrupted. Exiting the test process")
if success(p)
Expand Down

0 comments on commit 7279a85

Please sign in to comment.