Skip to content

Commit

Permalink
Reset the "jobs" config variable when upgrading to opam 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed May 7, 2024
1 parent d428725 commit e26260c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ users)
## External dependencies

## Format upgrade
* Handle init OCaml `sys-ocaml-*` eval variables during format upgrade from 2.0 -> 2.1 -> 2.2 [#5829 @dra27]
* Reset the "jobs" config variable when upgrading from opam 2.1 to 2.2, instead of 2.0 to 2.1 [#5904 @kit-ty-kate - fix #5816]

## Sandbox

Expand Down
24 changes: 12 additions & 12 deletions src/state/opamFormatUpgrade.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,18 @@ let sys_config_variables_unix_2_1 = [
"Host C Runtime Library type of the OCaml compiler present on your system";
]

let from_2_0_to_2_1 ~on_the_fly _ conf =
let from_2_0_to_2_1 ~on_the_fly:_ _ conf =
apply_eval_variables conf [] sys_config_variables_unix_2_1, gtc_none

let v2_2_alpha = OpamVersion.of_string "2.2~alpha"

let from_2_1_to_2_2_alpha ~on_the_fly:_ _ conf =
apply_eval_variables conf sys_config_variables_unix_2_1
OpamEnv.sys_ocaml_eval_variables, gtc_none

let v2_2_beta = OpamVersion.of_string "2.2~beta"

let from_2_2_alpha_to_2_2_beta ~on_the_fly _ 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.
Expand All @@ -1130,19 +1141,8 @@ let from_2_0_to_2_1 ~on_the_fly _ conf =
| 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);
let conf = apply_eval_variables conf [] sys_config_variables_unix_2_1 in
OpamFile.Config.with_jobs_opt None conf, gtc_none

let v2_2_alpha = OpamVersion.of_string "2.2~alpha"

let from_2_1_to_2_2_alpha ~on_the_fly:_ _ conf =
apply_eval_variables conf sys_config_variables_unix_2_1
OpamEnv.sys_ocaml_eval_variables, gtc_none

let v2_2_beta = OpamVersion.of_string "2.2~beta"

let from_2_2_alpha_to_2_2_beta ~on_the_fly:_ _ conf = conf, gtc_none

(* To add an upgrade layer
* If it is a light upgrade, returns as second element if the repo or switch
need an light upgrade with `gtc_*` values.
Expand Down
2 changes: 2 additions & 0 deletions tests/reftests/init-ocaml-eval-variables.unix.test
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | grep eval-variables
Expand Down
2 changes: 2 additions & 0 deletions tests/reftests/init-ocaml-eval-variables.win32.test
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | grep eval-variables
Expand Down
42 changes: 42 additions & 0 deletions tests/reftests/opamroot-versions.test
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1151,6 +1153,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1224,6 +1228,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1364,6 +1370,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1422,6 +1430,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1513,6 +1523,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1588,6 +1600,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1729,6 +1743,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.

Perform the update and 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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><><><><><><><><>
Expand Down Expand Up @@ -1822,6 +1838,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables | grep -v eval-variables:
Expand Down Expand Up @@ -1892,6 +1910,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables | grep -v eval-variables:
Expand Down Expand Up @@ -1964,6 +1984,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables | grep -v eval-variables:
Expand Down Expand Up @@ -2065,6 +2087,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM
RSTATE No cache found
Expand Down Expand Up @@ -2165,6 +2189,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables | grep -v eval-variables:
Expand Down Expand Up @@ -2234,6 +2260,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables | grep -v eval-variables:
Expand Down Expand Up @@ -2305,6 +2333,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables | grep -v eval-variables:
Expand Down Expand Up @@ -2376,6 +2406,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables | grep -v eval-variables:
Expand Down Expand Up @@ -2416,6 +2448,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
RSTATE LOAD-REPOSITORY-STATE @ ${BASEDIR}/OPAM
RSTATE No cache found
Expand Down Expand Up @@ -2516,6 +2550,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables
Expand Down Expand Up @@ -2587,6 +2623,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables
Expand Down Expand Up @@ -2658,6 +2696,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables
Expand Down Expand Up @@ -2730,6 +2770,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. You can restore the fixed value using:
opam option jobs=1 --global
Format upgrade done.
Set to '4' the field jobs in global configuration
### opam-cat $OPAMROOT/config | '"${OPAMROOTVERSION}"' -> "current" | grep -v sys-pkg-manager-cmd | grep -v global-variables
Expand Down

0 comments on commit e26260c

Please sign in to comment.