Skip to content

Commit 115e303

Browse files
add option for Pkg.build to allow_reresolve=false (#3329)
1 parent c1d5f73 commit 115e303

File tree

11 files changed

+141
-8
lines changed

11 files changed

+141
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Pkg v1.13 Release Notes
22
=======================
33

44
- Project.toml environments now support a `readonly` field to mark environments as read-only, preventing modifications. ([#4284])
5+
- `Pkg.build` now supports an `allow_reresolve` keyword argument to control whether the build process can re-resolve package versions, similar to the existing option for `Pkg.test`. ([#3329])
56
- Packages are now automatically added to `[sources]` when they are added by url or devved.
67

78
Pkg v1.12 Release Notes

src/API.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
11181118
return
11191119
end
11201120

1121-
function build(ctx::Context, pkgs::Vector{PackageSpec}; verbose=false, kwargs...)
1121+
function build(ctx::Context, pkgs::Vector{PackageSpec}; verbose=false, allow_reresolve::Bool=true, kwargs...)
11221122
Context!(ctx; kwargs...)
11231123

11241124
if isempty(pkgs)
@@ -1133,7 +1133,7 @@ function build(ctx::Context, pkgs::Vector{PackageSpec}; verbose=false, kwargs...
11331133
project_resolve!(ctx.env, pkgs)
11341134
manifest_resolve!(ctx.env.manifest, pkgs)
11351135
ensure_resolved(ctx, ctx.env.manifest, pkgs)
1136-
Operations.build(ctx, Set{UUID}(pkg.uuid for pkg in pkgs), verbose)
1136+
Operations.build(ctx, Set{UUID}(pkg.uuid for pkg in pkgs), verbose; allow_reresolve)
11371137
end
11381138

11391139
function get_or_make_pkgspec(pkgspecs::Vector{PackageSpec}, ctx::Context, uuid)

src/Operations.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,12 +1312,12 @@ function any_package_not_installed(manifest::Manifest)
13121312
return false
13131313
end
13141314

1315-
function build(ctx::Context, uuids::Set{UUID}, verbose::Bool)
1315+
function build(ctx::Context, uuids::Set{UUID}, verbose::Bool; allow_reresolve::Bool=true)
13161316
if any_package_not_installed(ctx.env.manifest) || !isfile(ctx.env.manifest_file)
13171317
Pkg.instantiate(ctx, allow_build = false, allow_autoprecomp = false)
13181318
end
13191319
all_uuids = get_deps(ctx.env, uuids)
1320-
build_versions(ctx, all_uuids; verbose)
1320+
build_versions(ctx, all_uuids; verbose, allow_reresolve)
13211321
end
13221322

13231323
function dependency_order_uuids(env::EnvCache, uuids::Vector{UUID})::Dict{UUID,Int}
@@ -1377,7 +1377,7 @@ pkg_scratchpath() = joinpath(depots1(), "scratchspaces", PkgUUID)
13771377

13781378
builddir(source_path::String) = joinpath(source_path, "deps")
13791379
buildfile(source_path::String) = joinpath(builddir(source_path), "build.jl")
1380-
function build_versions(ctx::Context, uuids::Set{UUID}; verbose=false)
1380+
function build_versions(ctx::Context, uuids::Set{UUID}; verbose=false, allow_reresolve::Bool=true)
13811381
# collect builds for UUIDs with `deps/build.jl` files
13821382
builds = Tuple{UUID,String,String,VersionNumber}[]
13831383
for uuid in uuids
@@ -1459,7 +1459,7 @@ function build_versions(ctx::Context, uuids::Set{UUID}; verbose=false)
14591459
fancyprint && show_progress(ctx.io, bar)
14601460

14611461
let log_file=log_file
1462-
sandbox(ctx, pkg, builddir(source_path), build_project_override; preferences=build_project_preferences) do
1462+
sandbox(ctx, pkg, builddir(source_path), build_project_override; preferences=build_project_preferences, allow_reresolve) do
14631463
flush(ctx.io)
14641464
ok = open(log_file, "w") do log
14651465
std = verbose ? ctx.io : log

src/Pkg.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,22 @@ const gc = API.gc
366366
Pkg.build(pkg::Union{String, Vector{String}}; verbose = false, io::IO=stderr)
367367
Pkg.build(pkgs::Union{PackageSpec, Vector{PackageSpec}}; verbose = false, io::IO=stderr)
368368
369+
**Keyword arguments:**
370+
- `verbose::Bool=false`: print the build output to `stdout`/`stderr` instead of redirecting to the `build.log` file.
371+
- `allow_reresolve::Bool=true`: allow Pkg to reresolve the package versions in the build environment
372+
373+
!!! compat "Julia 1.13"
374+
`allow_reresolve` requires at least Julia 1.13.
375+
369376
Run the build script in `deps/build.jl` for `pkg` and all of its dependencies in
370377
depth-first recursive order.
371378
If no argument is given to `build`, the current project is built, which thus needs
372379
to be a package.
373380
This function is called automatically on any package that gets installed
374381
for the first time.
375-
`verbose = true` prints the build output to `stdout`/`stderr` instead of
376-
redirecting to the `build.log` file.
382+
383+
The build takes place in a new process matching the current process with default of `startup-file=no`.
384+
If using the startup file (`~/.julia/config/startup.jl`) is desired, start julia with an explicit `--startup-file=yes`.
377385
"""
378386
const build = API.build
379387

test/api.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,33 @@ end
313313
end end
314314
end
315315

316+
@testset "allow_reresolve parameter" begin
317+
isolate(loaded_depot=false) do; mktempdir() do tempdir
318+
Pkg.Registry.add(url = "https://github.com/JuliaRegistries/Test")
319+
# AllowReresolveTest has Example v0.5.1 which is yanked in the test registry.
320+
test_dir = joinpath(tempdir, "AllowReresolveTest")
321+
322+
# Test that we can build and test with allow_reresolve=true
323+
copy_test_package(tempdir, "AllowReresolveTest")
324+
Pkg.activate(joinpath(tempdir, "AllowReresolveTest"))
325+
@test Pkg.build(; allow_reresolve=true) == nothing
326+
327+
rm(test_dir, force=true, recursive=true)
328+
copy_test_package(tempdir, "AllowReresolveTest")
329+
Pkg.activate(joinpath(tempdir, "AllowReresolveTest"))
330+
@test Pkg.test(; allow_reresolve=true) == nothing
331+
332+
# Test that allow_reresolve=false fails with the broken manifest
333+
rm(test_dir, force=true, recursive=true)
334+
copy_test_package(tempdir, "AllowReresolveTest")
335+
Pkg.activate(joinpath(tempdir, "AllowReresolveTest"))
336+
@test_throws Pkg.Resolve.ResolverError Pkg.build(; allow_reresolve=false)
337+
338+
rm(test_dir, force=true, recursive=true)
339+
copy_test_package(tempdir, "AllowReresolveTest")
340+
Pkg.activate(joinpath(tempdir, "AllowReresolveTest"))
341+
@test_throws Pkg.Resolve.ResolverError Pkg.test(; allow_reresolve=false)
342+
end end
343+
end
344+
316345
end # module APITests

test/test_packages/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Manifest.toml
2+
!AllowReresolveTest/Manifest.toml
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
julia_version = "1.13.0-DEV"
4+
manifest_format = "2.0"
5+
project_hash = "a100b4eee2a8dd47230a6724ae4de850bddbb7a5"
6+
7+
[[deps.AllowReresolveTest]]
8+
deps = ["Example"]
9+
path = "."
10+
uuid = "12345678-1234-1234-1234-123456789abc"
11+
version = "0.1.0"
12+
13+
[[deps.Base64]]
14+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
15+
version = "1.11.0"
16+
17+
[[deps.Example]]
18+
deps = ["Test"]
19+
git-tree-sha1 = "8eb7b4d4ca487caade9ba3e85932e28ce6d6e1f8"
20+
uuid = "7876af07-990d-54b4-ab0e-23690620f79a"
21+
version = "0.5.1"
22+
23+
[[deps.InteractiveUtils]]
24+
deps = ["Markdown"]
25+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
26+
version = "1.11.0"
27+
28+
[[deps.JuliaSyntaxHighlighting]]
29+
deps = ["StyledStrings"]
30+
uuid = "ac6e5ff7-fb65-4e79-a425-ec3bc9c03011"
31+
version = "1.12.0"
32+
33+
[[deps.Logging]]
34+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
35+
version = "1.11.0"
36+
37+
[[deps.Markdown]]
38+
deps = ["Base64", "JuliaSyntaxHighlighting", "StyledStrings"]
39+
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
40+
version = "1.11.0"
41+
42+
[[deps.Random]]
43+
deps = ["SHA"]
44+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
45+
version = "1.11.0"
46+
47+
[[deps.SHA]]
48+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
49+
version = "0.7.0"
50+
51+
[[deps.Serialization]]
52+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
53+
version = "1.11.0"
54+
55+
[[deps.StyledStrings]]
56+
uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
57+
version = "1.11.0"
58+
59+
[[deps.Test]]
60+
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
61+
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
62+
version = "1.11.0"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name = "AllowReresolveTest"
2+
uuid = "12345678-1234-1234-1234-123456789abc"
3+
version = "0.1.0"
4+
5+
[deps]
6+
Example = "7876af07-990d-54b4-ab0e-23690620f79a"
7+
8+
[compat]
9+
Example = "0.5"
10+
11+
[extras]
12+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
13+
14+
[targets]
15+
test = ["Test"]
16+
build = ["Test"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Build script for AllowReresolveTest
2+
using Test
3+
println("Build completed successfully!")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module AllowReresolveTest
2+
3+
import Example
4+
5+
greet() = "Hello from AllowReresolveTest using Example!"
6+
7+
end

0 commit comments

Comments
 (0)