Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR for 2.1.3 #5197

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ New option/command/subcommand are prefixed with ◈.
*

## Switch
*
* 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]

## Pin
*
Expand Down Expand Up @@ -106,7 +106,8 @@ New option/command/subcommand are prefixed with ◈.
* Add repo optim enable/disable test [#5015 @rjbou]
* Update list with co-instabillity [#5024 @AltGr]
* Update var-option test with no switch examples [#5025]
* Escape for cmdliner.1.1.1 output chane [#5131 @rjbou]
* Escape for cmdliner.1.1.1 output change [#5131 @rjbou]
* Add test for switch upgrade from 2.0 root, with pinned compiler [#5176 @rjbou @kit-ty-kate]
### Engine
* Fix meld reftest: open only with failing ones [#4913 @rjbou]
* Add `BASEDIR` to environement [#4913 @rjbou]
Expand Down Expand Up @@ -166,3 +167,4 @@ New option/command/subcommand are prefixed with ◈.
* `OpamHash`: add `sort` from strongest to weakest kind
* `OpamSystem.real_path`: Remove the double chdir trick on OCaml >= 4.13.0 [#4961 @kit-ty-kate]
* `OpamClient`: fix `update_with_init_config`, when ``jobs` was set in `init_config`, it dropped rest of `config` update [#5056 @rjbou]
* `OpamCompat`: add `Lazy` module and `Lazy.map` function [#5176 @dra27]
12 changes: 12 additions & 0 deletions src/core/opamCompat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,15 @@ end
#if OCAML_VERSION < (4, 7, 0)
module Stdlib = Pervasives
#endif

module Lazy =
#if OCAML_VERSION >= (4, 13, 0)
Lazy
#else
struct
include Lazy

let map f x =
lazy (f (force x))
end
#endif
11 changes: 11 additions & 0 deletions src/core/opamCompat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,14 @@ end
#if OCAML_VERSION < (4, 7, 0)
module Stdlib = Pervasives
#endif

module Lazy
#if OCAML_VERSION >= (4, 13, 0)
= Lazy
#else
: sig
include module type of struct include Lazy end

val map : ('a -> 'b) -> 'a t -> 'b t
end
#endif
41 changes: 26 additions & 15 deletions src/state/opamSwitchState.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,28 @@ let load_switch_config ?lock_kind gt switch =
(OpamSwitch.to_string switch);
OpamFile.Switch_config.empty)

let compute_available_packages gt switch switch_config ~pinned ~opams =
let filter_available_packages gt switch switch_config ~opams =
OpamPackage.keys @@
OpamPackage.Map.filter (fun package opam ->
OpamFilter.eval_to_bool ~default:false
(OpamPackageVar.resolve_switch_raw ~package gt switch switch_config)
(OpamFile.OPAM.available opam))
opams

let compute_available_and_pinned_packages gt switch switch_config ~pinned ~opams =
(* remove all versions of pinned packages, but the pinned-to version *)
let pinned_names = OpamPackage.names_of_packages pinned in
let opams =
OpamPackage.Map.filter
let (opams, pinned) =
OpamPackage.Map.partition
(fun nv _ ->
not (OpamPackage.Name.Set.mem nv.name pinned_names) ||
OpamPackage.Set.mem nv pinned)
opams
in
let avail_map =
OpamPackage.Map.filter (fun package opam ->
OpamFilter.eval_to_bool ~default:false
(OpamPackageVar.resolve_switch_raw ~package gt switch switch_config)
(OpamFile.OPAM.available opam))
opams
in
OpamPackage.keys avail_map
(filter_available_packages gt switch switch_config ~opams, pinned)

let compute_available_packages gt switch switch_config ~pinned ~opams =
fst @@ compute_available_and_pinned_packages gt switch switch_config ~pinned ~opams

let repos_list_raw rt switch_config =
let global, repos =
Expand Down Expand Up @@ -115,7 +119,7 @@ let infer_switch_invariant_raw
deps dmap
in
dmap)
(OpamPackage.packages_of_names (Lazy.force available_packages) @@
(OpamPackage.packages_of_names available_packages @@
OpamPackage.names_of_packages @@
compiler)
OpamPackage.Map.empty
Expand All @@ -133,7 +137,7 @@ let infer_switch_invariant_raw
match List.sort (fun (_, c1) (_, c2) -> compare c1 c2) counts with
| (nv, _) :: _ ->
let versions =
OpamPackage.packages_of_name (Lazy.force available_packages) nv.name
OpamPackage.packages_of_name available_packages nv.name
in
let n = OpamPackage.Set.cardinal versions in
if n <= 1 then
Expand All @@ -153,9 +157,10 @@ let infer_switch_invariant st =
st.installed
else st.compiler_packages
in
let lazy available_packages = st.available_packages in
infer_switch_invariant_raw
st.switch_global st.switch st.switch_config st.opams
st.packages compiler_packages st.installed_roots st.available_packages
st.packages compiler_packages st.installed_roots available_packages

let depexts_raw ~env nv opams =
try
Expand Down Expand Up @@ -330,7 +335,7 @@ let load lock_kind gt rt switch =
OpamPackage.Map.union (fun _ x -> x) repos_package_index pinned_opams
in
let available_packages =
lazy (compute_available_packages gt switch switch_config
lazy (compute_available_and_pinned_packages gt switch switch_config
~pinned ~opams)
in
let opams =
Expand Down Expand Up @@ -402,6 +407,11 @@ let load lock_kind gt rt switch =
match switch_config.invariant with
| Some invariant -> switch_config, invariant
| None ->
let available_packages =
let lazy (available_packages, pinned) = available_packages in
OpamPackage.Set.union available_packages @@
filter_available_packages gt switch switch_config ~opams:pinned
in
let invariant =
infer_switch_invariant_raw
gt switch switch_config opams
Expand Down Expand Up @@ -486,6 +496,7 @@ let load lock_kind gt rt switch =
OpamPackage.Set.empty
) in
(* depext check *)
let available_packages = OpamCompat.Lazy.map fst available_packages in
let sys_packages =
if not (OpamFile.Config.depext gt.config)
|| OpamStateConfig.(!r.no_depexts) then
Expand Down
17 changes: 17 additions & 0 deletions tests/reftests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,23 @@
%{targets}
(run ./run.exe %{bin:opam} %{dep:upgrade-format.test} %{read-lines:testing-env}))))

(alias
(name reftest-upgrade-two-point-o)
(action
(diff upgrade-two-point-o.test upgrade-two-point-o.out)))

(alias
(name reftest)
(deps (alias reftest-upgrade-two-point-o)))

(rule
(targets upgrade-two-point-o.out)
(deps root-N0REP0)
(action
(with-stdout-to
%{targets}
(run ./run.exe %{bin:opam} %{dep:upgrade-two-point-o.test} %{read-lines:testing-env}))))

(alias
(name reftest-var-option)
(action
Expand Down
40 changes: 40 additions & 0 deletions tests/reftests/upgrade-two-point-o.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
N0REP0
### <pkg:i-am-compiler.1>
opam-version: "2.0"
flags: compiler
### <pkg:i-am-compiler.2>
opam-version: "2.0"
flags: compiler
### OPAMYES=1
### <OPAM/config>
opam-version: "2.0"
repositories: "default"
installed-switches: ["pinned-comp"]
switch: "pinned-comp"
default-compiler: ["i-am-compiler"]
### <OPAM/pinned-comp/.opam-switch/switch-state>
opam-version: "2.0"
compiler: ["i-am-compiler.1"]
roots: ["i-am-compiler.1"]
installed: ["i-am-compiler.1"]
pinned: ["i-am-compiler.1"]
### <OPAM/pinned-comp/.opam-switch/switch-config>
opam-version: "2.0"
synopsis: "switch with pinned compiler"
### OPAMDEBUGSECTIONS=STATE opam upgrade --show-action --debug-level=-1
STATE LOAD-SWITCH-STATE @ pinned-comp
STATE Definition missing for installed package i-am-compiler.1, copying from repo
STATE Inferred invariant: from base packages { i-am-compiler.1 }, (roots { i-am-compiler.1 }) => ["i-am-compiler" {= "1"}]
STATE Switch state loaded in 0.000s
STATE Detected changed packages (marked for reinstall): {}
Everything as up-to-date as possible (run with --verbose to show unavailable upgrades).
However, you may "opam upgrade" these packages explicitly, which will ask permission to downgrade or uninstall the conflicting packages.
Nothing to do.
### opam pin remove i-am-compiler
Ok, i-am-compiler is no longer pinned locally (version 1)
No package build needed.
Nothing to do.
### opam upgrade --show-action
Everything as up-to-date as possible (run with --verbose to show unavailable upgrades).
However, you may "opam upgrade" these packages explicitly, which will ask permission to downgrade or uninstall the conflicting packages.
Nothing to do.