Skip to content

Commit

Permalink
Revise the API of is_manifest_current. (#3701)
Browse files Browse the repository at this point in the history
  • Loading branch information
GunnarFarneback authored Dec 17, 2023
1 parent 60b7b79 commit a509bc0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
10 changes: 9 additions & 1 deletion src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,15 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
return
end

is_manifest_current(ctx::Context = Context()) = Operations.is_manifest_current(ctx.env)
is_manifest_current(ctx::Context) = Operations.is_manifest_current(ctx.env)
function is_manifest_current(path::AbstractString)
project_file = projectfile_path(path, strict = true)
if project_file === nothing
pkgerror("could not find project file at `$path`")
end
env = EnvCache(project_file)
return Operations.is_manifest_current(env)
end

const UsageDict = Dict{String,DateTime}
const UsageByDepotDict = Dict{String,UsageDict}
Expand Down
11 changes: 8 additions & 3 deletions src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,17 @@ Upgrades the format of the current or specified manifest file from v1.0 to v2.0
const upgrade_manifest = API.upgrade_manifest

"""
is_manifest_current(ctx::Context = Context())
is_manifest_current(path::AbstractString)
Returns whether the active manifest was resolved from the active project state.
Returns whether the manifest for the project at `path` was resolved from the current project file.
For instance, if the project had compat entries changed, but the manifest wasn't re-resolved, this would return false.
If the manifest doesn't have the project hash recorded, `nothing` is returned.
If the manifest doesn't have the project hash recorded, or if there is no manifest file, `nothing` is returned.
This function can be used in tests to verify that the manifest is synchronized with the project file:
using Pkg, Test, Package
@test Pkg.is_manifest_current(pkgdir(Package))
"""
const is_manifest_current = API.is_manifest_current

Expand Down
8 changes: 4 additions & 4 deletions test/manifests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ end

Pkg.activate(; temp=true)
Pkg.add("Example")
@test Pkg.is_manifest_current() === true
@test Pkg.is_manifest_current(Pkg.Types.Context()) === true

Pkg.compat("Example", "0.4")
@test Pkg.is_manifest_current() === false
@test Pkg.is_manifest_current(Pkg.Types.Context()) === false
Pkg.status(io = iob)
sync_msg_str = r"The project dependencies or compat requirements have changed since the manifest was last resolved."
@test occursin(sync_msg_str, String(take!(iob)))
@test_logs (:warn, sync_msg_str) Pkg.instantiate()

Pkg.update()
@test Pkg.is_manifest_current() === true
@test Pkg.is_manifest_current(Pkg.Types.Context()) === true
Pkg.status(io = iob)
@test !occursin(sync_msg_str, String(take!(iob)))

Expand All @@ -206,7 +206,7 @@ end
@test_logs (:warn, sync_msg_str) Pkg.instantiate()

Pkg.rm("Example")
@test Pkg.is_manifest_current() === true
@test Pkg.is_manifest_current(Pkg.Types.Context()) === true
Pkg.status(io = iob)
@test !occursin(sync_msg_str, String(take!(iob)))
end
Expand Down

0 comments on commit a509bc0

Please sign in to comment.