diff --git a/master_changes.md b/master_changes.md index 1767f51d62b..1698eecd4e4 100644 --- a/master_changes.md +++ b/master_changes.md @@ -104,6 +104,7 @@ New option/command/subcommand are prefixed with ◈. ## Solver * Fix Cudf preprocessing [#4534 @AltGr] + * Allow to upgrade to a hidden-version package if a hidden-version package is already installed [#4525 @kit-ty-kate] ## Client * diff --git a/src/client/opamClient.ml b/src/client/opamClient.ml index 29bb60eac00..34f4085c683 100644 --- a/src/client/opamClient.ml +++ b/src/client/opamClient.ml @@ -187,8 +187,8 @@ let compute_upgrade_t if OpamPackage.Set.exists (fun nv -> OpamFormula.check atom nv && - not (OpamFile.OPAM.has_flag Pkgflag_AvoidVersion - (OpamSwitchState.opam t nv))) + (not (OpamFile.OPAM.has_flag Pkgflag_AvoidVersion (OpamSwitchState.opam t nv)) || + OpamSwitchState.can_upgrade_to_avoid_version (OpamPackage.name nv) t)) (Lazy.force t.available_packages) then atom else (n, None) diff --git a/src/state/opamSwitchState.ml b/src/state/opamSwitchState.ml index 0f8c877e135..19362704ca1 100644 --- a/src/state/opamSwitchState.ml +++ b/src/state/opamSwitchState.ml @@ -815,6 +815,12 @@ let get_conflicts st packages opams_map = (fun package -> OpamPackageVar.resolve_switch ~package st) packages opams_map +let can_upgrade_to_avoid_version name st = + OpamPackage.Set.exists (fun pkg -> + OpamPackage.Name.equal (OpamPackage.name pkg) name && + OpamFile.OPAM.has_flag Pkgflag_AvoidVersion (OpamPackage.Map.find pkg st.opams) + ) st.installed + let universe st ?(test=OpamStateConfig.(!r.build_test)) ?(doc=OpamStateConfig.(!r.build_doc)) @@ -913,7 +919,8 @@ let universe st in let avoid_versions = OpamPackage.Map.fold (fun nv opam acc -> - if OpamFile.OPAM.has_flag Pkgflag_AvoidVersion opam + if OpamFile.OPAM.has_flag Pkgflag_AvoidVersion opam && + not (can_upgrade_to_avoid_version (OpamFile.OPAM.name opam) st) then OpamPackage.Set.add nv acc else acc) st.opams OpamPackage.Set.empty diff --git a/src/state/opamSwitchState.mli b/src/state/opamSwitchState.mli index 76ffe3aafbb..5070c3aa9d9 100644 --- a/src/state/opamSwitchState.mli +++ b/src/state/opamSwitchState.mli @@ -239,6 +239,9 @@ val unavailable_reason: 'a switch_state -> ?default:string -> name * OpamFormula.version_formula -> string +(** Returns whether or not the package can be upgraded to a version tagged with avoid-version *) +val can_upgrade_to_avoid_version : OpamPackage.Name.t -> 'a switch_state -> bool + (** Handle a cache of the opam files of installed packages *) module Installed_cache: sig type t = OpamFile.OPAM.t OpamPackage.Map.t