diff --git a/CHANGES b/CHANGES index 03ea68f0c87..fa732979a06 100644 --- a/CHANGES +++ b/CHANGES @@ -6,7 +6,7 @@ are not marked). Those prefixed with "(+)" are new command/option (since 2.1.0: * Set DEBIAN_FRONTEND=noninteractive for unsafe-yes confirmation level [#4735 @dra27 - partially fix #4731] -* Fix 2.1~alpha2 to 2.1 format upgrade with reinit [#4750 @rjbou - fix #4748] +* Fix 2.1~alpha2 to 2.1 format upgrade with reinit [#4750 #4756 @rjbou - fix #4748] * Fix bypass-check handling on reinit [#4750 @rjbou] * fish: fix deprecated redirection syntax `^` [#4736 @vzaliva] * Bump src_exts and fix build compat with Dune 2.9.0 [#4754 @dra27] diff --git a/src/client/opamCliMain.ml b/src/client/opamCliMain.ml index 9eb1218ef32..6d95049bae1 100644 --- a/src/client/opamCliMain.ml +++ b/src/client/opamCliMain.ml @@ -340,14 +340,20 @@ let rec main_catch_all f = Windows anyway. *) else Unix.execvpe cmd args env - | OpamFormatUpgrade.Upgrade_done conf -> + | OpamFormatUpgrade.Upgrade_done (conf, reinit) -> main_catch_all @@ fun () -> OpamConsole.header_msg "Rerunning init and update"; - OpamClient.reinit ~interactive:true ~update_config:false ~bypass_checks:true - conf (OpamStd.Sys.guess_shell_compat ()); - OpamConsole.msg - "Update done, please now retry your command.\n"; - exit (OpamStd.Sys.get_exit_code `Aborted) + (match reinit with + | Some reinit -> + reinit conf; + OpamConsole.msg "Update done.\n"; + exit (OpamStd.Sys.get_exit_code `Success) + | None -> + OpamClient.reinit ~interactive:true ~update_config:false + ~bypass_checks:true conf (OpamStd.Sys.guess_shell_compat ()); + OpamConsole.msg + "Update done, please now retry your command.\n"; + exit (OpamStd.Sys.get_exit_code `Aborted)) | e -> flush stdout; flush stderr; diff --git a/src/client/opamCommands.ml b/src/client/opamCommands.ml index 5a03828526e..7ebfd1aab45 100644 --- a/src/client/opamCommands.ml +++ b/src/client/opamCommands.ml @@ -371,21 +371,26 @@ let init cli = get_init_config ~no_sandboxing ~no_default_config_file:no_config_file ~add_config_file:config_file in + let reinit conf = + OpamClient.reinit ~init_config ~interactive ~dot_profile + ?update_config ?env_hook ?completion ~inplace ~bypass_checks + ~check_sandbox:(not no_sandboxing) + conf shell + in let config = match OpamStateConfig.load ~lock_kind:`Lock_write root with | Some c -> c | exception (OpamPp.Bad_version _ as e) -> - OpamFormatUpgrade.hard_upgrade_from_2_1_intermediates root; + OpamFormatUpgrade.hard_upgrade_from_2_1_intermediates ~reinit root; raise e | None -> OpamFile.Config.empty in - OpamClient.reinit ~init_config ~interactive ~dot_profile - ?update_config ?env_hook ?completion ~inplace ~bypass_checks - ~check_sandbox:(not no_sandboxing) - config shell + reinit config else - (if not interactive && - update_config <> Some true && completion <> Some true && env_hook <> Some true then + (if not interactive + && update_config <> Some true + && completion <> Some true + && env_hook <> Some true then OpamConsole.msg "Opam was already initialised. If you want to set it up again, \ use `--interactive', `--reinit', or choose a different \ diff --git a/src/state/opamFormatUpgrade.ml b/src/state/opamFormatUpgrade.ml index 23409e2c212..dc0afa10b5f 100644 --- a/src/state/opamFormatUpgrade.ml +++ b/src/state/opamFormatUpgrade.ml @@ -17,7 +17,7 @@ open OpamFilename.Op let log fmt = OpamConsole.log "FMT_UPG" fmt let slog = OpamConsole.slog -exception Upgrade_done of OpamFile.Config.t +exception Upgrade_done of OpamFile.Config.t * (OpamFile.Config.t -> unit) option (* - Package and aux functions - *) @@ -1094,7 +1094,7 @@ let remove_missing_switches root conf = in OpamFile.Config.with_installed_switches exists conf, missing -let as_necessary requested_lock global_lock root config = +let as_necessary ?reinit requested_lock global_lock root config = let root_version = match OpamFile.Config.opam_root_version_opt config with | Some v -> v @@ -1237,7 +1237,7 @@ let as_necessary requested_lock global_lock root config = let config = hard config |> light in OpamConsole.msg "Format upgrade done.\n"; (* We need to re run init in case of hard upgrade *) - raise (Upgrade_done config) + raise (Upgrade_done (config, reinit)) else OpamStd.Sys.exit_because `Aborted else @@ -1255,7 +1255,7 @@ let as_necessary requested_lock global_lock root config = OpamConsole.error_and_exit `Locked "Could not acquire lock for performing format upgrade." -let hard_upgrade_from_2_1_intermediates ?global_lock root = +let hard_upgrade_from_2_1_intermediates ?reinit ?global_lock root = let config_f = OpamPath.config root in let opam_root_version = OpamFile.Config.raw_root_version config_f in match opam_root_version with @@ -1290,7 +1290,7 @@ let hard_upgrade_from_2_1_intermediates ?global_lock root = | None -> OpamFilename.flock `Lock_read (OpamPath.lock root) in (* it will trigger only hard upgrades that won't get back *) - ignore @@ as_necessary `Lock_write global_lock root + ignore @@ as_necessary `Lock_write global_lock root ?reinit (OpamFile.Config.with_opam_root_version v2_1_alpha2 config) let opam_file ?(quiet=false) ?filename opam = diff --git a/src/state/opamFormatUpgrade.mli b/src/state/opamFormatUpgrade.mli index 377fc367a8b..48f89f48f16 100644 --- a/src/state/opamFormatUpgrade.mli +++ b/src/state/opamFormatUpgrade.mli @@ -16,8 +16,10 @@ open OpamTypes open OpamStateTypes (** Raised when the opam root has been updated to a newer format, and further - action (opam init/update) is needed. *) -exception Upgrade_done of OpamFile.Config.t + action (opam init/update) is needed. + [Upgrade_done conf reinit] specifies the new config file and a reinit + function to call instead of default (see [OpamCliMain.main_catch_all]). *) +exception Upgrade_done of OpamFile.Config.t * (OpamFile.Config.t -> unit) option (** The latest version of the opam root format, that normal operation of this instance of opam requires *) @@ -32,7 +34,8 @@ val latest_version: OpamVersion.t when it's done raises [Upgrade_done updated_config]. Otherwise, it returns the upgraded or unchanged config file.*) val as_necessary: - 'a lock -> OpamSystem.lock -> dirname -> OpamFile.Config.t -> OpamFile.Config.t + ?reinit:(OpamFile.Config.t -> unit) -> 'a lock -> OpamSystem.lock -> dirname -> + OpamFile.Config.t -> OpamFile.Config.t (* Try to launch a hard upgrade from 2;1 alpha's & beta's root to 2.1~rc one. Raises [Upgrade_done] (catched by main @@ -40,7 +43,8 @@ val as_necessary: It is intend to be called after a config file that error with [OpamPp.Bad_version] *) val hard_upgrade_from_2_1_intermediates: - ?global_lock: OpamSystem.lock -> dirname -> unit + ?reinit:(OpamFile.Config.t -> unit) -> ?global_lock: OpamSystem.lock -> + dirname -> unit (** Converts the opam file format, including rewriting availability conditions based on OCaml-related variables into dependencies. The filename is used to diff --git a/tests/reftests/opamroot-versions.test b/tests/reftests/opamroot-versions.test index 4ad59ad9e71..a8264818e85 100644 --- a/tests/reftests/opamroot-versions.test +++ b/tests/reftests/opamroot-versions.test @@ -1628,8 +1628,7 @@ RSTATE Cache found <><> Updating repositories ><><><><><><><><><><><><><><><><><><><><><><><><><><> [default] no changes from file://${BASEDIR}/default -Update done, please now retry your command. -# Return code 10 # +Update done. ### opam switch --short GSTATE LOAD-GLOBAL-STATE @ ${BASEDIR}/OPAM ${BASEDIR}