Skip to content

Commit

Permalink
Merge pull request #3647 from JuliaLang/backports-release-1.9
Browse files Browse the repository at this point in the history
[release-1.9] Backports 1.9
  • Loading branch information
KristofferC authored Oct 11, 2023
2 parents 6b0e085 + b9179df commit 4d5bb9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
46 changes: 32 additions & 14 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
# make a flat map of each dep and its direct deps
depsmap = Dict{Base.PkgId, Vector{Base.PkgId}}()
pkg_specs = PackageSpec[]
pkg_exts_map = Dict{Base.PkgId, Vector{Base.PkgId}}()
for dep in ctx.env.manifest
pkg = Base.PkgId(first(dep), last(dep).name)
Base.in_sysimage(pkg) && continue
Expand All @@ -1148,6 +1149,7 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
# add any extensions
weakdeps = last(dep).weakdeps
pkg_exts = Dict{Base.PkgId, Vector{Base.PkgId}}()
prev_ext = nothing
for (ext_name, extdep_names) in last(dep).exts
ext_deps = Base.PkgId[]
push!(ext_deps, pkg) # depends on parent package
Expand All @@ -1163,22 +1165,31 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
end
end
all_extdeps_available || continue
if prev_ext isa Base.PkgId
# also make the exts depend on eachother sequentially to avoid race
push!(ext_deps, prev_ext)
end
ext_uuid = Base.uuid5(pkg.uuid, ext_name)
ext = Base.PkgId(ext_uuid, ext_name)
prev_ext = ext
push!(pkg_specs, PackageSpec(uuid = ext_uuid, name = ext_name)) # create this here as the name cannot be looked up easily later via the uuid
filter!(!Base.in_sysimage, ext_deps)
depsmap[ext] = ext_deps
exts[ext] = pkg.name
pkg_exts[ext] = ext_deps
end
if !isempty(pkg_exts)
# find any packages that depend on the extension(s)'s deps and replace those deps in their deps list with the extension(s),
# basically injecting the extension into the precompile order in the graph, to avoid race to precompile extensions
for (_pkg, deps) in depsmap # for each manifest dep
if !in(_pkg, keys(exts)) && pkg in deps # if not an extension and depends on pkg
append!(deps, keys(pkg_exts)) # add the package extensions to deps
filter!(!isequal(pkg), deps) # remove the pkg from deps
end
pkg_exts_map[pkg] = collect(keys(pkg_exts))
end
end
# this loop must be run after the full depsmap has been populated
for (pkg, pkg_exts) in pkg_exts_map
# find any packages that depend on the extension(s)'s deps and replace those deps in their deps list with the extension(s),
# basically injecting the extension into the precompile order in the graph, to avoid race to precompile extensions
for (_pkg, deps) in depsmap # for each manifest dep
if !in(_pkg, keys(exts)) && pkg in deps # if not an extension and depends on pkg
append!(deps, pkg_exts) # add the package extensions to deps
filter!(!isequal(pkg), deps) # remove the pkg from deps
end
end
end
Expand Down Expand Up @@ -1337,31 +1348,38 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool
end
bar.current = n_done - n_already_precomp
bar.max = n_total - n_already_precomp
final_loop || print(iostr, sprint(io -> show_progress(io, bar; termwidth = displaysize(ctx.io)[2]); context=io), "\n")
# when sizing to the terminal width subtract a little to give some tolerance to resizing the
# window between print cycles
termwidth = displaysize(io)[2] - 4
if !final_loop
str = sprint(io -> show_progress(io, bar; termwidth, carriagereturn=false); context=io)
print(iostr, Base._truncate_at_width_or_chars(true, str, termwidth), "\n")
end
for dep in pkg_queue_show
loaded = warn_loaded && haskey(Base.loaded_modules, dep)
_name = haskey(exts, dep) ? string(exts[dep], "", dep.name) : dep.name
name = dep in direct_deps ? _name : string(color_string(_name, :light_black))
if dep in precomperr_deps
print(iostr, color_string(" ? ", Base.warn_color()), name, "\n")
line = if dep in precomperr_deps
string(color_string(" ? ", Base.warn_color()), name)
elseif haskey(failed_deps, dep)
print(iostr, color_string("", Base.error_color()), name, "\n")
string(color_string("", Base.error_color()), name)
elseif was_recompiled[dep]
!loaded && interrupted_or_done.set && continue
print(iostr, color_string("", loaded ? Base.warn_color() : :green), name, "\n")
loaded || @async begin # keep successful deps visible for short period
sleep(1);
filter!(!isequal(dep), pkg_queue)
end
string(color_string("", loaded ? Base.warn_color() : :green), name)
elseif started[dep]
# Offset each spinner animation using the first character in the package name as the seed.
# If not offset, on larger terminal fonts it looks odd that they all sync-up
anim_char = anim_chars[(i + Int(dep.name[1])) % length(anim_chars) + 1]
anim_char_colored = dep in direct_deps ? anim_char : color_string(anim_char, :light_black)
print(iostr, " $anim_char_colored $name\n")
string(" ", anim_char_colored, " ", name)
else
print(iostr, " $name\n")
string(" ", name)
end
println(iostr, Base._truncate_at_width_or_chars(true, line, termwidth))
end
end
last_length = length(pkg_queue_show)
Expand Down
6 changes: 3 additions & 3 deletions src/MiniProgressBars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function start_progress(io::IO, _::MiniProgressBar)
print(io, ansi_disablecursor)
end

function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing)
function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing, carriagereturn=true)
if p.max == 0
perc = 0.0
prev_perc = 0.0
Expand All @@ -52,7 +52,7 @@ function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing)
else
string(p.current, "/", p.max)
end
termwidth = something(termwidth, displaysize(io)[2])
termwidth = @something termwidth displaysize(io)[2]
max_progress_width = max(0, min(termwidth - textwidth(p.header) - textwidth(progress_text) - 10 , p.width))
n_filled = ceil(Int, max_progress_width * perc / 100)
n_left = max_progress_width - n_filled
Expand All @@ -63,7 +63,7 @@ function show_progress(io::IO, p::MiniProgressBar; termwidth=nothing)
print(io, "="^n_filled, ">")
print(io, " "^n_left, "] ", )
print(io, progress_text)
print(io, "\r")
carriagereturn && print(io, "\r")
end
# Print everything in one call
print(io, to_print)
Expand Down

0 comments on commit 4d5bb9d

Please sign in to comment.