From 3a401f9e514322f5b1d9d92bc2d295c1b919a0ec Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 2 Jun 2021 14:58:08 +0200 Subject: [PATCH] Add support for new Manifest.toml format during code load (#40765) * support new manifest format during code load --- base/loading.jl | 26 ++++++++++++++++++++++++-- test/loading.jl | 26 ++++++++++++++++++++++++++ test/manifest/v1.0/Manifest.toml | 11 +++++++++++ test/manifest/v2.0/Manifest.toml | 14 ++++++++++++++ 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/manifest/v1.0/Manifest.toml create mode 100644 test/manifest/v2.0/Manifest.toml diff --git a/base/loading.jl b/base/loading.jl index a22cf2c2052bfb..95909608d861dd 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -557,12 +557,34 @@ function explicit_project_deps_get(project_file::String, name::String)::Union{No return nothing end +function is_v1_format_manifest(raw_manifest::Dict) + if haskey(raw_manifest, "manifest_format") + if raw_manifest["manifest_format"] isa Dict && haskey(raw_manifest["manifest_format"], "uuid") + # the off-chance where an old format manifest has a dep called "manifest_format" + return true + end + return false + else + return true + end +end + +# returns a deps list for both old and new manifest formats +function get_deps(raw_manifest::Dict) + if is_v1_format_manifest(raw_manifest) + return raw_manifest + else + # if the manifest has no deps, there won't be a `deps` field + return get(Dict{String, Any}, raw_manifest, "deps") + end +end + # find `where` stanza and return the PkgId for `name` # return `nothing` if it did not find `where` (indicating caller should continue searching) function explicit_manifest_deps_get(project_file::String, where::UUID, name::String)::Union{Nothing,PkgId} manifest_file = project_file_manifest_path(project_file) manifest_file === nothing && return nothing # manifest not found--keep searching LOAD_PATH - d = parsed_toml(manifest_file) + d = get_deps(parsed_toml(manifest_file)) found_where = false found_name = false for (dep_name, entries) in d @@ -610,7 +632,7 @@ function explicit_manifest_uuid_path(project_file::String, pkg::PkgId)::Union{No manifest_file = project_file_manifest_path(project_file) manifest_file === nothing && return nothing # no manifest, skip env - d = parsed_toml(manifest_file) + d = get_deps(parsed_toml(manifest_file)) entries = get(d, pkg.name, nothing)::Union{Nothing, Vector{Any}} entries === nothing && return nothing # TODO: allow name to mismatch? for entry in entries diff --git a/test/loading.jl b/test/loading.jl index d94abd889dcfc4..c56f6c463a21f5 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -730,3 +730,29 @@ end @test length(Base.manifest_names) == n @test length(Base.preferences_names) == n end + +@testset "Manifest formats" begin + deps = Dict{String,Any}( + "Serialization" => Any[Dict{String, Any}("uuid"=>"9e88b42a-f829-5b0c-bbe9-9e923198166b")], + "Random" => Any[Dict{String, Any}("deps"=>["Serialization"], "uuid"=>"9a3f8284-a2c9-5f02-9a11-845980a1fd5c")], + "Logging" => Any[Dict{String, Any}("uuid"=>"56ddb016-857b-54e1-b83d-db4d58db5568")] + ) + + @testset "v1.0" begin + env_dir = joinpath(@__DIR__, "manifest", "v1.0") + manifest_file = joinpath(env_dir, "Manifest.toml") + isfile(manifest_file) || error("Reference manifest is missing") + raw_manifest = Base.parsed_toml(manifest_file) + @test Base.is_v1_format_manifest(raw_manifest) + @test Base.get_deps(raw_manifest) == deps + end + + @testset "v2.0" begin + env_dir = joinpath(@__DIR__, "manifest", "v2.0") + manifest_file = joinpath(env_dir, "Manifest.toml") + isfile(manifest_file) || error("Reference manifest is missing") + raw_manifest = Base.parsed_toml(manifest_file) + @test Base.is_v1_format_manifest(raw_manifest) == false + @test Base.get_deps(raw_manifest) == deps + end +end diff --git a/test/manifest/v1.0/Manifest.toml b/test/manifest/v1.0/Manifest.toml new file mode 100644 index 00000000000000..758314a2f5f6a4 --- /dev/null +++ b/test/manifest/v1.0/Manifest.toml @@ -0,0 +1,11 @@ +# This file is machine-generated - editing it directly is not advised + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" diff --git a/test/manifest/v2.0/Manifest.toml b/test/manifest/v2.0/Manifest.toml new file mode 100644 index 00000000000000..f999fd6efb1c4b --- /dev/null +++ b/test/manifest/v2.0/Manifest.toml @@ -0,0 +1,14 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.7.0-DEV.1199" +manifest_format = "2.0" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"