Skip to content

Commit

Permalink
Fix PkgId repr (#52795)
Browse files Browse the repository at this point in the history
Fixes #52793 

```
% ./julia  --startup-file=no -E 'repr(Base.PkgId(Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe"), "Revise"))'
"Base.PkgId(UUID(\"295af30f-e4ad-537b-8983-00126c2a3abe\"), \"Revise\")"
```
```
julia> Base.PkgId(Base.UUID("295af30f-e4ad-537b-8983-00126c2a3abe"), "Revise")
Revise [295af30f-e4ad-537b-8983-00126c2a3abe]
```
  • Loading branch information
IanButterworth authored Feb 8, 2024
1 parent 4d0a469 commit 4414599
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,10 @@ function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{No
end

if ocachepath !== nothing
@debug "Loading object cache file $ocachepath for $pkg"
@debug "Loading object cache file $ocachepath for $(repr("text/plain", pkg))"
sv = ccall(:jl_restore_package_image_from_file, Any, (Cstring, Any, Cint, Cstring, Cint), ocachepath, depmods, false, pkg.name, ignore_native)
else
@debug "Loading cache file $path for $pkg"
@debug "Loading cache file $path for $(repr("text/plain", pkg))"
sv = ccall(:jl_restore_incremental, Any, (Cstring, Any, Cint, Cstring), path, depmods, false, pkg.name)
end
if isa(sv, Exception)
Expand Down Expand Up @@ -1160,7 +1160,7 @@ function _include_from_serialized(pkg::PkgId, path::String, ocachepath::Union{No
return M
end
end
return ErrorException("Required dependency $pkg failed to load from a cache file.")
return ErrorException("Required dependency $(repr("text/plain", pkg)) failed to load from a cache file.")

finally
timing_imports && cumulative_compile_timing(false)
Expand Down Expand Up @@ -2101,7 +2101,7 @@ function _require(pkg::PkgId, env=nothing)
path = locate_package(pkg, env)
if path === nothing
throw(ArgumentError("""
Package $pkg is required but does not seem to be installed:
Package $(repr("text/plain", pkg)) is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
"""))
end
Expand All @@ -2123,7 +2123,7 @@ function _require(pkg::PkgId, env=nothing)
for (concrete_pkg, concrete_build_id) in _concrete_dependencies
if pkg == concrete_pkg
@warn """Module $(pkg.name) with build ID $((UUID(concrete_build_id))) is missing from the cache.
This may mean $pkg does not support precompilation but is imported by a module that does."""
This may mean $(repr("text/plain", pkg)) does not support precompilation but is imported by a module that does."""
if JLOptions().incremental != 0
# during incremental precompilation, this should be fail-fast
throw(PrecompilableError())
Expand Down Expand Up @@ -2157,16 +2157,16 @@ function _require(pkg::PkgId, env=nothing)
elseif isa(cachefile, Exception)
if precompilableerror(cachefile)
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
@logmsg verbosity "Skipping precompilation due to precompilable error. Importing $pkg." exception=m
@logmsg verbosity "Skipping precompilation due to precompilable error. Importing $(repr("text/plain", pkg))." exception=m
else
@warn "The call to compilecache failed to create a usable precompiled cache file for $pkg" exception=m
@warn "The call to compilecache failed to create a usable precompiled cache file for $(repr("text/plain", pkg))" exception=m
end
# fall-through to loading the file locally if not incremental
else
cachefile, ocachefile = cachefile::Tuple{String, Union{Nothing, String}}
m = _tryrequire_from_serialized(pkg, cachefile, ocachefile)
if !isa(m, Module)
@warn "The call to compilecache failed to create a usable precompiled cache file for $pkg" exception=m
@warn "The call to compilecache failed to create a usable precompiled cache file for $(repr("text/plain", pkg))" exception=m
else
return m
end
Expand Down Expand Up @@ -2393,15 +2393,15 @@ function check_src_module_wrap(pkg::PkgId, srcpath::String)
inside_string && continue
if contains(s, module_rgx)
if load_seen
throw(ErrorException("Package $pkg source file $srcpath has a using/import before a module declaration."))
throw(ErrorException("Package $(repr("text/plain", pkg)) source file $srcpath has a using/import before a module declaration."))
end
return true
end
if startswith(s, load_rgx)
load_seen = true
end
end
throw(ErrorException("Package $pkg source file $srcpath does not contain a module declaration."))
throw(ErrorException("Package $(repr("text/plain", pkg)) source file $srcpath does not contain a module declaration."))
end

# this is called in the external process that generates precompiled package files
Expand Down Expand Up @@ -2480,12 +2480,12 @@ function create_expr_cache(pkg::PkgId, input::String, output::String, output_o::
end

if output_o !== nothing
@debug "Generating object cache file for $pkg"
@debug "Generating object cache file for $(repr("text/plain", pkg))"
cpu_target = get(ENV, "JULIA_CPU_TARGET", nothing)
opt_level = Base.JLOptions().opt_level
opts = `-O$(opt_level) --output-o $(output_o) --output-ji $(output) --output-incremental=yes`
else
@debug "Generating cache file for $pkg"
@debug "Generating cache file for $(repr("text/plain", pkg))"
cpu_target = nothing
opts = `-O0 --output-ji $(output) --output-incremental=yes`
end
Expand Down Expand Up @@ -2553,7 +2553,7 @@ for important notes.
function compilecache(pkg::PkgId, internal_stderr::IO = stderr, internal_stdout::IO = stdout; reasons::Union{Dict{String,Int},Nothing}=Dict{String,Int}())
@nospecialize internal_stderr internal_stdout
path = locate_package(pkg)
path === nothing && throw(ArgumentError("$pkg not found during precompilation"))
path === nothing && throw(ArgumentError("$(repr("text/plain", pkg)) not found during precompilation"))
return compilecache(pkg, path, internal_stderr, internal_stdout; reasons)
end

Expand All @@ -2577,7 +2577,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
end
# run the expression and cache the result
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
@logmsg verbosity "Precompiling $pkg $(list_reasons(reasons))"
@logmsg verbosity "Precompiling $(repr("text/plain", pkg)) $(list_reasons(reasons))"

# create a temporary file in `cachepath` directory, write the cache in it,
# write the checksum, _and then_ atomically move the file to `cachefile`.
Expand Down Expand Up @@ -2621,7 +2621,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
# append extra crc to the end of the .ji file:
open(tmppath, "r+") do f
if iszero(isvalid_cache_header(f))
error("Invalid header for $pkg in new cache file $(repr(tmppath)).")
error("Invalid header for $(repr("text/plain", pkg)) in new cache file $(repr(tmppath)).")
end
seekend(f)
write(f, crc_so)
Expand Down Expand Up @@ -2692,7 +2692,7 @@ function compilecache(pkg::PkgId, path::String, internal_stderr::IO = stderr, in
if p.exitcode == 125
return PrecompilableError()
else
error("Failed to precompile $pkg to $(repr(tmppath)).")
error("Failed to precompile $(repr("text/plain", pkg)) to $(repr(tmppath)).")
end
end

Expand Down Expand Up @@ -3283,9 +3283,9 @@ function maybe_cachefile_lock(f, pkg::PkgId, srcpath::String; stale_age=compilec
pid, hostname, age = invokelatest(parse_pidfile_hook, pidfile)
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
if isempty(hostname) || hostname == gethostname()
@logmsg verbosity "Waiting for another process (pid: $pid) to finish precompiling $pkg. Pidfile: $pidfile"
@logmsg verbosity "Waiting for another process (pid: $pid) to finish precompiling $(repr("text/plain", pkg)). Pidfile: $pidfile"
else
@logmsg verbosity "Waiting for another machine (hostname: $hostname, pid: $pid) to finish precompiling $pkg. Pidfile: $pidfile"
@logmsg verbosity "Waiting for another machine (hostname: $hostname, pid: $pid) to finish precompiling $(repr("text/plain", pkg)). Pidfile: $pidfile"
end
# wait until the lock is available, but don't actually acquire it
# returning nothing indicates a process waited for another
Expand Down Expand Up @@ -3438,7 +3438,7 @@ end
# verify that `require(modkey, name(req_modkey))` ==> `req_modkey`
pkg = identify_package(modkey, req_modkey.name)
if pkg != req_modkey
@debug "Rejecting cache file $cachefile because uuid mapping for $modkey => $req_modkey has changed, expected $modkey => $pkg"
@debug "Rejecting cache file $cachefile because uuid mapping for $modkey => $req_modkey has changed, expected $modkey => $(repr("text/plain", pkg))"
record_reason(reasons, "dep uuid changed")
return true
end
Expand Down
2 changes: 1 addition & 1 deletion base/pkgid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function hash(pkg::PkgId, h::UInt)
return h
end

show(io::IO, pkg::PkgId) =
show(io::IO, ::MIME"text/plain", pkg::PkgId) =
print(io, pkg.name, " [", pkg.uuid === nothing ? "top-level" : pkg.uuid, "]")

function binpack(pkg::PkgId)
Expand Down

0 comments on commit 4414599

Please sign in to comment.