Skip to content

Commit fd905fa

Browse files
Add support for new Manifest.toml format during code load (JuliaLang#40765)
* support new manifest format during code load
1 parent 0e094a8 commit fd905fa

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
@@ -557,12 +557,34 @@ function explicit_project_deps_get(project_file::String, name::String)::Union{No
557557
return nothing
558558
end
559559

560+
function is_v1_format_manifest(raw_manifest::Dict)
561+
if haskey(raw_manifest, "manifest_format")
562+
if raw_manifest["manifest_format"] isa Dict && haskey(raw_manifest["manifest_format"], "uuid")
563+
# the off-chance where an old format manifest has a dep called "manifest_format"
564+
return true
565+
end
566+
return false
567+
else
568+
return true
569+
end
570+
end
571+
572+
# returns a deps list for both old and new manifest formats
573+
function get_deps(raw_manifest::Dict)
574+
if is_v1_format_manifest(raw_manifest)
575+
return raw_manifest
576+
else
577+
# if the manifest has no deps, there won't be a `deps` field
578+
return get(Dict{String, Any}, raw_manifest, "deps")
579+
end
580+
end
581+
560582
# find `where` stanza and return the PkgId for `name`
561583
# return `nothing` if it did not find `where` (indicating caller should continue searching)
562584
function explicit_manifest_deps_get(project_file::String, where::UUID, name::String)::Union{Nothing,PkgId}
563585
manifest_file = project_file_manifest_path(project_file)
564586
manifest_file === nothing && return nothing # manifest not found--keep searching LOAD_PATH
565-
d = parsed_toml(manifest_file)
587+
d = get_deps(parsed_toml(manifest_file))
566588
found_where = false
567589
found_name = false
568590
for (dep_name, entries) in d
@@ -610,7 +632,7 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No
610632
manifest_file = project_file_manifest_path(project_file)
611633
manifest_file === nothing && return nothing # no manifest, skip env
612634

613-
d = parsed_toml(manifest_file)
635+
d = get_deps(parsed_toml(manifest_file))
614636
entries = get(d, pkg.name, nothing)::Union{Nothing, Vector{Any}}
615637
entries === nothing && return nothing # TODO: allow name to mismatch?
616638
for entry in entries

test/loading.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,3 +730,29 @@ end
730730
@test length(Base.manifest_names) == n
731731
@test length(Base.preferences_names) == n
732732
end
733+
734+
@testset "Manifest formats" begin
735+
deps = Dict{String,Any}(
736+
"Serialization" => Any[Dict{String, Any}("uuid"=>"9e88b42a-f829-5b0c-bbe9-9e923198166b")],
737+
"Random" => Any[Dict{String, Any}("deps"=>["Serialization"], "uuid"=>"9a3f8284-a2c9-5f02-9a11-845980a1fd5c")],
738+
"Logging" => Any[Dict{String, Any}("uuid"=>"56ddb016-857b-54e1-b83d-db4d58db5568")]
739+
)
740+
741+
@testset "v1.0" begin
742+
env_dir = joinpath(@__DIR__, "manifest", "v1.0")
743+
manifest_file = joinpath(env_dir, "Manifest.toml")
744+
isfile(manifest_file) || error("Reference manifest is missing")
745+
raw_manifest = Base.parsed_toml(manifest_file)
746+
@test Base.is_v1_format_manifest(raw_manifest)
747+
@test Base.get_deps(raw_manifest) == deps
748+
end
749+
750+
@testset "v2.0" begin
751+
env_dir = joinpath(@__DIR__, "manifest", "v2.0")
752+
manifest_file = joinpath(env_dir, "Manifest.toml")
753+
isfile(manifest_file) || error("Reference manifest is missing")
754+
raw_manifest = Base.parsed_toml(manifest_file)
755+
@test Base.is_v1_format_manifest(raw_manifest) == false
756+
@test Base.get_deps(raw_manifest) == deps
757+
end
758+
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)