Skip to content

Commit fc8fc53

Browse files
IanButterworthKristofferC
authored andcommitted
Add support for new Manifest.toml format during code load (#40765)
* support new manifest format during code load (cherry picked from commit fd905fa)
1 parent d4bca99 commit fc8fc53

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

base/loading.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,34 @@ function explicit_project_deps_get(project_file::String, name::String)::Union{No
486486
return nothing
487487
end
488488

489+
function is_v1_format_manifest(raw_manifest::Dict)
490+
if haskey(raw_manifest, "manifest_format")
491+
if raw_manifest["manifest_format"] isa Dict && haskey(raw_manifest["manifest_format"], "uuid")
492+
# the off-chance where an old format manifest has a dep called "manifest_format"
493+
return true
494+
end
495+
return false
496+
else
497+
return true
498+
end
499+
end
500+
501+
# returns a deps list for both old and new manifest formats
502+
function get_deps(raw_manifest::Dict)
503+
if is_v1_format_manifest(raw_manifest)
504+
return raw_manifest
505+
else
506+
# if the manifest has no deps, there won't be a `deps` field
507+
return get(Dict{String, Any}, raw_manifest, "deps")
508+
end
509+
end
510+
489511
# find `where` stanza and return the PkgId for `name`
490512
# return `nothing` if it did not find `where` (indicating caller should continue searching)
491513
function explicit_manifest_deps_get(project_file::String, where::UUID, name::String)::Union{Nothing,PkgId}
492514
manifest_file = project_file_manifest_path(project_file)
493515
manifest_file === nothing && return nothing # manifest not found--keep searching LOAD_PATH
494-
d = parsed_toml(manifest_file)
516+
d = get_deps(parsed_toml(manifest_file))
495517
found_where = false
496518
found_name = false
497519
for (dep_name, entries) in d
@@ -539,7 +561,7 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No
539561
manifest_file = project_file_manifest_path(project_file)
540562
manifest_file === nothing && return nothing # no manifest, skip env
541563

542-
d = parsed_toml(manifest_file)
564+
d = get_deps(parsed_toml(manifest_file))
543565
entries = get(d, pkg.name, nothing)::Union{Nothing, Vector{Any}}
544566
entries === nothing && return nothing # TODO: allow name to mismatch?
545567
for entry in entries

test/loading.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,3 +719,29 @@ import .Foo.Libdl; import Libdl
719719
end
720720
end
721721
end
722+
723+
@testset "Manifest formats" begin
724+
deps = Dict{String,Any}(
725+
"Serialization" => Any[Dict{String, Any}("uuid"=>"9e88b42a-f829-5b0c-bbe9-9e923198166b")],
726+
"Random" => Any[Dict{String, Any}("deps"=>["Serialization"], "uuid"=>"9a3f8284-a2c9-5f02-9a11-845980a1fd5c")],
727+
"Logging" => Any[Dict{String, Any}("uuid"=>"56ddb016-857b-54e1-b83d-db4d58db5568")]
728+
)
729+
730+
@testset "v1.0" begin
731+
env_dir = joinpath(@__DIR__, "manifest", "v1.0")
732+
manifest_file = joinpath(env_dir, "Manifest.toml")
733+
isfile(manifest_file) || error("Reference manifest is missing")
734+
raw_manifest = Base.parsed_toml(manifest_file)
735+
@test Base.is_v1_format_manifest(raw_manifest)
736+
@test Base.get_deps(raw_manifest) == deps
737+
end
738+
739+
@testset "v2.0" begin
740+
env_dir = joinpath(@__DIR__, "manifest", "v2.0")
741+
manifest_file = joinpath(env_dir, "Manifest.toml")
742+
isfile(manifest_file) || error("Reference manifest is missing")
743+
raw_manifest = Base.parsed_toml(manifest_file)
744+
@test Base.is_v1_format_manifest(raw_manifest) == false
745+
@test Base.get_deps(raw_manifest) == deps
746+
end
747+
end

test/manifest/v1.0/Manifest.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
[[Logging]]
4+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
5+
6+
[[Random]]
7+
deps = ["Serialization"]
8+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
9+
10+
[[Serialization]]
11+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

test/manifest/v2.0/Manifest.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
julia_version = "1.7.0-DEV.1199"
4+
manifest_format = "2.0"
5+
6+
[[deps.Logging]]
7+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
8+
9+
[[deps.Random]]
10+
deps = ["Serialization"]
11+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
12+
13+
[[deps.Serialization]]
14+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

0 commit comments

Comments
 (0)