Skip to content

Commit

Permalink
silence on from loading non interactive
Browse files Browse the repository at this point in the history
propagate through flags and cacheflags
  • Loading branch information
KristofferC committed Mar 1, 2024
1 parent 3a123d4 commit 3370636
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,16 @@ function printpkgstyle(io, header, msg; color=:light_green)
println(io, " ", msg)
end


function precompilepkgs(pkgs::Vector{String}=String[]; internal_call::Bool=false,
strict::Bool=false, warn_loaded = true, timing::Bool = false,
_from_loading::Bool=false, io::IO=stderr)
_from_loading::Bool=false, flags_cacheflags::Pair{Cmd, Base.CacheFlags}=(``=>Base.CacheFlags()), io::IO=stderr)
time_start = time_ns()

env = ExplicitEnv()

flags, cacheflags = flags_cacheflags

# Windows sometimes hits a ReadOnlyMemoryError, so we halve the default number of tasks. Issue #2323
# TODO: Investigate why this happens in windows and restore the full task limit
default_num_tasks = Sys.iswindows() ? div(Sys.CPU_THREADS::Int, 2) + 1 : Sys.CPU_THREADS::Int + 1
Expand All @@ -350,7 +353,11 @@ function precompilepkgs(pkgs::Vector{String}=String[]; internal_call::Bool=false
num_tasks = parse(Int, get(ENV, "JULIA_NUM_PRECOMPILE_TASKS", string(default_num_tasks)))
parallel_limiter = Base.Semaphore(num_tasks)

fancyprint = can_fancyprint(io) && !timing && !(_from_loading && !Sys.isinteractive())
fancyprint = can_fancyprint(io) && !timing

if _from_loading && !Sys.isinteractive()
io = devnull
end

hascolor = get(io, :color, false)::Bool
color_string(cstr::String, col::Union{Int64, Symbol}) = _color_string(cstr, col, hascolor)
Expand Down Expand Up @@ -717,7 +724,7 @@ function precompilepkgs(pkgs::Vector{String}=String[]; internal_call::Bool=false
end

circular = pkg in circular_deps
is_stale = !Base.isprecompiled(pkg; ignore_loaded=true, stale_cache, cachepaths, sourcepath)
is_stale = !Base.isprecompiled(pkg; ignore_loaded=true, stale_cache, cachepaths, sourcepath, flags=cacheflags)
if !circular && is_stale
Base.acquire(parallel_limiter)
is_direct_dep = pkg in direct_deps
Expand All @@ -742,10 +749,10 @@ function precompilepkgs(pkgs::Vector{String}=String[]; internal_call::Bool=false
try
# allows processes to wait if another process is precompiling a given package to
# a functionally identical package cache (except for preferences, which may differ)
t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock(io, print_lock, fancyprint, pkg, pkgspidlocked, hascolor) do
t = @elapsed ret = precompile_pkgs_maybe_cachefile_lock(io, print_lock, fancyprint, pkg, pkgspidlocked, hascolor, cacheflags) do
Base.with_logger(Base.NullLogger()) do
# The false here means we ignore loaded modules, so precompile for a fresh session
Base.compilecache(pkg, sourcepath, std_pipe, std_pipe, false)
Base.compilecache(pkg, sourcepath, std_pipe, std_pipe, false; flags)
end
end
t_str = timing ? string(lpad(round(t * 1e3, digits = 1), 9), " ms") : ""
Expand Down Expand Up @@ -903,7 +910,7 @@ function _color_string(cstr::String, col::Union{Int64, Symbol}, hascolor)
end

# Can be merged with `maybe_cachefile_lock` in loading?
function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::Bool, pkg::Base.PkgId, pkgspidlocked::Dict{Base.PkgId,String}, hascolor)
function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLock, fancyprint::Bool, pkg::Base.PkgId, pkgspidlocked::Dict{Base.PkgId,String}, hascolor, cacheflags)
FileWatching = Base.loaded_modules[Base.PkgId(Base.UUID("7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"), "FileWatching")]
stale_age = Base.compilecache_pidlock_stale_age
pidfile = Base.compilecache_pidfile_path(pkg)
Expand All @@ -925,7 +932,7 @@ function precompile_pkgs_maybe_cachefile_lock(f, io::IO, print_lock::ReentrantLo
# 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

0 comments on commit 3370636

Please sign in to comment.