Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.10] 1.10 Backports #4065

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 37 additions & 23 deletions src/Operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ end
####################

function load_tree_hash!(registries::Vector{Registry.RegistryInstance}, pkg::PackageSpec, julia_version)
if is_stdlib(pkg.uuid, julia_version) && pkg.tree_hash !== nothing
# manifests from newer julia versions might have stdlibs that are upgradable (FORMER_STDLIBS)
# that have tree_hash recorded, which we need to clear for this version where they are not upgradable
# given regular stdlibs don't have tree_hash recorded
pkg.tree_hash = nothing
return pkg
end
tracking_registered_version(pkg, julia_version) || return pkg
hash = nothing
for reg in registries
Expand Down Expand Up @@ -233,19 +240,16 @@ function reset_all_compat!(proj::Project)
return nothing
end

function collect_project(pkg::PackageSpec, path::String)
function collect_project(pkg::Union{PackageSpec, Nothing}, path::String)
deps = PackageSpec[]
weakdeps = Set{UUID}()
project_file = projectfile_path(path; strict=true)
if project_file === nothing
pkgerror("could not find project file for package $(err_rep(pkg)) at `$path`")
end
project = read_package(project_file)
project = project_file === nothing ? Project() : read_project(project_file)
#=
# TODO, this should either error or be quiet
julia_compat = get_compat(project, "julia")
if julia_compat !== nothing && !(VERSION in julia_compat)
println(io, "julia version requirement for package $(err_rep(pkg)) not satisfied")
println(io, "julia version requirement for package at `$path`"")
end
=#
for (name, uuid) in project.deps
Expand All @@ -257,11 +261,13 @@ function collect_project(pkg::PackageSpec, path::String)
push!(deps, PackageSpec(name, uuid, vspec))
push!(weakdeps, uuid)
end
if project.version !== nothing
pkg.version = project.version
else
# @warn("project file for $(pkg.name) is missing a `version` entry")
pkg.version = VersionNumber(0)
if pkg !== nothing
if project.version !== nothing
pkg.version = project.version
else
# @warn("project file for $(pkg.name) is missing a `version` entry")
pkg.version = VersionNumber(0)
end
end
return deps, weakdeps
end
Expand Down Expand Up @@ -299,13 +305,13 @@ end
function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UUID, String})
deps_map = Dict{UUID,Vector{PackageSpec}}()
weak_map = Dict{UUID,Set{UUID}}()
if env.pkg !== nothing
pkg = env.pkg
deps, weakdeps = collect_project(pkg, dirname(env.project_file))
deps_map[pkg.uuid] = deps
weak_map[pkg.uuid] = weakdeps
names[pkg.uuid] = pkg.name
end

uuid = Types.project_uuid(env)
deps, weakdeps = collect_project(env.pkg, dirname(env.project_file))
deps_map[uuid] = deps
weak_map[uuid] = weakdeps
names[uuid] = env.pkg === nothing ? "project" : env.pkg.name

