Skip to content

Commit

Permalink
Merge pull request #6273 from kit-ty-kate/no-avoid-version-upgrade
Browse files Browse the repository at this point in the history
opam upgrade: Do not show the not-up-to-date message with packages tagged with avoid-version
  • Loading branch information
rjbou authored Feb 5, 2025
2 parents 42b8619 + 8360db5 commit de8748b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 19 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ users)
## Var/Option

## Update / Upgrade
* [BUG] Do not show the not-up-to-date message with packages tagged with avoid-version [#6273 @kit-ty-kate - fix #6271]

## Tree

Expand Down Expand Up @@ -166,6 +167,7 @@ users)
* Extend the tests on opam admin check by including all the arguments [#6331 @kit-ty-kate @rjbou]
* Add double pinning test in case of opam/opam opam file [#6343 @rjbou]
* Make sure `download.test` does not fail due to a checksum collision in the download cache [#6378 @kit-ty-kate]
* Add a test showing the behaviour of `opam upgrade` with packages flagged with `avoid-version`/`deprecated` [#6273 @kit-ty-kate]

### Engine

Expand Down
24 changes: 21 additions & 3 deletions src/client/opamClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,27 @@ let upgrade_t
else OpamPackage.packages_of_names t.installed requested
in
let latest =
OpamPackage.Name.Set.fold (fun name acc ->
OpamPackage.Set.add (OpamPackage.max_version t.packages name) acc)
(OpamPackage.names_of_packages to_check)
OpamPackage.Set.fold (fun pkg acc ->
let name = OpamPackage.name pkg in
let pkgs = OpamPackage.packages_of_name t.packages name in
let latest =
OpamPackage.Set.fold (fun pkg latest ->
if OpamPackage.compare latest pkg < 0 then
let opam = OpamPackage.Map.find pkg t.opams in
let avoid_version =
List.exists (function
| Pkgflag_AvoidVersion | Pkgflag_Deprecated -> true
| Pkgflag_LightUninstall | Pkgflag_Verbose
| Pkgflag_Plugin | Pkgflag_Compiler
| Pkgflag_Conf | Pkgflag_Unknown _ -> false)
(OpamFile.OPAM.flags opam)
in
if avoid_version then latest else pkg
else latest)
pkgs pkg
in
OpamPackage.Set.add latest acc)
to_check
OpamPackage.Set.empty in
let notuptodate = latest -- to_check in
if OpamPackage.Set.is_empty notuptodate then
Expand Down
11 changes: 3 additions & 8 deletions tests/reftests/avoid-version.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ The following actions will be faked:
Faking installation of a.1
Done.
### opam upgrade a
Everything as up-to-date as possible

The following packages are not being upgraded because the new versions conflict with other installed packages:
- a.2
However, you may "opam upgrade" these packages explicitly at these versions (e.g. "opam upgrade a.2"), which will ask permission to downgrade or uninstall the conflicting packages.
Already up-to-date.
Nothing to do.
### <pkg:a.1.1>
opam-version: "2.0"
Expand Down Expand Up @@ -115,9 +111,8 @@ flags: avoid-version
Everything as up-to-date as possible

The following packages are not being upgraded because the new versions conflict with other installed packages:
- a.4
- b.3
However, you may "opam upgrade" these packages explicitly at these versions (e.g. "opam upgrade a.4"), which will ask permission to downgrade or uninstall the conflicting packages.
- b.2
However, you may "opam upgrade" these packages explicitly at these versions (e.g. "opam upgrade b.2"), which will ask permission to downgrade or uninstall the conflicting packages.
Nothing to do.
### opam upgrade b.3
The following actions will be faked:
Expand Down
11 changes: 3 additions & 8 deletions tests/reftests/deprecated.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ The following actions will be faked:
Faking installation of a.1
Done.
### opam upgrade a
Everything as up-to-date as possible

The following packages are not being upgraded because the new versions conflict with other installed packages:
- a.2
However, you may "opam upgrade" these packages explicitly at these versions (e.g. "opam upgrade a.2"), which will ask permission to downgrade or uninstall the conflicting packages.
Already up-to-date.
Nothing to do.
### <pkg:a.1.1>
opam-version: "2.0"
Expand Down Expand Up @@ -121,9 +117,8 @@ flags: deprecated
Everything as up-to-date as possible

The following packages are not being upgraded because the new versions conflict with other installed packages:
- a.4
- b.3
However, you may "opam upgrade" these packages explicitly at these versions (e.g. "opam upgrade a.4"), which will ask permission to downgrade or uninstall the conflicting packages.
- b.2
However, you may "opam upgrade" these packages explicitly at these versions (e.g. "opam upgrade b.2"), which will ask permission to downgrade or uninstall the conflicting packages.
Nothing to do.
### opam upgrade b.3
The following actions will be faked:
Expand Down
46 changes: 46 additions & 0 deletions tests/reftests/upgrade.test
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,49 @@ Done.
# Packages matching: name-match(quux) & installed
# Name # Installed files
quux ${BASEDIR}/OPAM/upgrading/lib/quux ${BASEDIR}/OPAM/upgrading/lib/quux/fichier
### ::::::::::::::::::
### : opam upgrade should not offer packages flagged with avoid-version
### ::::::::::::::::::
### <pkg:avoid-version.1>
opam-version: "2.0"
### <pkg:avoid-version.2>
opam-version: "2.0"
flags: avoid-version
### <pkg:avoid-version.3>
opam-version: "2.0"
flags: deprecated
### opam install avoid-version
The following actions will be performed:
=== install 1 package
- install avoid-version 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> installed avoid-version.1
Done.
### opam upgrade
Already up-to-date.
Nothing to do.
### opam upgrade avoid-version
Already up-to-date.
Nothing to do.
### opam install avoid-version.2
The following actions will be performed:
=== upgrade 1 package
- upgrade avoid-version 1 to 2

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed avoid-version.1
-> installed avoid-version.2
Done.
### opam upgrade
The following actions will be performed:
=== upgrade 1 package
- upgrade avoid-version 2 to 3 (deprecated)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed avoid-version.2
-> installed avoid-version.3
Done.

<><> avoid-version.3 installed successfully <><><><><><><><><><><><><><><><><><>
=> Note: This package is deprecated.

0 comments on commit de8748b

Please sign in to comment.