diff --git a/src/API.jl b/src/API.jl index 9ddac45f37..36eb4ac9d0 100644 --- a/src/API.jl +++ b/src/API.jl @@ -1670,4 +1670,18 @@ function handle_package_input!(pkg::PackageSpec) pkg.uuid = pkg.uuid isa String ? UUID(pkg.uuid) : pkg.uuid end +function upgrade_manifest(ctx::Context = Context()) + before_format = ctx.env.manifest.manifest_format + if before_format == v"2.0" + pkgerror("Format of manifest file at `$(ctx.env.manifest_file)` already up to date: manifest_format == $(before_format)") + elseif before_format != v"1.0" + pkgerror("Format of manifest file at `$(ctx.env.manifest_file)` version is unrecogized: manifest_format == $(before_format)") + end + ctx.env.manifest.manifest_format = v"2.0" + ctx.env.manifest.julia_version = VERSION + Types.write_manifest(ctx.env) + printpkgstyle(ctx.io, :Updated, "Format of manifest file at `$(ctx.env.manifest_file)` updated from v$(before_format.major).$(before_format.minor) to v2.0") + return nothing +end + end # module diff --git a/src/Pkg.jl b/src/Pkg.jl index 34ff54c01d..d446ae799b 100644 --- a/src/Pkg.jl +++ b/src/Pkg.jl @@ -559,6 +559,12 @@ Below is a comparison between the REPL mode and the functional API:: """ const RegistrySpec = Registry.RegistrySpec +""" + upgrade_manifest() + +Upgrades the format of the manifest file from v1.0 to v2.0 without re-resolving. +""" +const upgrade_manifest = API.upgrade_manifest function __init__() if isdefined(Base, :active_repl) diff --git a/src/Types.jl b/src/Types.jl index 2240074811..d6f4e4b684 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -262,7 +262,7 @@ Base.hash(x::PackageEntry, h::UInt) = foldr(hash, [x.name, x.version, x.path, x. Base.@kwdef mutable struct Manifest julia_version::Union{Nothing,VersionNumber} = Base.VERSION - manifest_format::VersionNumber = v"1.0.0" # default to older flat format + manifest_format::VersionNumber = v"2.0.0" deps::Dict{UUID,PackageEntry} = Dict{UUID,PackageEntry}() other::Dict{String,Any} = Dict{String,Any}() end diff --git a/src/manifest.jl b/src/manifest.jl index 5f85fa5520..9dbee98a68 100644 --- a/src/manifest.jl +++ b/src/manifest.jl @@ -281,6 +281,10 @@ function write_manifest(env::EnvCache) write_manifest(env.manifest, env.manifest_file) end function write_manifest(manifest::Manifest, manifest_file::AbstractString) + if manifest.manifest_format.major == 1 + @warn """The active manifest file at `$(manifest_file)` has an old format that is being maintained. + To update to the new format run `Pkg.upgrade_manifest()` which will upgrade the format without re-resolving""" maxlog = 1 + end return write_manifest(destructure(manifest), manifest_file) end function write_manifest(io::IO, manifest::Manifest) diff --git a/test/manifests.jl b/test/manifests.jl index 6f20f6b0ea..30a792bb99 100644 --- a/test/manifests.jl +++ b/test/manifests.jl @@ -5,7 +5,7 @@ import ..Pkg, LibGit2 using ..Utils @testset "Manifest.toml formats" begin - @testset "Default manifest format is v1" begin + @testset "Default manifest format is v2" begin isolate(loaded_depot=true) do io = IOBuffer() Pkg.activate(; io=io, temp=true) @@ -13,7 +13,8 @@ using ..Utils @test occursin(r"Activating.*project at.*", output) Pkg.add("Profile") env_manifest = Pkg.Types.Context().env.manifest_file - @test Base.is_v1_format_manifest(Base.parsed_toml(env_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" end end