Skip to content

Commit 9adb32b

Browse files
authored
Merge pull request #2354 from ianshmean/ib/16_more_backport
[release-1.6] more backport
2 parents b4a8014 + 88b512e commit 9adb32b

File tree

10 files changed

+59
-18
lines changed

10 files changed

+59
-18
lines changed

ext/HistoricaStdlibGenerator/generate_historical_stdlibs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ open(output_fname, "w") do io
164164
165165
# Julia standard libraries with duplicate entries removed so as to store only the
166166
# first release in a set of releases that all contain the same set of stdlibs.
167-
STDLIBS_BY_VERSION = [
167+
const STDLIBS_BY_VERSION = [
168168
""")
169169
for v in sorted_versions
170170
print(io, " $(repr(v)) => ")
@@ -176,7 +176,7 @@ open(output_fname, "w") do io
176176
# Next, we also embed a list of stdlibs that must _always_ be treated as stdlibs,
177177
# because they cannot be resolved in the registry; they have only ever existed within
178178
# the Julia stdlib source tree, and because of that, trying to resolve them will fail.
179-
UNREGISTERED_STDLIBS = Dict(
179+
const UNREGISTERED_STDLIBS = Dict(
180180
""")
181181
for (uuid, name) in unregistered_stdlibs
182182
println(io, " $(repr(uuid)) => $(repr(name)),")

src/API.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,16 @@ function make_pkgspec(man, uuid)
910910
end
911911

912912
precompile(; kwargs...) = precompile(Context(); kwargs...)
913-
function precompile(ctx::Context; internal_call::Bool=false, kwargs...)
913+
function precompile(ctx::Context; internal_call::Bool=false, strict::Bool=false, kwargs...)
914914
Context!(ctx; kwargs...)
915915
instantiate(ctx; allow_autoprecomp=false, kwargs...)
916916
time_start = time_ns()
917-
num_tasks = parse(Int, get(ENV, "JULIA_NUM_PRECOMPILE_TASKS", string(Sys.CPU_THREADS::Int + 1)))
917+
918+
# Windows sometimes hits a ReadOnlyMemoryError, so we halve the default number of tasks. Issue #2323
919+
# TODO: Investigate why this happens in windows and restore the full task limit
920+
default_num_tasks = Sys.iswindows() ? div(Sys.CPU_THREADS::Int, 2) + 1 : Sys.CPU_THREADS::Int + 1
921+
922+
num_tasks = parse(Int, get(ENV, "JULIA_NUM_PRECOMPILE_TASKS", string(default_num_tasks)))
918923
parallel_limiter = Base.Semaphore(num_tasks)
919924
io = ctx.io
920925
fancyprint = can_fancyprint(io)
@@ -1139,7 +1144,7 @@ function precompile(ctx::Context; internal_call::Bool=false, kwargs...)
11391144
end
11401145
catch err
11411146
if err isa ErrorException
1142-
failed_deps[pkg] = is_direct_dep ? String(take!(iob)) : ""
1147+
failed_deps[pkg] = (strict || is_direct_dep) ? String(take!(iob)) : ""
11431148
!fancyprint && lock(print_lock) do
11441149
println(io, string(color_string("", Base.error_color()), name))
11451150
end
@@ -1208,15 +1213,16 @@ function precompile(ctx::Context; internal_call::Bool=false, kwargs...)
12081213
err_str = ""
12091214
n_direct_errs = 0
12101215
for (dep, err) in failed_deps
1211-
if dep in direct_deps
1216+
if strict || (dep in direct_deps)
12121217
err_str *= "\n" * "$dep" * "\n\n" * err * (n_direct_errs > 0 ? "\n" : "")
12131218
n_direct_errs += 1
12141219
end
12151220
end
12161221
if err_str != ""
12171222
println(io, "")
12181223
plural = n_direct_errs == 1 ? "y" : "ies"
1219-
pkgerror("The following $( n_direct_errs) direct dependenc$(plural) failed to precompile:\n$(err_str[1:end-1])")
1224+
direct = strict ? "" : "direct "
1225+
pkgerror("The following $n_direct_errs $(direct)dependenc$(plural) failed to precompile:\n$(err_str[1:end-1])")
12201226
end
12211227
end
12221228
end

src/HistoricalStdlibs.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using Base: UUID
44

55
# Julia standard libraries with duplicate entries removed so as to store only the
66
# first release in a set of releases that all contain the same set of stdlibs.
7-
STDLIBS_BY_VERSION = [
7+
const STDLIBS_BY_VERSION = [
88
v"1.0.0" => Dict(
99
UUID("2a0f44e3-6c83-55bd-87e4-b1978d98bd5f") => "Base64",
1010
UUID("8bf52ea8-c179-5cab-976a-9e18b702a9bc") => "CRC32c",
@@ -99,7 +99,7 @@ STDLIBS_BY_VERSION = [
9999
# Next, we also embed a list of stdlibs that must _always_ be treated as stdlibs,
100100
# because they cannot be resolved in the registry; they have only ever existed within
101101
# the Julia stdlib source tree, and because of that, trying to resolve them will fail.
102-
UNREGISTERED_STDLIBS = Dict(
102+
const UNREGISTERED_STDLIBS = Dict(
103103
UUID("9a3f8284-a2c9-5f02-9a11-845980a1fd5c") => "Random",
104104
UUID("10745b16-79ce-11e8-11f9-7d13ad32a3b2") => "Statistics",
105105
UUID("8bb1440f-4735-579b-a4ab-409b98df4dab") => "DelimitedFiles",

src/Operations.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,15 @@ function is_instantiated(ctx::Context)::Bool
116116
pkgs = load_all_deps(ctx)
117117
# If the top-level project is a package, ensure it is instantiated as well
118118
if ctx.env.pkg !== nothing
119-
push!(pkgs, Types.PackageSpec(
120-
name=ctx.env.pkg.name, uuid=ctx.env.pkg.uuid, version=ctx.env.pkg.version, path=dirname(ctx.env.project_file)
121-
))
119+
# Top-level project may already be in the manifest (cyclic deps)
120+
# so only add it if it isn't there
121+
idx = findfirst(x -> x.uuid == ctx.env.pkg.uuid, pkgs)
122+
if idx === nothing
123+
push!(pkgs, Types.PackageSpec(
124+
name=ctx.env.pkg.name, uuid=ctx.env.pkg.uuid, version=ctx.env.pkg.version,
125+
path=dirname(ctx.env.project_file)
126+
))
127+
end
122128
end
123129
# Make sure all paths/artifacts exist
124130
return all(pkg -> is_package_downloaded(ctx, pkg), pkgs)

src/Pkg.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ See also [`PackageSpec`](@ref).
127127
const add = API.add
128128

129129
"""
130-
Pkg.precompile()
130+
Pkg.precompile(; strict::Bool=false)
131131
132132
Precompile all the dependencies of the project in parallel.
133133
!!! note
134134
Errors will only throw when precompiling the top-level dependencies, given that
135135
not all manifest dependencies may be loaded by the top-level dependencies on the given system.
136+
This can be overridden to make errors in all dependencies throw by setting the kwarg `strict` to `true`
136137
137138
!!! note
138139
This method is called automatically after any Pkg action that changes the manifest.
@@ -586,7 +587,7 @@ end
586587
##################
587588

588589
function _auto_precompile(ctx::Types.Context)
589-
if tryparse(Int, get(ENV, "JULIA_PKG_PRECOMPILE_AUTO", "1")) == 1
590+
if Base.JLOptions().use_compiled_modules == 1 && tryparse(Int, get(ENV, "JULIA_PKG_PRECOMPILE_AUTO", "1")) == 1
590591
Pkg.precompile(ctx; internal_call=true)
591592
end
592593
end

src/PlatformEngines.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function find7z()
2727
name = "7z"
2828
Sys.iswindows() && (name = "$name.exe")
2929
for dir in (joinpath("..", "libexec"), ".")
30-
path = normpath(Sys.BINDIR, dir, name)
30+
path = normpath(Sys.BINDIR::String, dir, name)
3131
isfile(path) && return path
3232
end
3333
path = Sys.which(name)

src/Types.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ end
986986

987987
pkg_server_url_hash(url::String) = split(url, '/')[end]
988988

989+
registry_use_pkg_server() =
990+
!Sys.iswindows() || haskey(ENV, "JULIA_PKG_SERVER")
991+
989992
# entry point for `registry add`
990993
function clone_or_cp_registries(ctx::Context, regs::Vector{RegistrySpec}, depot::String=depots1())
991994
populate_known_registries_with_urls!(regs)
@@ -998,7 +1001,7 @@ function clone_or_cp_registries(ctx::Context, regs::Vector{RegistrySpec}, depot:
9981001
mktempdir() do tmp
9991002
url, registry_urls = pkg_server_registry_url(reg.uuid, registry_urls)
10001003
# on Windows we prefer git cloning because untarring is so slow
1001-
if !Sys.iswindows() && url !== nothing
1004+
if url !== nothing && registry_use_pkg_server()
10021005
# download from Pkg server
10031006
try
10041007
download_verify_unpack(url, nothing, tmp, ignore_existence = true)
@@ -1031,7 +1034,7 @@ function clone_or_cp_registries(ctx::Context, regs::Vector{RegistrySpec}, depot:
10311034
# slug = Base.package_slug(UUID(registry["uuid"]))
10321035
regpath = joinpath(depot, "registries", registry["name"]::String#=, slug=#)
10331036
ispath(dirname(regpath)) || mkpath(dirname(regpath))
1034-
if Pkg.isdir_nothrow(regpath)
1037+
if isfile(joinpath(regpath, "Registry.toml"))
10351038
existing_registry = read_registry(joinpath(regpath, "Registry.toml"))
10361039
if registry["uuid"] == existing_registry["uuid"]
10371040
println(ctx.io,
@@ -1043,7 +1046,7 @@ function clone_or_cp_registries(ctx::Context, regs::Vector{RegistrySpec}, depot:
10431046
"`$(Base.contractuser(joinpath(depot, "registries", registry["name"]*"-2")))`."))
10441047
end
10451048
else
1046-
mv(tmp, regpath)
1049+
mv(tmp, regpath, force=true)
10471050
printpkgstyle(ctx, :Added, "registry `$(registry["name"])` to `$(Base.contractuser(regpath))`")
10481051
end
10491052
end

test/misc.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using Test
2+
using Pkg
3+
4+
@testset "inference" begin
5+
f() = Pkg.Types.STDLIBS_BY_VERSION
6+
@inferred f()
7+
f() = Pkg.Types.UNREGISTERED_STDLIBS
8+
@inferred f()
9+
end

test/new.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,21 @@ end
24132413
Pkg.add(path="A")
24142414
end
24152415
end
2416+
# test #2302
2417+
isolate(loaded_depot=true) do
2418+
cd_tempdir() do dir
2419+
Pkg.generate("A")
2420+
Pkg.generate("B")
2421+
git_init_and_commit("B")
2422+
Pkg.develop(path="B")
2423+
Pkg.activate("A")
2424+
Pkg.add(path="B")
2425+
git_init_and_commit("A")
2426+
Pkg.activate("B")
2427+
# This shouldn't error even though A has a dependency on B
2428+
Pkg.add(path="A")
2429+
end
2430+
end
24162431
end
24172432

24182433
@testset "Offline mode" begin

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ include("binaryplatforms.jl")
2626
include("platformengines.jl")
2727
include("sandbox.jl")
2828
include("resolve.jl")
29+
include("misc.jl")
2930

3031
# clean up locally cached registry
3132
rm(joinpath(@__DIR__, "registries"); force = true, recursive = true)

0 commit comments

Comments
 (0)