Repository: JuliaLang/julia
File: base/precompilation.jl (Julia)

Code before:
                                errmsg = String(take!(get(IOBuffer, std_outputs, pkg_config)))
                                delete!(std_outputs, pkg_config) # so it's not shown as warnings, given error report
                                failed_deps[pkg_config] = (strict || is_project_dep) ? string(sprint(showerror, err), "\n", strip(errmsg)) : ""
                                !fancyprint && @lock print_lock begin
                                    println(io, " "^12, color_string("  ✗ ", Base.error_color()), name)
                                end
                            else
                                rethrow()
                            end
                        finally
                            isopen(std_pipe.in) && close(std_pipe.in) # close pipe to end the std output monitor
                            wait(t_monitor)
                            Base.release(parallel_limiter)
                        end
                    else
                        is_stale || (n_already_precomp[] += 1)
                    end
                    n_done[] += 1
                    notify(was_processed[pkg_config])
                catch err_outer
                    # For debugging:
                    # println("Task failed $err_outer")
                    # Base.display_error(ErrorException(""), Base.catch_backtrace())# logging doesn't show here
                    handle_interrupt(err_outer, false)
                    rethrow()
                end
            end
            push!(tasks, task)
        end
    end
    try
        waitall(tasks; failfast=false, throw=false)
        interrupted_or_done[] = true
    catch err
        # For debugging:
        # println("Task failed $err")
        # Base.display_error(ErrorException(""), Base.catch_backtrace())# logging doesn't show here
        handle_interrupt(err, false) || rethrow()
    finally
        try
            waitall(tasks; failfast=false, throw=false)
        finally
            @lock Base.require_lock begin
                Base.LOADING_CACHE[] = nothing
            end
        end
    end
    notify(first_started) # in cases of no-op or !fancyprint
    fancyprint && wait(t_print)
    quick_exit = any(t -> !istaskdone(t) || istaskfailed(t), tasks) || interrupted[] # all should have finished (to avoid memory corruption)
    seconds_elapsed = round(Int, (time_ns() - time_start) / 1e9)

Review comment (suggestion):
Based on a bit of Claude.. I think this sounds reasonable:
```suggestion
                            loadable_exts = haskey(ext_to_parent, pkg) ? filter((dep)->haskey(ext_to_parent, dep), triggers[pkg]) : nothing
```
For an extension `ext`, `triggers[ext]` contains all triggers (including parent + trigger packages), some of which may be in the sysimage. `direct_deps[ext]` is `filter(!Base.in_sysimage, triggers[ext])` - so it excludes sysimage packages

Code after:
                    end
                    if !circular && is_stale
                        Base.acquire(parallel_limiter)
                        is_serial_dep = pkg in serial_deps
                        is_project_dep = pkg in project_deps

                        # std monitoring
                        std_pipe = Base.link_pipe!(Pipe(); reader_supports_async=true, writer_supports_async=true)
                        t_monitor = @async monitor_std(pkg_config, std_pipe; single_requested_pkg)

                        try
                            name = describe_pkg(pkg, is_project_dep, is_serial_dep, flags, cacheflags)
                            @lock print_lock begin
                                if !fancyprint && isempty(pkg_queue)
                                    printpkgstyle(logio, :Precompiling, something(target[], "packages..."))
                                end
                            end
                            push!(pkg_queue, pkg_config)
                            started[pkg_config] = true
                            fancyprint && notify(first_started)
                            if interrupted_or_done[]
                                return
                            end
                            # for extensions, any extension in our direct dependencies is one we have a right to load
                            # for packages, we may load any extension (all possible triggers are accounted for above)
                            loadable_exts = haskey(ext_to_parent, pkg) ? filter((dep)->haskey(ext_to_parent, dep), deps) : nothing
                            if !isempty(deps)
                                # if deps is empty, either it doesn't have any (so compiled-modules is
                                # irrelevant) or we couldn't compute them (so we actually should attempt
                                # serial compile, as the dependencies are not in the parallel list)
                                flags = `$flags --compiled-modules=strict`
                            end
                            if _from_loading && pkg in requested_pkgids
                                # loading already took the cachefile_lock and printed logmsg for its explicit requests
                                t = @elapsed ret = begin
                                    Base.compilecache(pkg, sourcepath, std_pipe, std_pipe, !ignore_loaded;
                                                      flags, cacheflags, loadable_exts)
                                end
                            else
                                # 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_config, pkgspidlocked, hascolor, parallel_limiter) do
                                    # refresh and double-check the search now that we have global lock
                                    if interrupted_or_done[]
                                        return ErrorException("canceled")
                                    end
                                    cachepaths = Base.find_all_in_cache_path(pkg)
                                    local freshpath = Base.compilecache_freshest_path(pkg; ignore_loaded, stale_cache, cachepath_cache, cachepaths, sourcepath, flags=cacheflags)
                                    local is_stale = freshpath === nothing
                                    if !is_stale
                                        push!(freshpaths, freshpath)