Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Manifest.toml format: Pt 2. Default to new format, warn if old format is being maintained #2580

Merged
merged 7 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/manifest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions test/manifests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ 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)
output = String(take!(io))
@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

Expand Down