From fb72cf6f163c2a45af1c17467824f60eee489c6f Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 20 Nov 2024 23:03:07 -0500 Subject: [PATCH] Automatically upgrade empty manifest files to v2 format (#4091) (cherry picked from commit 7b759d7f0af56c5ad01f2289bbad71284a556970) --- src/manifest.jl | 6 +++++- test/manifests.jl | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/manifest.jl b/src/manifest.jl index 4c8f9523d2..1366cd4cdd 100644 --- a/src/manifest.jl +++ b/src/manifest.jl @@ -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 diff --git a/test/manifests.jl b/test/manifests.jl index 0aaa81a78f..a46fc1b0ff 100644 --- a/test/manifests.jl +++ b/test/manifests.jl @@ -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()