Skip to content

Commit 623a549

Browse files
committed
Reset the "jobs" config variable when upgrading from opam 2.0
1 parent 6eeffc7 commit 623a549

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

master_changes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ users)
7878
* Really install invariant formula if not installed in switch [#5188 @rjbou]
7979
* On import, check that installed pinned packages changed, reinstall if so [#5181 @rjbou - fix #5173]
8080

81+
## Config
82+
* Reset the "jobs" config variable when upgrading from opam 2.0 [#5284 @kit-ty-kate]
83+
8184
## Pin
8285
* Switch the default version when undefined from ~dev to dev [#4949 @kit-ty-kate]
8386
* ◈ New option `opam pin --current` to fix a package in its current state (avoiding pending reinstallations or removals from the repository) [#4973 @AltGr - fix #4970]

src/state/opamFormatUpgrade.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,26 @@ let from_2_1_alpha2_to_v2_1_rc root conf =
10741074

10751075
let from_2_1_rc_to_v2_1 _ conf = conf
10761076

1077-
let from_2_0_to_v2_1 _ conf = conf
1077+
let from_2_0_to_v2_1 _ conf =
1078+
(* In opam < 2.1 "jobs" was set during initialisation
1079+
This creates problems when upgrading from opam 2.0 as it
1080+
sets the job count for good even if the CPU is replaced.
1081+
See https://github.com/ocurrent/ocaml-dockerfile/pull/92 *)
1082+
let info_jobs_changed ~prev_jobs =
1083+
OpamConsole.note
1084+
"The 'jobs' option was reset, its value was %d and its new value \
1085+
will vary according to the current number of cores on your machine. \
1086+
If it really was intended, you can set it again using:\n \
1087+
opam option jobs=%d --global" prev_jobs prev_jobs;
1088+
in
1089+
(* We print a note in case the previous value of 'jobs' does not
1090+
match the default in opam 2.0 as we can't determine if the value
1091+
was modified or if the hardware changed. *)
1092+
(match OpamFile.Config.jobs conf with
1093+
| Some prev_jobs when prev_jobs = max 1 (OpamSysPoll.cores () - 1) -> ()
1094+
| Some prev_jobs -> info_jobs_changed ~prev_jobs
1095+
| None -> info_jobs_changed ~prev_jobs:1);
1096+
OpamFile.Config.with_jobs_opt None conf
10781097

10791098
let latest_version = OpamFile.Config.root_version
10801099

0 commit comments

Comments
 (0)