Skip to content

Commit f571edd

Browse files
authored
Backports for 1.12 (#4416)
1 parent 69926e3 commit f571edd

File tree

6 files changed

+65
-17
lines changed

6 files changed

+65
-17
lines changed

src/API.jl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}; shared::Bool=true,
244244

245245
new_git = handle_repos_develop!(ctx, pkgs, shared)
246246

247+
Operations.update_registries(ctx; force = false, update_cooldown = Day(1))
247248

248249
for pkg in pkgs
249250
if Types.collides_with_project(ctx.env, pkg)
@@ -1053,18 +1054,33 @@ function gc(ctx::Context=Context(); collect_delay::Period=Day(7), verbose=false,
10531054
end
10541055
end
10551056

1056-
# Delete any files that could not be rm-ed and were specially moved to the delayed delete directory.
1057-
# Do this silently because it's out of scope for Pkg.gc() but it's helpful to use this opportunity to do it
1058-
if isdefined(Base.Filesystem, :delayed_delete_dir)
1059-
if isdir(Base.Filesystem.delayed_delete_dir())
1060-
for p in readdir(Base.Filesystem.delayed_delete_dir(), join=true)
1057+
# Delete anything that could not be rm-ed and was specially recorded in the delayed delete reference folder.
1058+
# Do this silently because it's out of scope for Pkg.gc() but it's helpful to use this opportunity to do it.
1059+
if isdefined(Base.Filesystem, :delayed_delete_ref)
1060+
delayed_delete_ref_path = Base.Filesystem.delayed_delete_ref()
1061+
if isdir(delayed_delete_ref_path)
1062+
delayed_delete_dirs = Set{String}()
1063+
for f in readdir(delayed_delete_ref_path; join = true)
10611064
try
1065+
p = readline(f)
1066+
push!(delayed_delete_dirs, dirname(p))
10621067
Base.Filesystem.prepare_for_deletion(p)
1063-
Base.rm(p; recursive=true, force=true, allow_delayed_delete=false)
1068+
Base.rm(p; recursive = true, force = true, allow_delayed_delete = false)
1069+
Base.rm(f)
10641070
catch e
10651071
@debug "Failed to delete $p" exception=e
10661072
end
10671073
end
1074+
for dir in delayed_delete_dirs
1075+
if basename(dir) == "julia_delayed_deletes" && isempty(readdir(dir))
1076+
Base.Filesystem.prepare_for_deletion(dir)
1077+
Base.rm(dir; recursive = true)
1078+
end
1079+
end
1080+
if isempty(readdir(delayed_delete_ref_path))
1081+
Base.Filesystem.prepare_for_deletion(delayed_delete_ref_path)
1082+
Base.rm(delayed_delete_ref_path; recursive = true)
1083+
end
10681084
end
10691085
end
10701086

src/Operations.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ function reset_all_compat!(proj::Project)
319319
return nothing
320320
end
321321

322-
function collect_project(pkg::Union{PackageSpec, Nothing}, path::String)
322+
function collect_project(pkg::Union{PackageSpec, Nothing}, path::String, julia_version)
323323
deps = PackageSpec[]
324324
weakdeps = Set{UUID}()
325325
project_file = projectfile_path(path; strict=true)
326326
project = project_file === nothing ? Project() : read_project(project_file)
327327
julia_compat = get_compat(project, "julia")
328-
if !isnothing(julia_compat) && !(VERSION in julia_compat)
329-
pkgerror("julia version requirement from Project.toml's compat section not satisfied for package at `$path`")
328+
if !isnothing(julia_compat) && !isnothing(julia_version) && !(julia_version in julia_compat)
329+
pkgerror("julia version requirement for package at `$path` not satisfied: compat entry \"julia = $(get_compat_str(project, "julia"))\" does not include Julia version $julia_version")
330330
end
331331
for (name, uuid) in project.deps
332332
path, repo = get_path_repo(project, name)
@@ -385,20 +385,20 @@ function collect_developed(env::EnvCache, pkgs::Vector{PackageSpec})
385385
return developed
386386
end
387387

388-
function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UUID, String})
388+
function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UUID, String}, julia_version)
389389
deps_map = Dict{UUID,Vector{PackageSpec}}()
390390
weak_map = Dict{UUID,Set{UUID}}()
391391

392392
uuid = Types.project_uuid(env)
393-
deps, weakdeps = collect_project(env.pkg, dirname(env.project_file))
393+
deps, weakdeps = collect_project(env.pkg, dirname(env.project_file), julia_version)
394394
deps_map[uuid] = deps
395395
weak_map[uuid] = weakdeps
396396
names[uuid] = env.pkg === nothing ? "project" : env.pkg.name
397397

