Skip to content

Commit 919cc28

Browse files
authored
Merge pull request #2592 from JuliaLang/fe/backports-release-1.6
Backports for Pkg 1.6.2
2 parents c78a8be + d69a8a0 commit 919cc28

File tree

21 files changed

+426
-118
lines changed

21 files changed

+426
-118
lines changed

src/API.jl

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ..can_fancyprint, ..DEFAULT_IO
1616
using ..Types, ..TOML
1717
using ..Types: VersionTypes
1818
using Base.BinaryPlatforms
19+
import ..stderr_f, ..stdout_f
1920
using ..Artifacts: artifact_paths
2021
using ..MiniProgressBars
2122

@@ -73,7 +74,7 @@ for f in (:develop, :add, :rm, :up, :pin, :free, :test, :build, :status)
7374
@eval begin
7475
$f(pkg::Union{AbstractString, PackageSpec}; kwargs...) = $f([pkg]; kwargs...)
7576
$f(pkgs::Vector{<:AbstractString}; kwargs...) = $f([PackageSpec(pkg) for pkg in pkgs]; kwargs...)
76-
function $f(pkgs::Vector{PackageSpec}; io::IO=DEFAULT_IO[], kwargs...)
77+
function $f(pkgs::Vector{PackageSpec}; io::IO=$(f === :status ? :stdout_f : :stderr_f)(), kwargs...)
7778
ctx = Context()
7879
kwargs = merge((;kwargs...), (:io => io,))
7980
ret = $f(ctx, pkgs; kwargs...)
@@ -261,7 +262,7 @@ function up(ctx::Context, pkgs::Vector{PackageSpec};
261262
return
262263
end
263264

264-
resolve(; io::IO=DEFAULT_IO[], kwargs...) = resolve(Context(;io); kwargs...)
265+
resolve(; io::IO=stderr_f(), kwargs...) = resolve(Context(;io); kwargs...)
265266
function resolve(ctx::Context; kwargs...)
266267
up(ctx; level=UPLEVEL_FIXED, mode=PKGMODE_MANIFEST, update_registry=false, kwargs...)
267268
return nothing
@@ -924,6 +925,7 @@ function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false,
924925
# Windows sometimes hits a ReadOnlyMemoryError, so we halve the default number of tasks. Issue #2323
925926
# TODO: Investigate why this happens in windows and restore the full task limit
926927
default_num_tasks = Sys.iswindows() ? div(Sys.CPU_THREADS::Int, 2) + 1 : Sys.CPU_THREADS::Int + 1
928+
default_num_tasks = min(default_num_tasks, 16) # limit for better stability on shared resource systems
927929

928930
num_tasks = parse(Int, get(ENV, "JULIA_NUM_PRECOMPILE_TASKS", string(default_num_tasks)))
929931
parallel_limiter = Base.Semaphore(num_tasks)
@@ -1008,9 +1010,11 @@ function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false,
10081010
ansi_disablecursor = "\e[?25l"
10091011
n_done::Int = 0
10101012
n_already_precomp::Int = 0
1013+
n_loaded::Int = 0
10111014

10121015
function handle_interrupt(err)
10131016
notify(interrupted_or_done)
1017+
sleep(0.2) # yield for a period to let the print loop cease first
10141018
if err isa InterruptException
10151019
lock(print_lock) do
10161020
println(io, " Interrupted: Exiting precompilation...")
@@ -1054,15 +1058,16 @@ function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false,
10541058
bar.max = n_total - n_already_precomp
10551059
final_loop || print(iostr, sprint(io -> show_progress(io, bar); context=io), "\n")
10561060
for dep in pkg_queue_show
1061+
loaded = haskey(Base.loaded_modules, dep)
10571062
name = dep in direct_deps ? dep.name : string(color_string(dep.name, :light_black))
10581063
if dep in precomperr_deps
10591064
print(iostr, color_string(" ? ", Base.warn_color()), name, "\n")
10601065
elseif haskey(failed_deps, dep)
10611066
print(iostr, color_string("", Base.error_color()), name, "\n")
10621067
elseif was_recompiled[dep]
1063-
interrupted_or_done.set && continue
1064-
print(iostr, color_string("", :green), name, "\n")
1065-
@async begin # keep successful deps visible for short period
1068+
!loaded && interrupted_or_done.set && continue
1069+
print(iostr, color_string("", loaded ? Base.warn_color() : :green), name, "\n")
1070+
loaded || @async begin # keep successful deps visible for short period
10661071
sleep(1);
10671072
filter!(!isequal(dep), pkg_queue)
10681073
end
@@ -1109,6 +1114,7 @@ function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false,
11091114

11101115
task = @async begin
11111116
try
1117+
loaded = haskey(Base.loaded_modules, pkg)
11121118
for dep in deps # wait for deps to finish
11131119
wait(was_processed[dep])
11141120
end
@@ -1141,7 +1147,12 @@ function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false,
11411147
end
11421148
try
11431149
ret = Logging.with_logger(Logging.NullLogger()) do
1144-
Base.compilecache(pkg, sourcepath, iob, devnull) # capture stderr, send stdout to devnull
1150+
@static if hasmethod(Base.compilecache, Tuple{Base.PkgId, String, IO, IO, Bool})
1151+
# capture stderr, send stdout to devnull, don't skip loaded modules
1152+
Base.compilecache(pkg, sourcepath, iob, devnull, false)
1153+
else
1154+
Base.compilecache(pkg, sourcepath, iob, devnull)
1155+
end
11451156
end
11461157
if ret isa Base.PrecompilableError
11471158
push!(precomperr_deps, pkg)
@@ -1152,13 +1163,14 @@ function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false,
11521163
else
11531164
queued && (haskey(man, pkg.uuid) && precomp_dequeue!(make_pkgspec(man, pkg.uuid)))
11541165
!fancyprint && lock(print_lock) do
1155-
println(io, string(color_string("", :green), name))
1166+
println(io, string(color_string("", loaded ? Base.warn_color() : :green), name))
11561167
end
11571168
was_recompiled[pkg] = true
11581169
end
1170+
loaded && (n_loaded += 1)
11591171
catch err
1160-
if err isa ErrorException
1161-
failed_deps[pkg] = (strict || is_direct_dep) ? String(take!(iob)) : ""
1172+
if err isa ErrorException || (err isa ArgumentError && startswith(err.msg, "Invalid header in cache file"))
1173+
failed_deps[pkg] = (strict || is_direct_dep) ? string(sprint(showerror, err), "\n", String(take!(iob))) : ""
11621174
!fancyprint && lock(print_lock) do
11631175
println(io, string(color_string("", Base.error_color()), name))
11641176
end
@@ -1211,6 +1223,15 @@ function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false,
12111223
!isempty(skipped_deps) && (print(iostr, ", $(length(skipped_deps)) skipped during auto due to previous errors"))
12121224
print(iostr, ")")
12131225
end
1226+
if n_loaded > 0
1227+
plural1 = n_loaded == 1 ? "y" : "ies"
1228+
plural2 = n_loaded == 1 ? "a different version is" : "different versions are"
1229+
plural3 = n_loaded == 1 ? "" : "s"
1230+
print(iostr, "\n ",
1231+
color_string(string(n_loaded), Base.warn_color()),
1232+
" dependenc$(plural1) precompiled but $(plural2) currently loaded. Restart julia to access the new version$(plural3)"
1233+
)
1234+
end
12141235
if !isempty(precomperr_deps)
12151236
plural = length(precomperr_deps) == 1 ? "y" : "ies"
12161237
print(iostr, "\n ",
@@ -1406,9 +1427,9 @@ function status(ctx::Context, pkgs::Vector{PackageSpec}; diff::Bool=false, mode=
14061427
end
14071428

14081429

1409-
function activate(;temp=false, shared=false, io::IO=DEFAULT_IO[])
1430+
function activate(;temp=false, shared=false, io::IO=stderr_f())
14101431
shared && pkgerror("Must give a name for a shared environment")
1411-
temp && return activate(mktempdir())
1432+
temp && return activate(mktempdir(); io)
14121433
Base.ACTIVE_PROJECT[] = nothing
14131434
p = Base.active_project()
14141435
p === nothing || printpkgstyle(io, :Activating, "environment at $(pathrepr(p))")
@@ -1432,7 +1453,7 @@ function _activate_dep(dep_name::AbstractString)
14321453
end
14331454
end
14341455
end
1435-
function activate(path::AbstractString; shared::Bool=false, temp::Bool=false, io::IO=DEFAULT_IO[])
1456+
function activate(path::AbstractString; shared::Bool=false, temp::Bool=false, io::IO=stderr_f())
14361457
temp && pkgerror("Can not give `path` argument when creating a temporary environment")
14371458
if !shared
14381459
# `pkg> activate path`/`Pkg.activate(path)` does the following

src/Artifacts.jl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ..GitTools
1111
import ..TOML
1212
import ..Types: parse_toml, write_env_usage, printpkgstyle
1313
import ..Pkg
14-
import ..Pkg: pkg_server, can_fancyprint, DEFAULT_IO
14+
import ..Pkg: pkg_server, can_fancyprint, stderr_f
1515
using ..Pkg.MiniProgressBars
1616
using ..PlatformEngines
1717
using SHA
@@ -286,7 +286,7 @@ end
286286

287287
"""
288288
download_artifact(tree_hash::SHA1, tarball_url::String, tarball_hash::String;
289-
verbose::Bool = false, io::IO=DEFAULT_IO[])
289+
verbose::Bool = false, io::IO=stderr)
290290
291291
Download/install an artifact into the artifact store. Returns `true` on success.
292292
@@ -299,7 +299,7 @@ function download_artifact(
299299
tarball_hash::Union{String, Nothing} = nothing;
300300
verbose::Bool = false,
301301
quiet_download::Bool = false,
302-
io::IO=DEFAULT_IO[],
302+
io::IO=stderr_f(),
303303
)
304304
if artifact_exists(tree_hash)
305305
return true
@@ -321,12 +321,13 @@ function download_artifact(
321321
try
322322
download_verify_unpack(tarball_url, tarball_hash, dest_dir, ignore_existence=true,
323323
verbose=verbose, quiet_download=quiet_download, io=io)
324-
catch e
324+
catch err
325+
@debug "download_artifact error" tree_hash tarball_url tarball_hash err
325326
# Clean that destination directory out if something went wrong
326327
rm(dest_dir; force=true, recursive=true)
327328

328-
if isa(e, InterruptException)
329-
rethrow(e)
329+
if isa(err, InterruptException)
330+
rethrow(err)
330331
end
331332
return false
332333
end
@@ -343,9 +344,10 @@ function download_artifact(
343344
download_verify_unpack(tarball_url, tarball_hash, dir, ignore_existence=true, verbose=verbose,
344345
quiet_download=quiet_download, io=io)
345346
end
346-
catch e
347-
if isa(e, InterruptException)
348-
rethrow(e)
347+
catch err
348+
@debug "download_artifact error" tree_hash tarball_url tarball_hash err
349+
if isa(err, InterruptException)
350+
rethrow(err)
349351
end
350352
# If something went wrong during download, return false
351353
return false
@@ -384,7 +386,7 @@ end
384386
pkg_uuid::Union{Base.UUID,Nothing}=nothing,
385387
verbose::Bool = false,
386388
quiet_download::Bool = false,
387-
io::IO=DEFAULT_IO[])
389+
io::IO=stderr)
388390
389391
Ensures an artifact is installed, downloading it via the download information stored in
390392
`artifacts_toml` if necessary. Throws an error if unable to install.
@@ -397,7 +399,7 @@ function ensure_artifact_installed(name::String, artifacts_toml::String;
397399
pkg_uuid::Union{Base.UUID,Nothing}=nothing,
398400
verbose::Bool = false,
399401
quiet_download::Bool = false,
400-
io::IO=DEFAULT_IO[])
402+
io::IO=stderr_f())
401403
meta = artifact_meta(name, artifacts_toml; pkg_uuid=pkg_uuid, platform=platform)
402404
if meta === nothing
403405
error("Cannot locate artifact '$(name)' in '$(artifacts_toml)'")
@@ -411,7 +413,7 @@ function ensure_artifact_installed(name::String, meta::Dict, artifacts_toml::Str
411413
platform::AbstractPlatform = HostPlatform(),
412414
verbose::Bool = false,
413415
quiet_download::Bool = false,
414-
io::IO=DEFAULT_IO[])
416+
io::IO=stderr_f())
415417
hash = SHA1(meta["git-tree-sha1"])
416418

417419
if !artifact_exists(hash)
@@ -470,7 +472,7 @@ end
470472
include_lazy = false,
471473
verbose = false,
472474
quiet_download = false,
473-
io::IO=DEFAULT_IO[])
475+
io::IO=stderr)
474476
475477
Installs all non-lazy artifacts from a given `(Julia)Artifacts.toml` file. `package_uuid` must
476478
be provided to properly support overrides from `Overrides.toml` entries in depots.
@@ -486,7 +488,7 @@ function ensure_all_artifacts_installed(artifacts_toml::String;
486488
include_lazy::Bool = false,
487489
verbose::Bool = false,
488490
quiet_download::Bool = false,
489-
io::IO=DEFAULT_IO[])
491+
io::IO=stderr_f())
490492
if !isfile(artifacts_toml)
491493
return
492494
end

src/MiniProgressBars.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using Printf
77
Base.@kwdef mutable struct MiniProgressBar
88
max::Int = 1.0
99
header::String = ""
10-
color::Symbol = :white
10+
color::Symbol = :nothing
1111
width::Int = 40
1212
current::Int = 0.0
1313
prev::Int = 0.0

src/Operations.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import ..Artifacts: ensure_all_artifacts_installed, artifact_names, extract_all_
1414
using Base.BinaryPlatforms
1515
import ...Pkg
1616
import ...Pkg: pkg_server
17-
import ...Pkg: can_fancyprint, DEFAULT_IO
17+
import ...Pkg: can_fancyprint, stderr_f
1818
import ..Types: printpkgstyle
1919

2020
#########
@@ -567,7 +567,7 @@ function install_archive(
567567
urls::Vector{Pair{String,Bool}},
568568
hash::SHA1,
569569
version_path::String;
570-
io::IO=DEFAULT_IO[]
570+
io::IO=stderr_f()
571571
)::Bool
572572
tmp_objects = String[]
573573
url_success = false
@@ -686,7 +686,7 @@ end
686686
function download_artifacts(ctx::Context, pkg_roots::Vector{String};
687687
platform::AbstractPlatform=HostPlatform(),
688688
verbose::Bool=false,
689-
io::IO=DEFAULT_IO[])
689+
io::IO=stderr_f())
690690
# List of Artifacts.toml files that we're going to download from
691691
artifacts_tomls = String[]
692692

@@ -850,7 +850,7 @@ function prune_manifest(ctx::Context)
850850
ctx.env.manifest = prune_manifest(ctx.env.manifest, keep)
851851
end
852852

853-
function prune_manifest(manifest::Dict, keep::Vector{UUID})
853+
function prune_manifest(manifest::Manifest, keep::Vector{UUID})
854854
while !isempty(keep)
855855
clean = true
856856
for (uuid, entry) in manifest
@@ -863,7 +863,8 @@ function prune_manifest(manifest::Dict, keep::Vector{UUID})
863863
end
864864
clean && break
865865
end
866-
return Dict(uuid => entry for (uuid, entry) in manifest if uuid in keep)
866+
manifest.deps = Dict(uuid => entry for (uuid, entry) in manifest if uuid in keep)
867+
return manifest
867868
end
868869

869870
function any_package_not_installed(ctx)
@@ -1463,9 +1464,9 @@ function sandbox_preserve(ctx::Context, target::PackageSpec, test_project::Strin
14631464
return prune_manifest(env.manifest, keep)
14641465
end
14651466

1466-
abspath!(ctx::Context, manifest::Dict{UUID,PackageEntry}) =
1467+
abspath!(ctx::Context, manifest::Manifest) =
14671468
abspath!(dirname(ctx.env.project_file), manifest)
1468-
function abspath!(project::String, manifest::Dict{UUID,PackageEntry})
1469+
function abspath!(project::String, manifest::Manifest)
14691470
for (uuid, entry) in manifest
14701471
if entry.path !== nothing
14711472
entry.path = project_rel_path(project, entry.path)
@@ -1524,7 +1525,7 @@ function sandbox(fn::Function, ctx::Context, target::PackageSpec, target_path::S
15241525
catch err# TODO
15251526
@debug err
15261527
@warn "Could not use exact versions of packages in manifest, re-resolving"
1527-
temp_ctx.env.manifest = Dict(uuid => entry for (uuid, entry) in temp_ctx.env.manifest if isfixed(entry))
1528+
temp_ctx.env.manifest.deps = Dict(uuid => entry for (uuid, entry) in temp_ctx.env.manifest.deps if isfixed(entry))
15281529
Pkg.resolve(temp_ctx; io=devnull)
15291530
@debug "Using _clean_ dep graph"
15301531
end
@@ -1657,7 +1658,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
16571658
printpkgstyle(ctx, :Testing, pkg.name)
16581659
sandbox(ctx, pkg, source_path, testdir(source_path), test_project_override) do
16591660
test_fn !== nothing && test_fn()
1660-
sandbox_ctx = Context()
1661+
sandbox_ctx = Context(;io=ctx.io)
16611662
status(sandbox_ctx; mode=PKGMODE_COMBINED)
16621663
Pkg._auto_precompile(sandbox_ctx)
16631664
printpkgstyle(ctx, :Testing, "Running tests...")
@@ -1740,7 +1741,7 @@ function stat_rep(x::PackageSpec; name=true)
17401741
return join(filter(!isempty, [name,version,repo,path,pinned]), " ")
17411742
end
17421743

1743-
print_single(ctx::Context, pkg::PackageSpec) = printstyled(ctx.io, stat_rep(pkg); color=:white)
1744+
print_single(ctx::Context, pkg::PackageSpec) = print(ctx.io, stat_rep(pkg))
17441745

17451746
is_instantiated(::Nothing) = false
17461747
is_instantiated(x::PackageSpec) = x.version != VersionSpec() || is_stdlib(x.uuid)

0 commit comments

Comments
 (0)