diff --git a/src/Operations.jl b/src/Operations.jl index 4e9eaed55f..f7f4b5500c 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -1378,6 +1378,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) @@ -1404,6 +1405,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 @@ -2200,6 +2202,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) @@ -2210,10 +2213,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 diff --git a/test/extensions.jl b/test/extensions.jl index 1a76757d7d..dbb9e5200e 100644 --- a/test/extensions.jl +++ b/test/extensions.jl @@ -78,4 +78,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