diff --git a/master_changes.md b/master_changes.md index 53af43ebbaf..faede2280ab 100644 --- a/master_changes.md +++ b/master_changes.md @@ -134,6 +134,7 @@ users) ## opam-client * `OpamClient.windows_checks`: On existing cygwin install, permit to detect msys2 and store `os-distribution=msys2` in `global-variables` config file field [#5843 @rjbou] * `OpamClient.windows_checks`: When updating config file for msys2, resolve `pacman` path and store it in `sys-pkg-manager-cmd` for msys2 [#5843 @rjbou] + * `OpamArg.apply_global_options`: load MSYS2 Cygwin binary path too [#5843 @rjbou] ## opam-repository @@ -141,6 +142,7 @@ users) * `OpamEnv.env_expansion`: Fix detection of out-of-date environment variables, a filter predicate was inverted [#5837 @dra27] * `OpamSysInteract.Cygwin.check_install`: add `variant` argument to permit checking that it is an Cygwin-like install if it is set to true, keep checking that it is a strictly Cygwin install if false [#5843 @rjbou] * `OpamSysInteract.Cygwin.check_install`: look for `cygcheck.exe` in `usr/bin` also as MSYS2 doesn't have "bin" [#5843 @rjbou] + * `OpamGlobalState.load_config`: load MSYS2 Cygwin binary path too at config file loading [#5843 @rjbou] ## opam-solver diff --git a/src/client/opamArg.ml b/src/client/opamArg.ml index b37db85f2cc..c43ff1f6382 100644 --- a/src/client/opamArg.ml +++ b/src/client/opamArg.ml @@ -600,6 +600,21 @@ let apply_global_options cli o = | _, element::elements -> aux (Some element) elements in aux None elements + | { pelem = Variable ({ pelem = "global-variables"; _}, + {pelem = List { pelem = elements; _}; _}); _} -> + let rec aux last elements = + match last, elements with + | _, [] -> () + | Some { pelem = Ident "os-distribution"; _}, + { pelem = String "msys2"; _}::_ -> + let cygbin = + OpamStd.Option.map Filename.dirname + (OpamSystem.resolve_command "cygcheck") + in + OpamCoreConfig.update ?cygbin () + | _, element::elements -> aux (Some element) elements + in + aux None elements | { pelem = Variable ({ pelem = "git-location"; _}, {pelem = String git_location; _}); _} -> OpamCoreConfig.update ~git_location () diff --git a/src/state/opamGlobalState.ml b/src/state/opamGlobalState.ml index 811d20da2e1..b8140765dea 100644 --- a/src/state/opamGlobalState.ml +++ b/src/state/opamGlobalState.ml @@ -38,10 +38,22 @@ let load_config lock_kind global_lock root = let config = OpamFormatUpgrade.as_necessary lock_kind global_lock root config in - OpamStd.Option.iter - (fun cygbin -> - OpamCoreConfig.update ~cygbin:(OpamFilename.Dir.to_string cygbin) ()) - (OpamSysInteract.Cygwin.cygbin_opt (fst config)); + (* Update Cygwin variants cygbin *) + let cygbin = + let config = fst config in + match OpamSysInteract.Cygwin.cygbin_opt config with + | Some cygbin -> Some (OpamFilename.Dir.to_string cygbin) + | None -> + if List.exists (function + | (v, S "msys2", _) -> + String.equal (OpamVariable.to_string v) "os-distribution" + | _ -> false) (OpamFile.Config.global_variables config) + then + OpamStd.Option.map Filename.dirname + (OpamSystem.resolve_command "cygcheck") + else None + in + OpamCoreConfig.update ?cygbin (); config let inferred_from_system = "Inferred from system"