Skip to content

Commit 55d5375

Browse files
fix forcedeps mode with build numbers (#42)
1 parent d5d2db3 commit 55d5375

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

downgrade.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,19 @@ function get_resolved_versions(manifest_file::String)
479479
return versions
480480
end
481481

482+
"""
483+
versions_match_ignoring_build(actual, expected)
484+
485+
Return true if two versions are equal, ignoring SemVer build metadata
486+
(the `+...` suffix). This allows `1.2.3` and `1.2.3+4` to match.
487+
"""
488+
function versions_match_ignoring_build(actual::VersionNumber, expected::VersionNumber)
489+
return actual.major == expected.major &&
490+
actual.minor == expected.minor &&
491+
actual.patch == expected.patch &&
492+
actual.prerelease == expected.prerelease
493+
end
494+
482495
"""
483496
check_forced_lower_bounds(project_file, manifest_file, ignore_pkgs)
484497
@@ -503,7 +516,7 @@ function check_forced_lower_bounds(project_file::String, manifest_file::String,
503516
# Check if the major.minor.patch matches
504517
# We compare the full version, but note that the lower bound might be
505518
# less specific (e.g., "1.2" means v1.2.0)
506-
if actual != expected
519+
if !versions_match_ignoring_build(actual, expected)
507520
@error "forcedeps check failed: $pkg resolved to $actual but lower bound is $expected"
508521
all_match = false
509522
else

test/runtests.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,38 @@ downgrade_jl = joinpath(dirname(@__DIR__), "downgrade.jl")
152152
end
153153
end
154154

155+
@testset "forcedeps mode - ignores build metadata" begin
156+
mktempdir() do dir
157+
cd(dir) do
158+
# JLL packages commonly resolve with build metadata (e.g., +0)
159+
# while compat lower bounds typically omit it.
160+
toml_content = """
161+
name = "TestPackage"
162+
version = "0.1.0"
163+
164+
[deps]
165+
OpenSSL_jll = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
166+
167+
[compat]
168+
julia = "1.10"
169+
OpenSSL_jll = "3.5.0"
170+
"""
171+
write("Project.toml", toml_content)
172+
173+
# Should pass even when resolved version is like 3.5.0+0
174+
run(`$(Base.julia_cmd()) $downgrade_jl "" "." "forcedeps" "1.10"`)
175+
176+
manifest = TOML.parsefile("Manifest.toml")
177+
deps = manifest["deps"]
178+
deps_OpenSSL_jll = get(deps, "OpenSSL_jll", [])
179+
180+
@test !isempty(deps_OpenSSL_jll)
181+
@test startswith(deps_OpenSSL_jll[1]["version"], "3.5.0")
182+
@test occursin("+", deps_OpenSSL_jll[1]["version"])
183+
end
184+
end
185+
end
186+
155187
@testset "invalid cases" begin
156188
# Test invalid mode
157189
mktempdir() do dir

0 commit comments

Comments
 (0)