Skip to content

Commit dd0b37b

Browse files
IanButterworthKristofferC
authored andcommitted
warn when loading a manifest from a different julia version
(cherry picked from commit 6b301fc)
1 parent 402f37f commit dd0b37b

File tree

4 files changed

+107
-48
lines changed

4 files changed

+107
-48
lines changed

src/API.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
14151415
end
14161416
if !isfile(ctx.env.project_file) && isfile(ctx.env.manifest_file)
14171417
_manifest = Pkg.Types.read_manifest(ctx.env.manifest_file)
1418+
Types.check_warn_manifest_julia_version_compat(_manifest, ctx.env.manifest_file)
14181419
deps = Dict{String,String}()
14191420
for (uuid, pkg) in _manifest
14201421
if pkg.name in keys(deps)
@@ -1433,6 +1434,7 @@ function instantiate(ctx::Context; manifest::Union{Bool, Nothing}=nothing,
14331434
if !isfile(ctx.env.manifest_file) && manifest == true
14341435
pkgerror("expected manifest file at `$(ctx.env.manifest_file)` but it does not exist")
14351436
end
1437+
Types.check_warn_manifest_julia_version_compat(ctx.env.manifest, ctx.env.manifest_file)
14361438
Operations.prune_manifest(ctx.env)
14371439
for (name, uuid) in ctx.env.project.deps
14381440
get(ctx.env.manifest, uuid, nothing) === nothing || continue

src/manifest.jl

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ function Manifest(raw::Dict, f_or_io::Union{String, IO})::Manifest
135135
manifest_format = VersionNumber(raw["manifest_format"])
136136
if !in(manifest_format.major, 1:2)
137137
if f_or_io isa IO
138-
@warn "Unknown Manifest.toml format version detected in streamed manifest. Unexpected behavior may occur" manifest_format maxlog = 1
138+
@warn "Unknown Manifest.toml format version detected in streamed manifest. Unexpected behavior may occur" manifest_format
139139
else
140-
@warn "Unknown Manifest.toml format version detected in file `$(f_or_io)`. Unexpected behavior may occur" manifest_format maxlog = 1
140+
@warn "Unknown Manifest.toml format version detected in file `$(f_or_io)`. Unexpected behavior may occur" manifest_format maxlog = 1 _id = Symbol(f_or_io)
141141
end
142142
end
143143
stage1 = Dict{String,Vector{Stage1}}()
@@ -285,7 +285,7 @@ end
285285
function write_manifest(manifest::Manifest, manifest_file::AbstractString)
286286
if manifest.manifest_format.major == 1
287287
@warn """The active manifest file at `$(manifest_file)` has an old format that is being maintained.
288-
To update to the new format run `Pkg.upgrade_manifest()` which will upgrade the format without re-resolving.""" maxlog = 1
288+
To update to the new format run `Pkg.upgrade_manifest()` which will upgrade the format without re-resolving.""" maxlog = 1 _id = Symbol(manifest_file)
289289
end
290290
return write_manifest(destructure(manifest), manifest_file)
291291
end
@@ -304,3 +304,27 @@ function write_manifest(raw_manifest::Dict, manifest_file::AbstractString)
304304
str = sprint(write_manifest, raw_manifest)
305305
write(manifest_file, str)
306306
end
307+
308+
############
309+
# METADATA #
310+
############
311+
312+
function check_warn_manifest_julia_version_compat(manifest::Manifest, manifest_file::String)
313+
isempty(manifest.deps) && return
314+
if manifest.manifest_format < v"2"
315+
@warn """The active manifest file is an older format with no julia version entry. Dependencies may have \
316+
been resolved with a different julia version.""" maxlog = 1 _file = manifest_file _line = 0 _module = nothing
317+
return
318+
end
319+
v = manifest.julia_version
320+
if v === nothing
321+
@warn """The active manifest file is missing a julia version entry. Dependencies may have \
322+
been resolved with a different julia version.""" maxlog = 1 _file = manifest_file _line = 0 _module = nothing
323+
return
324+
end
325+
if v.major != VERSION.major && v.minor != VERSION.minor
326+
ver_str = something(manifest.julia_version, "pre-1.7")
327+
@warn """The active manifest file has dependencies that were resolved with a different julia \
328+
version ($(manifest.julia_version)). Unexpected behavior may occur.""" maxlog = 1 _file = manifest_file _line = 0 _module = nothing
329+
end
330+
end

test/manifests.jl

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@ using Test, UUIDs, Dates, TOML
44
import ..Pkg, LibGit2
55
using ..Utils
66

7+
# used with the reference manifests in `test/manifest/formats`
8+
# ensures the manifests are valid and restored after test
9+
function reference_manifest_isolated_test(f, dir::String; v1::Bool=false)
10+
env_dir = joinpath(@__DIR__, "manifest", "formats", dir)
11+
env_manifest = joinpath(env_dir, "Manifest.toml")
12+
env_project = joinpath(env_dir, "Project.toml")
13+
cp(env_manifest, string(env_manifest, "_backup"))
14+
cp(env_project, string(env_project, "_backup"))
15+
try
16+
isfile(env_manifest) || error("Reference manifest is missing")
17+
if Base.is_v1_format_manifest(Base.parsed_toml(env_manifest)) == !v1
18+
error("Reference manifest file at $(env_manifest) is invalid")
19+
end
20+
isolate(loaded_depot=true) do
21+
f(env_dir, env_manifest)
22+
end
23+
finally
24+
cp(string(env_manifest, "_backup"), env_manifest, force = true)
25+
rm(string(env_manifest, "_backup"))
26+
cp(string(env_project, "_backup"), env_project, force = true)
27+
rm(string(env_project, "_backup"))
28+
end
29+
end
30+
31+
##
32+
733
@testset "Manifest.toml formats" begin
834
@testset "Default manifest format is v2" begin
935
isolate(loaded_depot=true) do
@@ -19,13 +45,7 @@ using ..Utils
1945
end
2046

2147
@testset "v1.0: activate, change, maintain manifest format" begin
22-
env_dir = joinpath(@__DIR__, "manifest", "formats", "v1.0")
23-
env_manifest = joinpath(env_dir, "Manifest.toml")
24-
isfile(env_manifest) || error("Reference manifest is missing")
25-
if Base.is_v1_format_manifest(Base.parsed_toml(env_manifest)) == false
26-
error("Reference manifest file at $(env_manifest) is invalid")
27-
end
28-
isolate(loaded_depot=true) do
48+
reference_manifest_isolated_test("v1.0", v1 = true) do env_dir, env_manifest
2949
io = IOBuffer()
3050
Pkg.activate(env_dir; io=io)
3151
output = String(take!(io))
@@ -41,13 +61,7 @@ using ..Utils
4161
end
4262

4363
@testset "v2.0: activate, change, maintain manifest format" begin
44-
env_dir = joinpath(@__DIR__, "manifest", "formats", "v2.0")
45-
env_manifest = joinpath(env_dir, "Manifest.toml")
46-
isfile(env_manifest) || error("Reference manifest is missing")
47-
if Base.is_v1_format_manifest(Base.parsed_toml(env_manifest))
48-
error("Reference manifest file at $(env_manifest) is invalid")
49-
end
50-
isolate(loaded_depot=true) do
64+
reference_manifest_isolated_test("v2.0") do env_dir, env_manifest
5165
io = IOBuffer()
5266
Pkg.activate(env_dir; io=io)
5367
output = String(take!(io))
@@ -72,50 +86,69 @@ using ..Utils
7286
@test m.manifest_format == m2.manifest_format
7387
@test m.other == m2.other
7488
end
75-
7689
end
7790
end
7891

7992
@testset "v3.0: unknown format, warn" begin
8093
# the reference file here is not actually v3.0. It just represents an unknown manifest format
81-
env_dir = joinpath(@__DIR__, "manifest", "formats", "v3.0_unknown")
82-
env_manifest = joinpath(env_dir, "Manifest.toml")
83-
isfile(env_manifest) || error("Reference manifest is missing")
84-
isolate(loaded_depot=true) do
94+
reference_manifest_isolated_test("v3.0_unknown") do env_dir, env_manifest
8595
io = IOBuffer()
8696
@test_logs (:warn,) Pkg.activate(env_dir; io=io)
8797
end
8898
end
8999

90100
@testset "Pkg.upgrade_manifest()" begin
91-
env_dir = joinpath(@__DIR__, "manifest", "formats", "v1.0")
92-
env_manifest = joinpath(env_dir, "Manifest.toml")
93-
cp(env_manifest, string(env_manifest, "_backup"))
94-
try
95-
isfile(env_manifest) || error("Reference manifest is missing")
96-
if Base.is_v1_format_manifest(Base.parsed_toml(env_manifest)) == false
97-
error("Reference manifest file at $(env_manifest) is invalid")
98-
end
101+
reference_manifest_isolated_test("v1.0", v1 = true) do env_dir, env_manifest
102+
io = IOBuffer()
103+
Pkg.activate(env_dir; io=io)
104+
output = String(take!(io))
105+
@test occursin(r"Activating.*project at.*`.*v1.0`", output)
106+
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest))
107+
108+
Pkg.upgrade_manifest()
109+
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest)) == false
110+
Pkg.activate(env_dir; io=io)
111+
output = String(take!(io))
112+
@test occursin(r"Activating.*project at.*`.*v1.0`", output)
113+
@test Pkg.Types.Context().env.manifest.manifest_format == v"2.0.0"
114+
end
115+
end
116+
end
117+
118+
@testset "Manifest metadata" begin
119+
@testset "julia_version" begin
120+
@testset "new environment: value is `nothing`, then `VERSION` after resolve" begin
99121
isolate(loaded_depot=true) do
100-
io = IOBuffer()
101-
Pkg.activate(env_dir; io=io)
102-
output = String(take!(io))
103-
@test occursin(r"Activating.*project at.*`.*v1.0`", output)
104-
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest))
105-
106-
Pkg.upgrade_manifest()
107-
@test Base.is_v1_format_manifest(Base.parsed_toml(env_manifest)) == false
108-
Pkg.activate(env_dir; io=io)
109-
output = String(take!(io))
110-
@test occursin(r"Activating.*project at.*`.*v1.0`", output)
111-
@test Pkg.Types.Context().env.manifest.manifest_format == v"2.0.0"
122+
Pkg.activate(; temp=true)
123+
@test Pkg.Types.Context().env.manifest.julia_version == nothing
124+
Pkg.add("Profile")
125+
@test Pkg.Types.Context().env.manifest.julia_version == VERSION
126+
end
127+
end
128+
@testset "activating old environment: maintains old version, then `VERSION` after resolve" begin
129+
reference_manifest_isolated_test("v2.0") do env_dir, env_manifest
130+
Pkg.activate(env_dir)
131+
@test Pkg.Types.Context().env.manifest.julia_version == v"1.7.0-DEV.1199"
132+
133+
Pkg.add("Profile")
134+
@test Pkg.Types.Context().env.manifest.julia_version == VERSION
135+
end
136+
end
137+
@testset "instantiate manifest from different julia_version" begin
138+
reference_manifest_isolated_test("v1.0", v1 = true) do env_dir, env_manifest
139+
Pkg.activate(env_dir)
140+
@test_logs (:warn, r"The active manifest file") Pkg.instantiate()
141+
@test Pkg.Types.Context().env.manifest.julia_version == nothing
142+
end
143+
if VERSION >= v"1.8"
144+
reference_manifest_isolated_test("v2.0") do env_dir, env_manifest
145+
Pkg.activate(env_dir)
146+
@test_logs (:warn, r"The active manifest file") Pkg.instantiate()
147+
@test Pkg.Types.Context().env.manifest.julia_version == v"1.7.0-DEV.1199"
148+
end
112149
end
113-
finally
114-
cp(string(env_manifest, "_backup"), env_manifest, force = true)
115-
rm(string(env_manifest, "_backup"))
116150
end
117151
end
118152
end
119153

120-
121154
end # module

test/new.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ end
895895
) Pkg.pkg"add some/really/random/Dir"
896896
# warn if not explicit about adding directory
897897
mkdir("Example")
898-
@test_logs (:info, r"Use `./Example` to add or develop the local directory at `.*`.") Pkg.pkg"add Example"
898+
@test_logs (:info, r"Use `./Example` to add or develop the local directory at `.*`.") match_mode=:any Pkg.pkg"add Example"
899899
end end
900900
end
901901

@@ -1967,7 +1967,7 @@ end
19671967
# other
19681968
isolate(loaded_depot=true) do
19691969
@test_deprecated Pkg.status(Pkg.PKGMODE_MANIFEST)
1970-
@test_logs (:warn, r"diff option only available") Pkg.status(diff=true)
1970+
@test_logs (:warn, r"diff option only available") match_mode=:any Pkg.status(diff=true)
19711971
end
19721972
# State changes
19731973
isolate(loaded_depot=true) do

0 commit comments

Comments
 (0)