for pkg in pkgs
path = project_rel_path(env, source_path(env.manifest_file, pkg))
if !isdir(path)
Expand All @@ -330,7 +336,8 @@ function collect_fixed!(env::EnvCache, pkgs::Vector{PackageSpec}, names::Dict{UU
idx = findfirst(pkg -> pkg.uuid == uuid, pkgs)
fix_pkg = pkgs[idx]
end
fixed[uuid] = Resolve.Fixed(fix_pkg.version, q, weak_map[uuid])
fixpkgversion = fix_pkg === nothing ? v"0.0.0" : fix_pkg.version
fixed[uuid] = Resolve.Fixed(fixpkgversion, q, weak_map[uuid])
end
return fixed
end
Expand Down Expand Up @@ -1378,6 +1385,7 @@ function add(ctx::Context, pkgs::Vector{PackageSpec}, new_git=Set{UUID}();
assert_can_add(ctx, pkgs)
# load manifest data
for (i, pkg) in pairs(pkgs)
delete!(ctx.env.project.weakdeps, pkg.name)
entry = manifest_info(ctx.env.manifest, pkg.uuid)
is_dep = any(uuid -> uuid == pkg.uuid, [uuid for (name, uuid) in ctx.env.project.deps])
pkgs[i] = update_package_add(ctx, pkg, entry, is_dep)
Expand All @@ -1404,6 +1412,7 @@ function develop(ctx::Context, pkgs::Vector{PackageSpec}, new_git::Set{UUID};
assert_can_add(ctx, pkgs)
# no need to look at manifest.. dev will just nuke whatever is there before
for pkg in pkgs
delete!(ctx.env.project.weakdeps, pkg.name)
ctx.env.project.deps[pkg.name] = pkg.uuid
end
# resolve & apply package versions
Expand Down Expand Up @@ -2200,6 +2209,7 @@ function status_ext_info(pkg::PackageSpec, env::EnvCache)
manifest = env.manifest
manifest_info = get(manifest, pkg.uuid, nothing)
manifest_info === nothing && return nothing
depses = manifest_info.deps
weakdepses = manifest_info.weakdeps
exts = manifest_info.exts
if !isempty(weakdepses) && !isempty(exts)
Expand All @@ -2210,10 +2220,14 @@ function status_ext_info(pkg::PackageSpec, env::EnvCache)
# Check if deps are loaded
extdeps_info= Tuple{String, Bool}[]
for extdep in extdeps
haskey(weakdepses, extdep) ||
pkgerror(isnothing(pkg.name) ? "M" : "$(pkg.name) has a m",
"alformed Project.toml, the extension package $extdep is not listed in [weakdeps]")
uuid = weakdepses[extdep]
if !(haskey(weakdepses, extdep) || haskey(depses, extdep))
pkgerror(isnothing(pkg.name) ? "M" : "$(pkg.name) has a malformed Project.toml, ",
"the extension package $extdep is not listed in [weakdeps] or [deps]")
end
uuid = get(weakdepses, extdep, nothing)
if uuid === nothing
uuid = depses[extdep]
end
loaded = haskey(Base.loaded_modules, Base.PkgId(uuid, extdep))
push!(extdeps_info, (extdep, loaded))
end
Expand Down
2 changes: 1 addition & 1 deletion src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ Base.@kwdef mutable struct Context
julia_version::Union{VersionNumber,Nothing} = VERSION
end

project_uuid(env::EnvCache) = env.pkg === nothing ? nothing : env.pkg.uuid
project_uuid(env::EnvCache) = env.pkg === nothing ? Base.dummy_uuid(env.project_file) : env.pkg.uuid
collides_with_project(env::EnvCache, pkg::PackageSpec) =
is_project_name(env, pkg.name) || is_project_uuid(env, pkg.uuid)
is_project(env::EnvCache, pkg::PackageSpec) = is_project_uuid(env, pkg.uuid)
Expand Down
21 changes: 21 additions & 0 deletions test/extensions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using .Utils
using Test
using UUIDs

@testset "weak deps" begin
he_root = joinpath(@__DIR__, "test_packages", "ExtensionExamples", "HasExtensions.jl")
Expand Down Expand Up @@ -78,4 +79,24 @@ using Test
@test occursin("HasExtensions", out)
@test occursin("HasDepWithExtensions", out)
end

isolate(loaded_depot=false) do
mktempdir() do dir
Pkg.Registry.add("General")
path = joinpath(@__DIR__, "test_packages", "TestWeakDepProject")
cp(path, joinpath(dir, "TestWeakDepProject"))
Pkg.activate(joinpath(dir, "TestWeakDepProject"))
Pkg.resolve()
@test Pkg.dependencies()[UUID("2ab3a3ac-af41-5b50-aa03-7779005ae688")].version == v"0.3.26"

# Check that explicitly adding a package that is a weak dep removes it from the set of weak deps
ctx = Pkg.Types.Context()
@test "LogExpFunctions" in keys(ctx.env.project.weakdeps)
@test !("LogExpFunctions" in keys(ctx.env.project.deps))
Pkg.add("LogExpFunctions")
ctx = Pkg.Types.Context()
@test "LogExpFunctions" in keys(ctx.env.project.deps)
@test !("LogExpFunctions" in keys(ctx.env.project.weakdeps))
end
end
end
9 changes: 9 additions & 0 deletions test/test_packages/TestWeakDepProject/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[deps]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

[weakdeps]
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"

[compat]
ForwardDiff = "=0.10.36"
LogExpFunctions = "=0.3.26"
Loading