diff --git a/src/Operations.jl b/src/Operations.jl index 7e837c74c8..d24fbe3b99 100644 --- a/src/Operations.jl +++ b/src/Operations.jl @@ -245,17 +245,14 @@ 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) julia_compat = get_compat(project, "julia") if !isnothing(julia_compat) && !(VERSION in julia_compat) - pkgerror("julia version requirement from Project.toml's compat section not satisfied for package $(err_rep(pkg)) at `$path`") + pkgerror("julia version requirement from Project.toml's compat section not satisfied for package at `$path`") end for (name, uuid) in project.deps path, repo = get_path_repo(project, name) @@ -267,11 +264,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 @@ -309,13 +308,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 # add repo package if necessary if (pkg.repo.rev !== nothing || pkg.repo.source !== nothing) && pkg.tree_hash === nothing @@ -345,7 +344,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 diff --git a/src/Types.jl b/src/Types.jl index 4f5da0f6ad..46fdd685ff 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -417,7 +417,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) diff --git a/test/extensions.jl b/test/extensions.jl index 347352863f..d46b358bb6 100644 --- a/test/extensions.jl +++ b/test/extensions.jl @@ -1,5 +1,6 @@ using .Utils using Test +using UUIDs @testset "weak deps" begin he_root = joinpath(@__DIR__, "test_packages", "ExtensionExamples", "HasExtensions.jl") @@ -93,4 +94,15 @@ using Test @test proj.extras == Dict{String, Base.UUID}("Example" => Base.UUID("7876af07-990d-54b4-ab0e-23690620f79a")) end 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" + end + end end diff --git a/test/test_packages/TestWeakDepProject/Project.toml b/test/test_packages/TestWeakDepProject/Project.toml new file mode 100644 index 0000000000..c856f60f08 --- /dev/null +++ b/test/test_packages/TestWeakDepProject/Project.toml @@ -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"