398398
for (path, project) in env.workspace
399399
uuid = Types.project_uuid(project, path)
400400
pkg = project.name === nothing ? nothing : PackageSpec(name=project.name, uuid=uuid)
401-
deps, weakdeps = collect_project(pkg, path)
401+
deps, weakdeps = collect_project(pkg, path, julia_version)
402402
deps_map[Types.project_uuid(env)] = deps
403403
weak_map[Types.project_uuid(env)] = weakdeps
404404
names[uuid] = project.name === nothing ? "project" : project.name
@@ -418,7 +418,7 @@ function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UU
418418
if !isdir(path)
419419
pkgerror("expected package $(err_rep(pkg)) to exist at path `$path`")
420420
end
421-
deps, weakdeps = collect_project(pkg, path)
421+
deps, weakdeps = collect_project(pkg, path, julia_version)
422422
deps_map[pkg.uuid] = deps
423423
weak_map[pkg.uuid] = weakdeps
424424
end
@@ -469,7 +469,7 @@ function resolve_versions!(env::EnvCache, registries::Vector{Registry.RegistryIn
469469
# compatibility
470470
if julia_version !== nothing
471471
# only set the manifest julia_version if ctx.julia_version is not nothing
472-
env.manifest.julia_version = dropbuild(VERSION)
472+
env.manifest.julia_version = dropbuild(julia_version)
473473
v = intersect(julia_version, get_compat_workspace(env, "julia"))
474474
if isempty(v)
475475
@warn "julia version requirement for project not satisfied" _module=nothing _file=nothing
@@ -493,7 +493,7 @@ function resolve_versions!(env::EnvCache, registries::Vector{Registry.RegistryIn
493493
end
494494
end
495495
# this also sets pkg.version for fixed packages
496-
fixed = collect_fixed!(env, filter(!is_tracking_registry, pkgs), names)
496+
fixed = collect_fixed!(env, filter(!is_tracking_registry, pkgs), names, julia_version)
497497
# non fixed packages are `add`ed by version: their version is either restricted or free
498498
# fixed packages are `dev`ed or `add`ed by repo
499499
# at this point, fixed packages have a version and `deps`

src/Pkg.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,5 +898,6 @@ DEFAULT_IO[] = nothing
898898
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = false
899899
PREV_ENV_PATH[] = ""
900900
Types.STDLIB[] = nothing
901+
empty!(Registry.REGISTRY_CACHE)
901902

902903
end # module

src/Types.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,16 @@ function Context!(ctx::Context; kwargs...)
585585
for (k, v) in kwargs
586586
setfield!(ctx, k, v)
587587
end
588+
589+
# Highlight for logging purposes if julia_version is set to a different version than current VERSION
590+
if haskey(kwargs, :julia_version) && ctx.julia_version !== nothing && ctx.julia_version != VERSION
591+
Pkg.printpkgstyle(
592+
ctx.io, :Context,
593+
"Pkg is operating with julia_version set to `$(ctx.julia_version)`",
594+
color = Base.warn_color()
595+
)
596+
end
597+
588598
return ctx
589599
end
590600

test/api.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ end
308308
isolate(loaded_depot=true) do; mktempdir() do tempdir
309309
pathf = git_init_package(tempdir, joinpath(@__DIR__, "test_packages", "FarFuture"))
310310
pathp = git_init_package(tempdir, joinpath(@__DIR__, "test_packages", "FarPast"))
311-
@test_throws "julia version requirement from Project.toml's compat section not satisfied for package" Pkg.add(path=pathf)
312-
@test_throws "julia version requirement from Project.toml's compat section not satisfied for package" Pkg.add(path=pathp)
311+
@test_throws "julia version requirement for package" Pkg.add(path=pathf)
312+
@test_throws "julia version requirement for package" Pkg.add(path=pathp)
313313
end end
314314
end
315315

test/pkg.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,27 @@ end
684684
end
685685
end
686686

687+
if isdefined(Base.Filesystem, :delayed_delete_ref)
688+
@testset "Pkg.gc for delayed deletes" begin
689+
mktempdir() do root
690+
dir = joinpath(root, "julia_delayed_deletes")
691+
mkdir(dir)
692+
testfile = joinpath(dir, "testfile")
693+
write(testfile, "foo bar")
694+
delayed_delete_ref_path = Base.Filesystem.delayed_delete_ref()
695+
mkpath(delayed_delete_ref_path)
696+
ref = tempname(delayed_delete_ref_path; cleanup = false)
697+
write(ref, testfile)
698+
@test isfile(testfile)
699+
Pkg.gc()
700+
@test !ispath(testfile)
701+
@test !ispath(dir)
702+
@test !ispath(ref)
703+
@test !ispath(delayed_delete_ref_path) || !isempty(readdir(delayed_delete_ref_path))
704+
end
705+
end
706+
end
707+
687708
#issue #876
688709
@testset "targets should survive add/rm" begin
689710
temp_pkg_dir() do project_path; cd_tempdir() do tmpdir

0 commit comments

Comments
 (0)