Skip to content

Commit

Permalink
Automatically upgrade empty manifest files to v2 format (#4091)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7b759d7)
  • Loading branch information
IanButterworth committed Nov 24, 2024
1 parent afe50da commit fb72cf6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/manifest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ function read_manifest(f_or_io::Union{String, IO})
rethrow()
end
if Base.is_v1_format_manifest(raw)
raw = convert_v1_format_manifest(raw)
if isempty(raw) # treat an empty Manifest file as v2 format for convenience
raw["manifest_format"] = "2.0.0"
else
raw = convert_v1_format_manifest(raw)
end
end
return Manifest(raw, f_or_io)
end
Expand Down
29 changes: 29 additions & 0 deletions test/manifests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ end
end
end

@testset "Empty manifest file is automatically upgraded to v2" begin
isolate(loaded_depot=true) do
io = IOBuffer()
d = mktempdir()
manifest = joinpath(d, "Manifest.toml")
touch(manifest)
Pkg.activate(d; io=io)
output = String(take!(io))
@test occursin(r"Activating.*project at.*", output)
env_manifest = Pkg.Types.Context().env.manifest_file
@test samefile(env_manifest, manifest)
# an empty manifest is still technically considered to be v1 manifest
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest))
@test Pkg.Types.Context().env.manifest.manifest_format == v"2.0.0"

Pkg.add("Profile"; io=io)
env_manifest = Pkg.Types.Context().env.manifest_file
@test samefile(env_manifest, manifest)
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest)) == false
@test Pkg.Types.Context().env.manifest.manifest_format == v"2.0.0"

# check that having a Project with deps, and an empty manifest file doesn't error
rm(manifest)
touch(manifest)
Pkg.activate(d; io=io)
Pkg.add("Example"; io=io)
end
end

@testset "v1.0: activate, change, maintain manifest format" begin
reference_manifest_isolated_test("v1.0", v1 = true) do env_dir, env_manifest
io = IOBuffer()
Expand Down

0 comments on commit fb72cf6

Please sign in to comment.