Skip to content

Commit 27e6dfa

Browse files
authored
Merge pull request #5197 from rjbou/213
Backport PR for 2.1.3
2 parents f2bba77 + 4458b1d commit 27e6dfa

6 files changed

Lines changed: 110 additions & 17 deletions

File tree

master_changes.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ New option/command/subcommand are prefixed with ◈.
2525
*
2626

2727
## Switch
28-
*
28+
* When inferring a 2.1+ switch invariant from 2.0 base packages, don't filter out pinned packages as that causes very wide invariants for pinned compiler packages [#5176 @dra27 - fix #4501]
2929

3030
## Pin
3131
*
@@ -106,7 +106,8 @@ New option/command/subcommand are prefixed with ◈.
106106
* Add repo optim enable/disable test [#5015 @rjbou]
107107
* Update list with co-instabillity [#5024 @AltGr]
108108
* Update var-option test with no switch examples [#5025]
109-
* Escape for cmdliner.1.1.1 output chane [#5131 @rjbou]
109+
* Escape for cmdliner.1.1.1 output change [#5131 @rjbou]
110+
* Add test for switch upgrade from 2.0 root, with pinned compiler [#5176 @rjbou @kit-ty-kate]
110111
### Engine
111112
* Fix meld reftest: open only with failing ones [#4913 @rjbou]
112113
* Add `BASEDIR` to environement [#4913 @rjbou]
@@ -166,3 +167,4 @@ New option/command/subcommand are prefixed with ◈.
166167
* `OpamHash`: add `sort` from strongest to weakest kind
167168
* `OpamSystem.real_path`: Remove the double chdir trick on OCaml >= 4.13.0 [#4961 @kit-ty-kate]
168169
* `OpamClient`: fix `update_with_init_config`, when ``jobs` was set in `init_config`, it dropped rest of `config` update [#5056 @rjbou]
170+
* `OpamCompat`: add `Lazy` module and `Lazy.map` function [#5176 @dra27]

src/core/opamCompat.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,15 @@ end
138138
#if OCAML_VERSION < (4, 7, 0)
139139
module Stdlib = Pervasives
140140
#endif
141+
142+
module Lazy =
143+
#if OCAML_VERSION >= (4, 13, 0)
144+
Lazy
145+
#else
146+
struct
147+
include Lazy
148+
149+
let map f x =
150+
lazy (f (force x))
151+
end
152+
#endif

src/core/opamCompat.mli

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,14 @@ end
118118
#if OCAML_VERSION < (4, 7, 0)
119119
module Stdlib = Pervasives
120120
#endif
121+
122+
module Lazy
123+
#if OCAML_VERSION >= (4, 13, 0)
124+
= Lazy
125+
#else
126+
: sig
127+
include module type of struct include Lazy end
128+
129+
val map : ('a -> 'b) -> 'a t -> 'b t
130+
end
131+
#endif

src/state/opamSwitchState.ml

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,28 @@ let load_switch_config ?lock_kind gt switch =
3434
(OpamSwitch.to_string switch);
3535
OpamFile.Switch_config.empty)
3636

37-
let compute_available_packages gt switch switch_config ~pinned ~opams =
37+
let filter_available_packages gt switch switch_config ~opams =
38+
OpamPackage.keys @@
39+
OpamPackage.Map.filter (fun package opam ->
40+
OpamFilter.eval_to_bool ~default:false
41+
(OpamPackageVar.resolve_switch_raw ~package gt switch switch_config)
42+
(OpamFile.OPAM.available opam))
43+
opams
44+
45+
let compute_available_and_pinned_packages gt switch switch_config ~pinned ~opams =
3846
(* remove all versions of pinned packages, but the pinned-to version *)
3947
let pinned_names = OpamPackage.names_of_packages pinned in
40-
let opams =
41-
OpamPackage.Map.filter
48+
let (opams, pinned) =
49+
OpamPackage.Map.partition
4250
(fun nv _ ->
4351
not (OpamPackage.Name.Set.mem nv.name pinned_names) ||
4452
OpamPackage.Set.mem nv pinned)
4553
opams
4654
in
47-
let avail_map =
48-
OpamPackage.Map.filter (fun package opam ->
49-
OpamFilter.eval_to_bool ~default:false
50-
(OpamPackageVar.resolve_switch_raw ~package gt switch switch_config)
51-
(OpamFile.OPAM.available opam))
52-
opams
53-
in
54-
OpamPackage.keys avail_map
55+
(filter_available_packages gt switch switch_config ~opams, pinned)
56+
57+
let compute_available_packages gt switch switch_config ~pinned ~opams =
58+
fst @@ compute_available_and_pinned_packages gt switch switch_config ~pinned ~opams
5559

5660
let repos_list_raw rt switch_config =
5761
let global, repos =
@@ -115,7 +119,7 @@ let infer_switch_invariant_raw
115119
deps dmap
116120
in
117121
dmap)
118-
(OpamPackage.packages_of_names (Lazy.force available_packages) @@
122+
(OpamPackage.packages_of_names available_packages @@
119123
OpamPackage.names_of_packages @@
120124
compiler)
121125
OpamPackage.Map.empty
@@ -133,7 +137,7 @@ let infer_switch_invariant_raw
133137
match List.sort (fun (_, c1) (_, c2) -> compare c1 c2) counts with
134138
| (nv, _) :: _ ->
135139
let versions =
136-
OpamPackage.packages_of_name (Lazy.force available_packages) nv.name
140+
OpamPackage.packages_of_name available_packages nv.name
137141
in
138142
let n = OpamPackage.Set.cardinal versions in
139143
if n <= 1 then
@@ -153,9 +157,10 @@ let infer_switch_invariant st =
153157
st.installed
154158
else st.compiler_packages
155159
in
160+
let lazy available_packages = st.available_packages in
156161
infer_switch_invariant_raw
157162
st.switch_global st.switch st.switch_config st.opams
158-
st.packages compiler_packages st.installed_roots st.available_packages
163+
st.packages compiler_packages st.installed_roots available_packages
159164

160165
let depexts_raw ~env nv opams =
161166
try
@@ -330,7 +335,7 @@ let load lock_kind gt rt switch =
330335
OpamPackage.Map.union (fun _ x -> x) repos_package_index pinned_opams
331336
in
332337
let available_packages =
333-
lazy (compute_available_packages gt switch switch_config
338+
lazy (compute_available_and_pinned_packages gt switch switch_config
334339
~pinned ~opams)
335340
in
336341
let opams =
@@ -402,6 +407,11 @@ let load lock_kind gt rt switch =
402407
match switch_config.invariant with
403408
| Some invariant -> switch_config, invariant
404409
| None ->
410+
let available_packages =
411+
let lazy (available_packages, pinned) = available_packages in
412+
OpamPackage.Set.union available_packages @@
413+
filter_available_packages gt switch switch_config ~opams:pinned
414+
in
405415
let invariant =
406416
infer_switch_invariant_raw
407417
gt switch switch_config opams
@@ -486,6 +496,7 @@ let load lock_kind gt rt switch =
486496
OpamPackage.Set.empty
487497
) in
488498
(* depext check *)
499+
let available_packages = OpamCompat.Lazy.map fst available_packages in
489500
let sys_packages =
490501
if not (OpamFile.Config.depext gt.config)
491502
|| OpamStateConfig.(!r.no_depexts) then

tests/reftests/dune.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,23 @@
458458
%{targets}
459459
(run ./run.exe %{bin:opam} %{dep:upgrade-format.test} %{read-lines:testing-env}))))
460460

461+
(alias
462+
(name reftest-upgrade-two-point-o)
463+
(action
464+
(diff upgrade-two-point-o.test upgrade-two-point-o.out)))
465+
466+
(alias
467+
(name reftest)
468+
(deps (alias reftest-upgrade-two-point-o)))
469+
470+
(rule
471+
(targets upgrade-two-point-o.out)
472+
(deps root-N0REP0)
473+
(action
474+
(with-stdout-to
475+
%{targets}
476+
(run ./run.exe %{bin:opam} %{dep:upgrade-two-point-o.test} %{read-lines:testing-env}))))
477+
461478
(alias
462479
(name reftest-var-option)
463480
(action
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
N0REP0
2+
### <pkg:i-am-compiler.1>
3+
opam-version: "2.0"
4+
flags: compiler
5+
### <pkg:i-am-compiler.2>
6+
opam-version: "2.0"
7+
flags: compiler
8+
### OPAMYES=1
9+
### <OPAM/config>
10+
opam-version: "2.0"
11+
repositories: "default"
12+
installed-switches: ["pinned-comp"]
13+
switch: "pinned-comp"
14+
default-compiler: ["i-am-compiler"]
15+
### <OPAM/pinned-comp/.opam-switch/switch-state>
16+
opam-version: "2.0"
17+
compiler: ["i-am-compiler.1"]
18+
roots: ["i-am-compiler.1"]
19+
installed: ["i-am-compiler.1"]
20+
pinned: ["i-am-compiler.1"]
21+
### <OPAM/pinned-comp/.opam-switch/switch-config>
22+
opam-version: "2.0"
23+
synopsis: "switch with pinned compiler"
24+
### OPAMDEBUGSECTIONS=STATE opam upgrade --show-action --debug-level=-1
25+
STATE LOAD-SWITCH-STATE @ pinned-comp
26+
STATE Definition missing for installed package i-am-compiler.1, copying from repo
27+
STATE Inferred invariant: from base packages { i-am-compiler.1 }, (roots { i-am-compiler.1 }) => ["i-am-compiler" {= "1"}]
28+
STATE Switch state loaded in 0.000s
29+
STATE Detected changed packages (marked for reinstall): {}
30+
Everything as up-to-date as possible (run with --verbose to show unavailable upgrades).
31+
However, you may "opam upgrade" these packages explicitly, which will ask permission to downgrade or uninstall the conflicting packages.
32+
Nothing to do.
33+
### opam pin remove i-am-compiler
34+
Ok, i-am-compiler is no longer pinned locally (version 1)
35+
No package build needed.
36+
Nothing to do.
37+
### opam upgrade --show-action
38+
Everything as up-to-date as possible (run with --verbose to show unavailable upgrades).
39+
However, you may "opam upgrade" these packages explicitly, which will ask permission to downgrade or uninstall the conflicting packages.
40+
Nothing to do.

0 commit comments

Comments
 (0)