@@ -691,7 +691,7 @@ let string_of_kind = function
691
691
| `Msys2 -> " MSYS2"
692
692
| `Cygwin -> " Cygwin"
693
693
694
- let git_for_windows kind mechanism cygwin_is_tweakable =
694
+ let git_for_windows kind mechanism ~ interactive ~ cygwin_is_tweakable =
695
695
let resolve_git_in p =
696
696
OpamSystem. resolve_command ~env: [||] (Filename. concat p " git.exe" )
697
697
in
@@ -890,7 +890,7 @@ let git_for_windows kind mechanism cygwin_is_tweakable =
890
890
| None -> false
891
891
| Some git -> is_git_for_windows git
892
892
in
893
- if not git_found && OpamStd.Sys. tty_out then
893
+ if not git_found && interactive && OpamStd.Sys. tty_out then
894
894
(OpamConsole. header_msg " Git" ;
895
895
OpamConsole. msg
896
896
" Cygwin Git is functional but can have credentials issues for private \
@@ -900,8 +900,12 @@ let git_for_windows kind mechanism cygwin_is_tweakable =
900
900
" Git for Windows can be downloaded and installed from \
901
901
https://gitforwindows.org" ]);
902
902
menu () )
903
- else
904
- None , not git_found && cygwin_is_tweakable
903
+ else begin
904
+ let install_via_depext = not git_found && cygwin_is_tweakable in
905
+ if not interactive && install_via_depext then
906
+ OpamConsole. note " opam will add Git to %s" (string_of_kind kind);
907
+ None , install_via_depext
908
+ end
905
909
in
906
910
OpamStd.Option. iter (fun _ ->
907
911
OpamConsole. msg
@@ -1004,10 +1008,10 @@ let cygwin_searches ?first () =
1004
1008
in
1005
1009
seq cygwin_searches
1006
1010
1007
- let rec cygwin_menu ~bypass_checks header =
1011
+ let rec cygwin_menu ~bypass_checks ~ interactive header =
1008
1012
let start = Unix. gettimeofday () in
1009
1013
let test_mechanism (roots , count , mechanisms ) search =
1010
- match test_mechanism ~bypass_checks header search with
1014
+ match test_mechanism ~bypass_checks ~interactive header search with
1011
1015
| Some ((kind , `Root root ) as mechanism ) ->
1012
1016
if OpamFilename.Dir.Set. mem root roots then
1013
1017
roots, count, mechanisms
@@ -1148,20 +1152,31 @@ let rec cygwin_menu ~bypass_checks header =
1148
1152
end
1149
1153
end
1150
1154
in
1151
- Lazy. force header;
1152
- OpamConsole. msg
1153
- " \n \
1154
- opam and the OCaml ecosystem in general require various Unix tools in \
1155
- order to operate correctly. At present, this requires the installation \
1156
- of Cygwin to provide these tools.\n\n " ;
1157
- match OpamConsole. menu " How should opam obtain Unix tools?"
1158
- ~default ~yes: default ~no: default ~options with
1155
+ let result =
1156
+ Lazy. force header;
1157
+ if interactive then begin
1158
+ OpamConsole. msg
1159
+ " \n \
1160
+ opam and the OCaml ecosystem in general require various Unix tools in \
1161
+ order to operate correctly. At present, this requires the installation \
1162
+ of Cygwin to provide these tools.\n\n " ;
1163
+ OpamConsole. menu " How should opam obtain Unix tools?"
1164
+ ~default ~yes: default ~no: default ~options
1165
+ end else
1166
+ default
1167
+ in
1168
+ match result with
1159
1169
| `Chosen (kind , `Internal) ->
1160
1170
assert (kind = `Cygwin );
1171
+ if not interactive then
1172
+ OpamConsole. note " opam will maintain an internal Cygwin installation" ;
1161
1173
Some (kind, `Internal OpamInitDefaults. required_packages_for_cygwin)
1162
1174
| `Chosen (kind , ((`Root _ ) as mechanism )) ->
1163
1175
Some (kind, mechanism)
1164
- | `Chosen ((_ , `Path _ ) as mechanism ) ->
1176
+ | `Chosen ((kind , `Path _ ) as mechanism ) ->
1177
+ if not interactive then
1178
+ OpamConsole. note " opam will use the %s installation found in your Path"
1179
+ (string_of_kind kind);
1165
1180
OpamStd.Option. iter (OpamConsole. warning " %s" ) warn_path;
1166
1181
Some mechanism
1167
1182
| `Specify ->
@@ -1176,11 +1191,11 @@ let rec cygwin_menu ~bypass_checks header =
1176
1191
Some (kind, `Root root)
1177
1192
| Error msg ->
1178
1193
OpamConsole. error " %s" msg;
1179
- cygwin_menu ~bypass_checks header
1194
+ cygwin_menu ~bypass_checks ~interactive header
1180
1195
end
1181
1196
| `Abort -> OpamStd.Sys. exit_because `Aborted
1182
1197
1183
- and test_mechanism ~bypass_checks header = function
1198
+ and test_mechanism ~bypass_checks ~ interactive header = function
1184
1199
| (`Internal _ ) as mechanism -> Some (`Cygwin , mechanism)
1185
1200
| `Path ->
1186
1201
let cygcheck =
@@ -1204,7 +1219,7 @@ and test_mechanism ~bypass_checks header = function
1204
1219
| Error msg ->
1205
1220
OpamConsole. error_and_exit `Not_found " %s" msg
1206
1221
end
1207
- | `Menu -> cygwin_menu ~bypass_checks header
1222
+ | `Menu -> cygwin_menu ~bypass_checks ~interactive header
1208
1223
1209
1224
let string_of_cygwin_setup = function
1210
1225
| `internal pkgs ->
@@ -1268,7 +1283,7 @@ let initialise_msys2 root =
1268
1283
OpamStd.Sys. exit_because `Aborted
1269
1284
1270
1285
let determine_windows_configuration ?cygwin_setup ?git_location
1271
- ~bypass_checks config =
1286
+ ~bypass_checks ~ interactive config =
1272
1287
OpamStd.Option. iter
1273
1288
(log " Cygwin (from CLI): %a" (slog string_of_cygwin_setup)) cygwin_setup;
1274
1289
(* Check whether symlinks can be created. Developer Mode is not the only way
@@ -1379,7 +1394,7 @@ let determine_windows_configuration ?cygwin_setup ?git_location
1379
1394
else
1380
1395
cygwin_setup
1381
1396
in
1382
- let mechanisms, cygwin_tweakable =
1397
+ let mechanisms, cygwin_is_tweakable =
1383
1398
match cygwin_setup with
1384
1399
| Some (`internal packages ) ->
1385
1400
(* git, if needed, will be added later *)
@@ -1407,7 +1422,7 @@ let determine_windows_configuration ?cygwin_setup ?git_location
1407
1422
(* Reduce mechanisms to a single mechanism (which may therefore display a
1408
1423
menu). *)
1409
1424
let kind, mechanism =
1410
- let test_mechanism = test_mechanism ~bypass_checks header in
1425
+ let test_mechanism = test_mechanism ~bypass_checks ~interactive header in
1411
1426
match OpamCompat.Seq. find_map test_mechanism mechanisms with
1412
1427
| Some result -> result
1413
1428
| None ->
@@ -1493,7 +1508,7 @@ let determine_windows_configuration ?cygwin_setup ?git_location
1493
1508
`Internal , pkgs
1494
1509
| (`Root _ | `Path _ ) as mechanism ->
1495
1510
let cygwin_packages =
1496
- if cygwin_tweakable && not OpamStateConfig. (! r.no_depexts) then
1511
+ if cygwin_is_tweakable && not OpamStateConfig. (! r.no_depexts) then
1497
1512
OpamInitDefaults. required_packages_for_cygwin
1498
1513
else
1499
1514
[]
@@ -1503,14 +1518,14 @@ let determine_windows_configuration ?cygwin_setup ?git_location
1503
1518
if git_location = None && not git_determined
1504
1519
&& not have_git_for_windows_in_path then
1505
1520
let git_location, from_cygwin =
1506
- git_for_windows kind mechanism cygwin_tweakable
1521
+ git_for_windows kind mechanism ~interactive ~cygwin_is_tweakable
1507
1522
in
1508
1523
let config =
1509
1524
OpamStd.Option. map_default (apply_git_location config)
1510
1525
config git_location
1511
1526
in
1512
1527
let cygwin_packages =
1513
- if cygwin_tweakable && from_cygwin then
1528
+ if cygwin_is_tweakable && from_cygwin then
1514
1529
OpamSysPkg. of_string " git" :: cygwin_packages
1515
1530
else
1516
1531
cygwin_packages
@@ -1601,7 +1616,7 @@ let reinit ?(init_config=OpamInitDefaults.init_config()) ~interactive
1601
1616
let config, mechanism, system_packages, msys2_check_root =
1602
1617
if Sys. win32 then
1603
1618
determine_windows_configuration ?cygwin_setup ?git_location
1604
- ~bypass_checks config
1619
+ ~bypass_checks ~interactive config
1605
1620
else
1606
1621
config, None , [] , None
1607
1622
in
@@ -1670,7 +1685,7 @@ let setup_redirection target =
1670
1685
OpamStateConfig. update ~root_dir () ;
1671
1686
root_dir
1672
1687
1673
- let get_redirected_root () =
1688
+ let get_redirected_root ~ interactive =
1674
1689
let {contents = {OpamStateConfig. original_root_dir = root; root_from; _}} =
1675
1690
OpamStateConfig. r
1676
1691
in
@@ -1728,9 +1743,19 @@ let get_redirected_root () =
1728
1743
OpamStd.Option. replace check (OpamConsole. read " Root directory for opam: " )
1729
1744
in
1730
1745
let rec menu () =
1731
- match OpamConsole. menu " Where should opam store files?" ~options
1732
- ~default ~yes: default ~no: default with
1746
+ let result =
1747
+ if interactive then
1748
+ OpamConsole. menu " Where should opam store files?" ~options
1749
+ ~default ~yes: default ~no: default
1750
+ else begin
1751
+ default
1752
+ end
1753
+ in
1754
+ match result with
1733
1755
| `Redirect ->
1756
+ if not interactive then
1757
+ OpamConsole. note " opam is storing files in %s"
1758
+ (OpamFilename.Dir. to_string default_redirect_root);
1734
1759
Some None
1735
1760
| `Endure ->
1736
1761
None
@@ -1743,14 +1768,16 @@ let get_redirected_root () =
1743
1768
| `Quit ->
1744
1769
OpamStd.Sys. exit_because `Aborted
1745
1770
in
1746
- OpamConsole. header_msg " opam root file store" ;
1747
- OpamConsole. msg
1748
- " \n \
1749
- %s\n \
1750
- \n \
1751
- Many parts of the OCaml ecosystem do not presently work correctly\n \
1752
- when installed to directories containing spaces. You have been warned!%s\n \
1753
- \n " explanation collision;
1771
+ if interactive then begin
1772
+ OpamConsole. header_msg " opam root file store" ;
1773
+ OpamConsole. msg
1774
+ " \n \
1775
+ %s\n \
1776
+ \n \
1777
+ Many parts of the OCaml ecosystem do not presently work correctly when\n \
1778
+ installed to directories containing spaces. You have been warned!%s\n \
1779
+ \n " explanation collision;
1780
+ end ;
1754
1781
Option. map setup_redirection (menu () )
1755
1782
1756
1783
let init
@@ -1776,7 +1803,7 @@ let init
1776
1803
if root_empty &&
1777
1804
Sys. win32 &&
1778
1805
has_space (OpamFilename.Dir. to_string root) then
1779
- get_redirected_root ()
1806
+ get_redirected_root ~interactive
1780
1807
else
1781
1808
None
1782
1809
in
@@ -1821,7 +1848,7 @@ let init
1821
1848
let config, mechanism, system_packages, msys2_check_root =
1822
1849
if Sys. win32 then
1823
1850
determine_windows_configuration ?cygwin_setup ?git_location
1824
- ~bypass_checks config
1851
+ ~bypass_checks ~interactive config
1825
1852
else
1826
1853
config, None , [] , None
1827
1854
in
0 commit comments