diff --git a/ext/REPLExt/precompile.jl b/ext/REPLExt/precompile.jl index a295f66fc8..268cbc1204 100644 --- a/ext/REPLExt/precompile.jl +++ b/ext/REPLExt/precompile.jl @@ -14,7 +14,7 @@ let original_load_path = copy(LOAD_PATH) __init__() Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true - Pkg.DEFAULT_IO[] = Pkg.UnstableIO(devnull) + Pkg.DEFAULT_IO[] = Pkg.unstableio(devnull) withenv("JULIA_PKG_SERVER" => nothing, "JULIA_PKG_UNPACK_REGISTRY" => nothing) do tmp = Pkg._run_precompilation_script_setup() cd(tmp) do diff --git a/src/API.jl b/src/API.jl index 212d2c3de1..6a3b74be9f 100644 --- a/src/API.jl +++ b/src/API.jl @@ -12,7 +12,7 @@ import FileWatching import Base: StaleCacheKey -import ..depots, ..depots1, ..logdir, ..devdir, ..printpkgstyle, ..UnstableIO +import ..depots, ..depots1, ..logdir, ..devdir, ..printpkgstyle import ..Operations, ..GitTools, ..Pkg, ..Registry import ..can_fancyprint, ..pathrepr, ..isurl, ..PREV_ENV_PATH using ..Types, ..TOML @@ -1146,8 +1146,8 @@ function precompile(ctx::Context, pkgs::Vector{PackageSpec}; internal_call::Bool end io = ctx.io - if io isa UnstableIO - # precompile does quite a bit of output and using the UnstableIO can cause + if io isa IOContext{IO} + # precompile does quite a bit of output and using the IOContext{IO} can cause # some slowdowns, the important part here is to not specialize the whole # precompile function on the io io = io.io diff --git a/src/Operations.jl b/src/Operations.jl index 7e837c74c8..c812c13205 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -12,7 +12,7 @@ import ..Artifacts: ensure_artifact_installed, artifact_names, extract_all_hashe artifact_exists, select_downloadable_artifacts using Base.BinaryPlatforms import ...Pkg -import ...Pkg: pkg_server, Registry, pathrepr, can_fancyprint, printpkgstyle, stderr_f, OFFLINE_MODE, UnstableIO +import ...Pkg: pkg_server, Registry, pathrepr, can_fancyprint, printpkgstyle, stderr_f, OFFLINE_MODE import ...Pkg: UPDATED_REGISTRY_THIS_SESSION, RESPECT_SYSIMAGE_VERSIONS, should_autoprecompile ######### @@ -2108,8 +2108,8 @@ end function subprocess_handler(cmd::Cmd, ctx, sandbox_ctx, error_msg::String) stdout = sandbox_ctx.io stderr = stderr_f() - stdout isa UnstableIO && (stdout = stdout.io) - stderr isa UnstableIO && (stderr = stderr.io) + stdout isa IOContext{IO} && (stdout = stdout.io) + stderr isa IOContext{IO} && (stderr = stderr.io) @debug "Running command" cmd p = run(pipeline(ignorestatus(cmd); stdout, stderr), wait = false) interrupted = false diff --git a/src/Pkg.jl b/src/Pkg.jl index 4e776c93c7..d62ceb2e3f 100644 --- a/src/Pkg.jl +++ b/src/Pkg.jl @@ -40,17 +40,20 @@ const RESPECT_SYSIMAGE_VERSIONS = Ref(true) # For globally overriding in e.g. tests const DEFAULT_IO = Ref{Union{IO,Nothing}}(nothing) -struct UnstableIO <: IO - io::IO +# See discussion in https://github.com/JuliaLang/julia/pull/52249 +function unstableio(@nospecialize(io::IO)) + # Needed to prevent specialization https://github.com/JuliaLang/julia/pull/52249#discussion_r1401199265 + _io = Base.inferencebarrier(io) + IOContext{IO}( + _io, + get(_io,:color,false) ? Base.ImmutableDict{Symbol,Any}(:color, true) : Base.ImmutableDict{Symbol,Any}() + ) end -Base.write(io::UnstableIO, b::UInt8) = write(io.io, b)::Int -Base.get(io::UnstableIO, val, default) = get(io.io, val, default) -Base.print(io::UnstableIO, arg::Union{SubString{String}, String}) = print(io.io, arg) -stderr_f() = something(DEFAULT_IO[], UnstableIO(stderr)) -stdout_f() = something(DEFAULT_IO[], UnstableIO(stdout)) +stderr_f() = something(DEFAULT_IO[], unstableio(stderr)) +stdout_f() = something(DEFAULT_IO[], unstableio(stdout)) const PREV_ENV_PATH = Ref{String}("") -can_fancyprint(io::IO) = ((io isa Base.TTY) || (io isa UnstableIO && io.io isa Base.TTY)) && (get(ENV, "CI", nothing) != "true") +can_fancyprint(io::IO) = ((io isa Base.TTY) || (io isa IOContext{IO} && io.io isa Base.TTY)) && (get(ENV, "CI", nothing) != "true") should_autoprecompile() = Base.JLOptions().use_compiled_modules == 1 && Base.get_bool_env("JULIA_PKG_PRECOMPILE_AUTO", true) include("utils.jl") diff --git a/src/precompile.jl b/src/precompile.jl index 35dde8b3dd..72b796a5cb 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -105,7 +105,7 @@ let Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true # Default 30 sec grace period means we hang 30 seconds before precompiling finishes - DEFAULT_IO[] = UnstableIO(devnull) + DEFAULT_IO[] = unstableio(devnull) Downloads.DOWNLOADER[] = Downloads.Downloader(; grace = 1.0) # We need to override JULIA_PKG_UNPACK_REGISTRY to fix https://github.com/JuliaLang/Pkg.jl/issues/3663