Skip to content

Commit 44c74ba

Browse files
committed
state,arg: load MSYS2 Cygwin binary path in 'OpamCoreConfig.cygbin'
If MSYS2 is detected via 'os-distribution' in the config file, resolve 'cygcheck' from the environment and store resulting value as Cygwin binary path in 'OpamCoreConfig.cygbin'
1 parent 61bc20f commit 44c74ba

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

master_changes.md

+2
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@ users)
134134
## opam-client
135135
* `OpamClient.windows_checks`: On existing cygwin install, permit to detect msys2 and store `os-distribution=msys2` in `global-variables` config file field [#5843 @rjbou]
136136
* `OpamClient.windows_checks`: When updating config file for msys2, resolve `pacman` path and store it in `sys-pkg-manager-cmd` for msys2 [#5843 @rjbou]
137+
* `OpamArg.apply_global_options`: load MSYS2 Cygwin binary path too [#5843 @rjbou]
137138

138139
## opam-repository
139140

140141
## opam-state
141142
* `OpamEnv.env_expansion`: Fix detection of out-of-date environment variables, a filter predicate was inverted [#5837 @dra27]
142143
* `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]
143144
* `OpamSysInteract.Cygwin.check_install`: look for `cygcheck.exe` in `usr/bin` also as MSYS2 doesn't have "bin" [#5843 @rjbou]
145+
* `OpamGlobalState.load_config`: load MSYS2 Cygwin binary path too at config file loading [#5843 @rjbou]
144146

145147
## opam-solver
146148

src/client/opamArg.ml

+15
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,21 @@ let apply_global_options cli o =
600600
| _, element::elements -> aux (Some element) elements
601601
in
602602
aux None elements
603+
| { pelem = Variable ({ pelem = "global-variables"; _},
604+
{pelem = List { pelem = elements; _}; _}); _} ->
605+
let rec aux last elements =
606+
match last, elements with
607+
| _, [] -> ()
608+
| Some { pelem = Ident "os-distribution"; _},
609+
{ pelem = String "msys2"; _}::_ ->
610+
let cygbin =
611+
OpamStd.Option.map Filename.dirname
612+
(OpamSystem.resolve_command "cygcheck")
613+
in
614+
OpamCoreConfig.update ?cygbin ()
615+
| _, element::elements -> aux (Some element) elements
616+
in
617+
aux None elements
603618
| { pelem = Variable ({ pelem = "git-location"; _},
604619
{pelem = String git_location; _}); _} ->
605620
OpamCoreConfig.update ~git_location ()

src/state/opamGlobalState.ml

+16-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,22 @@ let load_config lock_kind global_lock root =
3838
let config =
3939
OpamFormatUpgrade.as_necessary lock_kind global_lock root config
4040
in
41-
OpamStd.Option.iter
42-
(fun cygbin ->
43-
OpamCoreConfig.update ~cygbin:(OpamFilename.Dir.to_string cygbin) ())
44-
(OpamSysInteract.Cygwin.cygbin_opt (fst config));
41+
(* Update Cygwin variants cygbin *)
42+
let cygbin =
43+
let config = fst config in
44+
match OpamSysInteract.Cygwin.cygbin_opt config with
45+
| Some cygbin -> Some (OpamFilename.Dir.to_string cygbin)
46+
| None ->
47+
if List.exists (function
48+
| (v, S "msys2", _) ->
49+
String.equal (OpamVariable.to_string v) "os-distribution"
50+
| _ -> false) (OpamFile.Config.global_variables config)
51+
then
52+
OpamStd.Option.map Filename.dirname
53+
(OpamSystem.resolve_command "cygcheck")
54+
else None
55+
in
56+
OpamCoreConfig.update ?cygbin ();
4557
config
4658

4759
let inferred_from_system = "Inferred from system"

0 commit comments

Comments
 (0)