@@ -775,18 +775,29 @@ let windows_checks ?cygwin_setup ?git_location config =
775
775
| None -> config
776
776
in
777
777
(* Cygwin handling *)
778
+ let is_cygwin cygcheck =
779
+ OpamStd.Sys. is_cygwin_cygcheck
780
+ ~cygbin: (Some OpamFilename. (Dir. to_string (dirname cygcheck)))
781
+ in
782
+ let is_variant cygcheck =
783
+ OpamStd.Sys. is_cygwin_variant_cygcheck
784
+ ~cygbin: (Some OpamFilename. (Dir. to_string (dirname cygcheck)))
785
+ in
786
+ let is_msys2 cygcheck = is_variant cygcheck && not (is_cygwin cygcheck) in
778
787
let success cygcheck =
788
+ let cygbin = OpamFilename. dirname cygcheck in
789
+ let distrib = if is_cygwin cygcheck then " cygwin" else " msys2" in
779
790
let config =
780
791
let os_distribution = OpamVariable. of_string " os-distribution" in
781
792
let update vars =
782
793
OpamFile.Config. with_global_variables
783
- ((os_distribution, S " cygwin " , " Set by opam init" )::vars)
794
+ ((os_distribution, S distrib , " Set by opam init" )::vars)
784
795
config
785
796
in
786
797
match OpamStd.List. pick (fun (v ,_ ,_ ) ->
787
798
OpamVariable. equal v os_distribution)
788
799
vars with
789
- | Some (_ , S "cygwin" , _ ), _ -> config
800
+ | Some (_ , S d , _ ), _ when String. equal d distrib -> config
790
801
| None , vars -> update vars
791
802
| Some (_ , vc , _ ), vars ->
792
803
OpamConsole. warning
@@ -802,17 +813,41 @@ let windows_checks ?cygwin_setup ?git_location config =
802
813
OpamStd.Sys. exit_because `Aborted
803
814
in
804
815
let config =
805
- OpamFile.Config. with_sys_pkg_manager_cmd
806
- (OpamStd.String.Map. add " cygwin" cygcheck
807
- (OpamFile.Config. sys_pkg_manager_cmd config))
808
- config
816
+ if is_msys2 cygcheck then
817
+ let env =
818
+ OpamStd.Env. cyg_env ~cygbin: (OpamFilename.Dir. to_string cygbin)
819
+ ~git_location: None
820
+ in
821
+ match OpamSystem. resolve_command ~env " pacman.exe" with
822
+ | Some pacman ->
823
+ if OpamConsole. confirm
824
+ " Found package manager pacman binary at %s.\n \
825
+ Do you want to use it for depexts?"
826
+ pacman then
827
+ OpamFile.Config. with_sys_pkg_manager_cmd
828
+ (OpamStd.String.Map. add distrib (OpamFilename. of_string pacman)
829
+ (OpamFile.Config. sys_pkg_manager_cmd config))
830
+ config
831
+ else config
832
+ | None -> config
833
+ else
834
+ OpamFile.Config. with_sys_pkg_manager_cmd
835
+ (OpamStd.String.Map. add distrib cygcheck
836
+ (OpamFile.Config. sys_pkg_manager_cmd config))
837
+ config
809
838
in
810
839
OpamConsole. note " Configured with %s for depexts"
811
- (if OpamSysInteract.Cygwin. is_internal config then
812
- " internal Cygwin install"
840
+ (if is_cygwin cygcheck then
841
+ if OpamSysInteract.Cygwin. is_internal config then
842
+ " internal Cygwin install"
843
+ else
844
+ (* cygcheck is in CYGWINROOT/bin *)
845
+ Printf. sprintf " Cygwin at %s"
846
+ OpamFilename. (Dir. to_string (dirname_dir cygbin))
813
847
else
814
- Printf. sprintf " Cygwin at %s"
815
- OpamFilename. (Dir. to_string (dirname_dir (dirname cygcheck))));
848
+ (* cygcheck is in MSYS2ROOT/usr/bin *)
849
+ Printf. sprintf " MSYS2 at %s"
850
+ OpamFilename. (Dir. to_string (dirname_dir (dirname_dir cygbin))));
816
851
config
817
852
in
818
853
let install_cygwin_tools () =
@@ -826,12 +861,10 @@ let windows_checks ?cygwin_setup ?git_location config =
826
861
OpamSysInteract.Cygwin. install ~packages
827
862
in
828
863
let header () = OpamConsole. header_msg " Unix support infrastructure" in
864
+
829
865
let get_cygwin = function
830
- | Some cygcheck
831
- when OpamFilename. exists cygcheck
832
- && OpamStd.Sys. is_cygwin_cygcheck
833
- ~cygbin: (Some OpamFilename. (Dir. to_string (dirname cygcheck))) ->
834
- success cygcheck
866
+ | Some cygcheck when OpamFilename. exists cygcheck && is_variant cygcheck ->
867
+ success cygcheck
835
868
| Some _ | None ->
836
869
let rec menu () =
837
870
let enter_paths () =
@@ -862,7 +895,8 @@ let windows_checks ?cygwin_setup ?git_location config =
862
895
in
863
896
(* Check for default cygwin installation path *)
864
897
let default =
865
- match OpamSysInteract.Cygwin. (check_install default_cygroot) with
898
+ match OpamSysInteract.Cygwin. (check_install
899
+ ~variant: true default_cygroot) with
866
900
| Ok cygcheck ->
867
901
let prompt_cygroot () =
868
902
let options = [
@@ -894,7 +928,7 @@ let windows_checks ?cygwin_setup ?git_location config =
894
928
| None -> None
895
929
| Some entry ->
896
930
let cygcheck =
897
- OpamSysInteract.Cygwin. check_install entry
931
+ OpamSysInteract.Cygwin. check_install ~variant: true entry
898
932
in
899
933
match cygcheck with
900
934
| Ok cygcheck -> Some cygcheck
@@ -903,7 +937,8 @@ let windows_checks ?cygwin_setup ?git_location config =
903
937
(* And finally ask for setup.exe *)
904
938
match cygcheck with
905
939
| Some cygcheck ->
906
- OpamSysInteract.Cygwin. check_setup (enter_setup () );
940
+ if is_cygwin cygcheck then
941
+ OpamSysInteract.Cygwin. check_setup (enter_setup () );
907
942
Some (success cygcheck)
908
943
| None -> None
909
944
in
@@ -967,31 +1002,34 @@ let windows_checks ?cygwin_setup ?git_location config =
967
1002
| `default_location -> OpamSysInteract.Cygwin. default_cygroot
968
1003
| `location dir -> OpamFilename.Dir. to_string dir
969
1004
in
970
- (match OpamSysInteract.Cygwin. check_install cygroot with
971
- | Ok cygcheck -> cygcheck
972
- | Error msg ->
973
- OpamConsole. error_and_exit `Not_found
974
- " Error while checking %sCygwin install (%s): %s"
975
- (match setup with
976
- | `default_location -> " default"
977
- | `location _ -> " " )
978
- (OpamSysInteract.Cygwin. default_cygroot) msg)
1005
+ (match OpamSysInteract.Cygwin. check_install ~variant: true
1006
+ cygroot with
1007
+ | Ok cygcheck -> cygcheck
1008
+ | Error msg ->
1009
+ OpamConsole. error_and_exit `Not_found
1010
+ " Error while checking %sCygwin install (%s): %s"
1011
+ (match setup with
1012
+ | `default_location -> " default"
1013
+ | `location _ -> " " )
1014
+ (OpamSysInteract.Cygwin. default_cygroot) msg)
979
1015
in
980
- OpamSysInteract.Cygwin. check_setup None ;
1016
+ if is_cygwin cygcheck then
1017
+ OpamSysInteract.Cygwin. check_setup None ;
981
1018
success cygcheck)
982
- | Some "cygwin" ->
1019
+ | Some "cygwin" | Some "msys2" ->
983
1020
(* We check that current install is good *)
984
1021
(match OpamSysInteract.Cygwin. cygroot_opt config with
985
1022
| Some cygroot ->
986
- (match OpamSysInteract.Cygwin. check_install
1023
+ (match OpamSysInteract.Cygwin. check_install ~variant: true
987
1024
(OpamFilename.Dir. to_string cygroot) with
988
1025
| Ok cygcheck ->
989
1026
OpamSysInteract.Cygwin. check_setup None ;
990
1027
success cygcheck
991
1028
| Error err -> OpamConsole. error " %s" err; get_cygwin None )
992
1029
| None ->
993
- (* Cygwin is detected from environment (path), we check the install
994
- in that case and stores it in config *)
1030
+ (* A Cygwin install (Cygwin or MSYS2) is detected from environment
1031
+ (path), we check the install in that case and stores it in
1032
+ config *)
995
1033
OpamSystem. resolve_command " cygcheck"
996
1034
|> OpamStd.Option. map OpamFilename. of_string
997
1035
|> get_cygwin
@@ -1000,9 +1038,18 @@ let windows_checks ?cygwin_setup ?git_location config =
1000
1038
else
1001
1039
config
1002
1040
in
1003
- let cygbin = OpamStd.Option.Op. (
1004
- OpamSysInteract.Cygwin. cygbin_opt config
1005
- >> | OpamFilename.Dir. to_string)
1041
+ let cygbin =
1042
+ match OpamSysInteract.Cygwin. cygbin_opt config with
1043
+ | Some cygbin -> Some (OpamFilename.Dir. to_string cygbin)
1044
+ | None ->
1045
+ if List. exists (function
1046
+ | (v , S "msys2" , _ ) ->
1047
+ String. equal (OpamVariable. to_string v) " os-distribution"
1048
+ | _ -> false ) (OpamFile.Config. global_variables config)
1049
+ then
1050
+ OpamStd.Option. map Filename. dirname
1051
+ (OpamSystem. resolve_command " cygcheck" )
1052
+ else None
1006
1053
in
1007
1054
OpamCoreConfig. update ?cygbin () ;
1008
1055
config
0 commit comments