Skip to content

fix: deduplicate dune version bounds in generated opam files - #14175

Merged
Leonidas-from-XIV merged 7 commits into
ocaml:mainfrom
robinbb:robinbb-fix-duplicate-dune-dep-3916
Apr 14, 2026
Merged

Leonidas-from-XIV merged 7 commits into
ocaml:mainfrom
robinbb:robinbb-fix-duplicate-dune-dep-3916

Conversation

@robinbb

@robinbb robinbb commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • When users declare an explicit (dune (>= X.Y)) dependency matching or exceeding the (lang dune X.Y) version, the generated opam file no longer contains redundant duplicate bounds like {>= "2.7" & >= "2.7"} or {>= "3.16" & >= "3.16.0"}
  • Uses OpamVersionCompare to keep only the more restrictive of the two >= bounds; other constraint shapes (=, or, and, etc.) continue to be combined with & as before
  • Adds three cram test cases covering exact match, higher patch version, and lower user bound

Fixes #3916
Fixes #11106

robinbb added 2 commits April 13, 2026 00:59
When users declare an explicit dune dependency with a >= constraint
that matches or exceeds the (lang dune X.Y) version, the generated
opam file no longer contains redundant duplicate bounds like
{>= "2.7" & >= "2.7"} or {>= "3.16" & >= "3.16.0"}.

The fix uses OpamVersionCompare to keep only the more restrictive
of the two >= bounds. Other constraint shapes (=, or, and, etc.)
continue to be combined with & as before.

Fixes ocaml#3916
Fixes ocaml#11106

Signed-off-by: Robin Bate Boerop <[email protected]>
Signed-off-by: Robin Bate Boerop <[email protected]>
Comment thread src/dune_rules/opam_create.ml Resolved
robinbb added 5 commits April 13, 2026 10:06
Address reviewer feedback: match the depends block by its delimiters
rather than hardcoding a line count.

Signed-off-by: Robin Bate Boerop <[email protected]>
Replace sed range patterns with the project's own dune_cmd helpers,
which are clearer and don't assume section-closing ] appears at
the start of a line.

Signed-off-by: Robin Bate Boerop <[email protected]>
Clarifies which constraint comes from (lang dune X.Y) and which
from the user's (depends ...) stanza.

Signed-off-by: Robin Bate Boerop <[email protected]>
When the user specifies a dune dependency like (dune (>= 2.5)) but
uses (lang dune 2.7), emit a warning explaining that the generated
opam file will use the higher lang version bound instead.

Signed-off-by: Robin Bate Boerop <[email protected]>
@robinbb
robinbb marked this pull request as ready for review April 13, 2026 18:01
@robinbb

robinbb commented Apr 13, 2026

Copy link
Copy Markdown
Collaborator Author

@Leonidas-from-XIV Back to you.

@Leonidas-from-XIV
Leonidas-from-XIV merged commit b097c51 into ocaml:main Apr 14, 2026
28 checks passed
@robinbb
robinbb deleted the robinbb-fix-duplicate-dune-dep-3916 branch April 14, 2026 18:47
robinbb added a commit to robinbb/dune that referenced this pull request May 9, 2026
PR ocaml#14175 added deduplication of redundant `>=` bounds on the `dune`
dependency in generated opam files (e.g. `{>= "3.17" & >= "3.20"}`
collapsing to `{>= "3.20"}`), but did so without a lang-version
guard. As a result, simply upgrading the dune binary to 3.23 changed
the generated opam output for projects whose `(lang dune X.Y)` had
not changed (issue ocaml#14436).

Gate the new behaviour on `(lang dune 3.23)`, the lang version under
which the dedup feature shipped. Projects at earlier lang versions
get the pre-14175 `And [lang; user]` shape. The accompanying user
warning (lower bound < lang version) is also gated, since it lives
inside `merge_dune_constraints`.

Fixes ocaml#14436

Signed-off-by: Robin Bate Boerop <[email protected]>
Alizter added a commit that referenced this pull request May 9, 2026
## Summary

Gate the dune-version-bound deduplication in generated opam files
(introduced in #14175 and shipped in 3.23.0) on `(lang dune 3.23)`.
Projects at earlier lang versions get the pre-14175 `And [lang; user]`
shape.

Fixes #14436

Related: #14175
shonfeder pushed a commit that referenced this pull request May 10, 2026
## Summary

Gate the dune-version-bound deduplication in generated opam files
(introduced in #14175 and shipped in 3.23.0) on `(lang dune 3.23)`.
Projects at earlier lang versions get the pre-14175 `And [lang; user]`
shape.

Fixes #14436

Related: #14175
(cherry picked from commit eb4a64a)
Signed-off-by: Robin Bate Boerop <[email protected]>
@Alizter Alizter added this to the 3.23.0 milestone Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redundant dune version constraint Duplicate bounds on autogenerated opam files

3 participants