Skip to content

Commit

Permalink
Fix --update-invariant when changing package name
Browse files Browse the repository at this point in the history
Fixes ocaml#4353, although an issue remains if invariant packages are purely
removed, as opposed to replaced.
  • Loading branch information
AltGr committed Sep 15, 2020
1 parent 60b571a commit e23b712
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions src/client/opamSolution.ml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ let parallel_apply t ~requested ?add_roots ~assume_built ?(force_remove=false)
(* only needed when --update-invariant is set. Use the configured invariant,
not the current one which will be empty. *)
let original_invariant = t.switch_config.OpamFile.Switch_config.invariant in
let original_invariant_packages =
OpamFormula.packages t.installed original_invariant
in
let invariant_ref = ref original_invariant in

let bypass_ref = ref (t.switch_config.OpamFile.Switch_config.depext_bypass) in
Expand All @@ -336,19 +339,35 @@ let parallel_apply t ~requested ?add_roots ~assume_built ?(force_remove=false)
let bypass = OpamSysPkg.Set.union missing_depexts !bypass_ref in
let invariant =
if OpamStateConfig.(!r.unlock_base) then
let update_cstr cstr =
if OpamFormula.check_version_formula cstr nv.version then cstr
else
OpamFormula.map (fun (relop, _ as vat) ->
if OpamFormula.check_version_formula (Atom vat) nv.version
then Atom vat
else match relop with
| `Neq | `Gt | `Lt -> OpamFormula.Empty
| `Eq | `Geq | `Leq -> Atom (relop, nv.version))
cstr
in
let nvset = OpamPackage.Set.singleton nv in
let upd_packages =
OpamSwitchState.conflicts_with t nvset original_invariant_packages
in
OpamFormula.map (fun (n, cstr as at) ->
if n <> nv.name || OpamFormula.check_version_formula cstr nv.version
then Atom at else
let cstr =
OpamFormula.map (fun (relop, _ as vat) ->
if OpamFormula.check_version_formula (Atom vat) nv.version
then Atom vat
else match relop with
| `Neq | `Gt | `Lt -> OpamFormula.Empty
| `Eq | `Geq | `Leq -> Atom (relop, nv.version))
cstr
in
Atom (n, cstr))
if
OpamPackage.Set.exists (OpamFormula.verifies (Atom at))
upd_packages
then
(* a package in the previous base validated this atom but is in
conflict with what we just installed *)
Atom (nv.name, update_cstr cstr)
else if
n = nv.name && OpamFormula.check_version_formula cstr nv.version
then
Atom (n, update_cstr cstr)
else
Atom at)
!invariant_ref
else !invariant_ref
in
Expand All @@ -368,8 +387,9 @@ let parallel_apply t ~requested ?add_roots ~assume_built ?(force_remove=false)
{!t_ref.switch_config with invariant; depext_bypass = bypass }
in
t_ref := {!t_ref with switch_config};
OpamSwitchAction.install_switch_config t.switch_global.root t.switch
switch_config)
if not OpamStateConfig.(!r.dryrun) then
OpamSwitchAction.install_switch_config t.switch_global.root t.switch
switch_config)
in

let remove_from_install ?keep_as_root nv =
Expand Down

0 comments on commit e23b712

Please sign in to comment.