From dd9253e207c1c440de284520b2c6d7599d3b8e1b Mon Sep 17 00:00:00 2001 From: Kate Date: Wed, 14 Sep 2022 20:29:29 +0100 Subject: [PATCH] Reset the "jobs" config variable when upgrading from opam 2.0 --- master_changes.md | 3 +++ src/state/opamFormatUpgrade.ml | 21 ++++++++++++++++++++- tests/reftests/opamroot-versions.test | 22 ++++++++++++++++++++++ tests/reftests/upgrade-two-point-o.test | 6 ++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/master_changes.md b/master_changes.md index 485fc9a31ec..cb9a2d5b87d 100644 --- a/master_changes.md +++ b/master_changes.md @@ -83,6 +83,9 @@ users) * Really install invariant formula if not installed in switch [#5188 @rjbou] * On import, check that installed pinned packages changed, reinstall if so [#5181 @rjbou - fix #5173] +## Config + * Reset the "jobs" config variable when upgrading from opam 2.0 [#5284 @kit-ty-kate] + ## Pin * Switch the default version when undefined from ~dev to dev [#4949 @kit-ty-kate] * ◈ 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] diff --git a/src/state/opamFormatUpgrade.ml b/src/state/opamFormatUpgrade.ml index dc0afa10b5f..a9b05b8a414 100644 --- a/src/state/opamFormatUpgrade.ml +++ b/src/state/opamFormatUpgrade.ml @@ -1074,7 +1074,26 @@ let from_2_1_alpha2_to_v2_1_rc root conf = let from_2_1_rc_to_v2_1 _ conf = conf -let from_2_0_to_v2_1 _ conf = conf +let from_2_0_to_v2_1 _ conf = + (* In opam < 2.1 "jobs" was set during initialisation + This creates problems when upgrading from opam 2.0 as it + sets the job count for good even if the CPU is replaced. + See https://github.com/ocurrent/ocaml-dockerfile/pull/92 *) + let info_jobs_changed ~prev_jobs = + OpamConsole.note + "The 'jobs' option was reset, its value was %d and its new value \ + will vary according to the current number of cores on your machine. \ + If it really was intended, you can set it again using:\n \ + opam option jobs=%d --global" prev_jobs prev_jobs; + in + (* We print a note in case the previous value of 'jobs' does not + match the default in opam 2.0 as we can't determine if the value + was modified or if the hardware changed. *) + (match OpamFile.Config.jobs conf with + | Some prev_jobs when prev_jobs = max 1 (OpamSysPoll.cores () - 1) -> () + | Some prev_jobs -> info_jobs_changed ~prev_jobs + | None -> info_jobs_changed ~prev_jobs:1); + OpamFile.Config.with_jobs_opt None conf let latest_version = OpamFile.Config.root_version diff --git a/tests/reftests/opamroot-versions.test b/tests/reftests/opamroot-versions.test index 9829c6fa4af..0a7d6a61df0 100644 --- a/tests/reftests/opamroot-versions.test +++ b/tests/reftests/opamroot-versions.test @@ -681,11 +681,15 @@ No configuration file found, using built-in defaults. ### opam option jobs | "${OPAMROOTVERSION}$" -> "current" GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM FMT_UPG On-the-fly config upgrade, from 2.0 to current +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global FMT_UPG Format upgrade done ### # ro global state, ro repo state, ro switch state ### opam list | "${OPAMROOTVERSION}$" -> "current" GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM FMT_UPG On-the-fly config upgrade, from 2.0 to current +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global FMT_UPG Format upgrade done RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE No cache found @@ -702,6 +706,8 @@ i-am-sys-compiler 1 One-line description ### opam install i-am-another-package --switch sw-comp | "${OPAMROOTVERSION}$" -> "current" GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM FMT_UPG On-the-fly config upgrade, from 2.0 to current +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global FMT_UPG Format upgrade done RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE Cache found @@ -727,6 +733,8 @@ This version of opam requires an update to the layout of ${BASEDIR}/OPAM from ve You may want to back it up before going further. Continue? [y/n] y +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global Format upgrade done. RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE Cache found @@ -768,6 +776,8 @@ roots: ["i-am-another-package.2" "i-am-compiler.2" "i-am-package.2"] ### opam list | "${OPAMROOTVERSION}$" -> "current" GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM FMT_UPG On-the-fly config upgrade, from 2.0 to current +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global FMT_UPG Format upgrade done RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE No cache found @@ -783,6 +793,8 @@ i-am-sys-compiler 2 One-line description ### opam install i-am-package | "${OPAMROOTVERSION}$" -> "current" GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM FMT_UPG On-the-fly config upgrade, from 2.0 to current +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global FMT_UPG Format upgrade done RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE Cache found @@ -807,6 +819,8 @@ This version of opam requires an update to the layout of ${BASEDIR}/OPAM from ve You may want to back it up before going further. Continue? [y/n] y +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global Format upgrade done. Set to '4' the field jobs in global configuration ### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" @@ -848,6 +862,8 @@ roots: ["i-am-package.2" "i-am-sys-compiler.2"] ### opam list | "${OPAMROOTVERSION}$" -> " current" GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM FMT_UPG On-the-fly config upgrade, from 2.0 to current +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global FMT_UPG Format upgrade done RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE No cache found @@ -862,6 +878,8 @@ i-am-sys-compiler 2 One-line description ### opam install i-am-package | "${OPAMROOTVERSION}$" -> "current" GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM FMT_UPG On-the-fly config upgrade, from 2.0 to current +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global FMT_UPG Format upgrade done RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE Cache found @@ -886,6 +904,8 @@ This version of opam requires an update to the layout of ${BASEDIR}/OPAM from ve You may want to back it up before going further. Continue? [y/n] y +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global Format upgrade done. Set to '4' the field jobs in global configuration ### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" @@ -998,6 +1018,8 @@ This version of opam requires an update to the layout of ${BASEDIR}/OPAM from ve You may want to back it up before going further. Continue? [y/n] y +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global Format upgrade done. RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM RSTATE No cache found diff --git a/tests/reftests/upgrade-two-point-o.test b/tests/reftests/upgrade-two-point-o.test index 8ebc765ee46..3c6b6ce3e82 100644 --- a/tests/reftests/upgrade-two-point-o.test +++ b/tests/reftests/upgrade-two-point-o.test @@ -22,6 +22,8 @@ pinned: ["i-am-compiler.1"] opam-version: "2.0" synopsis: "switch with pinned compiler" ### OPAMDEBUGSECTIONS=STATE opam upgrade --show-action --debug-level=-1 +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global 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"}] @@ -31,9 +33,13 @@ Everything as up-to-date as possible (run with --verbose to show unavailable upg 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 +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global Ok, i-am-compiler is no longer pinned locally (version 1) Nothing to do. ### opam upgrade --show-action +[NOTE] The 'jobs' option was reset, its value was 1 and its new value will vary according to the current number of cores on your machine. If it really was intended, you can set it again using: + opam option jobs=1 --global 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.