Skip to content

Commit

Permalink
Add support for new Manifest.toml format during code load (JuliaLang#…
Browse files Browse the repository at this point in the history
…40765)

* support new manifest format during code load
  • Loading branch information
IanButterworth authored and Amit Shirodkar committed Jun 9, 2021
1 parent f9d4544 commit 3a401f9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
26 changes: 24 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions test/manifest/v1.0/Manifest.toml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions test/manifest/v2.0/Manifest.toml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 3a401f9

Please sign in to comment.