From 3370636b47b85017fdfc7e96d0d89767a0a13b03 Mon Sep 17 00:00:00 2001 From: Kristoffer Date: Fri, 1 Mar 2024 16:36:41 +0100 Subject: [PATCH] silence on from loading non interactive propagate through flags and cacheflags --- base/precompile.jl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/base/precompile.jl b/base/precompile.jl index 98ae35b02382e8..61b6f577b99f7c 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -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 @@ -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) @@ -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 @@ -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") : "" @@ -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) @@ -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)