Skip to content

Commit 2934dc4

Browse files
committed
Support Windows Command Processor as a shell
Support cmd as an additional option to --shell. Additionally, use parent_putenv so that opam config env does not have to be run at the end of opam init or after opam switch. Windows Command Processor has no equivalent to .profile - at present, the user must run opam env every time they launch a command prompt. Signed-off-by: David Allsopp <david.allsopp@metastack.com>
1 parent ed44880 commit 2934dc4

File tree

11 files changed

+194
-86
lines changed

11 files changed

+194
-86
lines changed

src/client/opamArg.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,12 +738,13 @@ let installed_roots_flag =
738738
mk_flag ["installed-roots"] "Display only the installed roots."
739739

740740
let shell_opt =
741-
let enum = [
741+
let (enum : (string * OpamTypes.shell) list) = [
742742
"bash",`bash;
743743
"sh",`sh;
744744
"csh",`csh;
745745
"zsh",`zsh;
746746
"fish",`fish;
747+
"cmd",`cmd;
747748
] in
748749
mk_opt ["shell"] "SHELL"
749750
(Printf.sprintf

src/client/opamClient.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,10 @@ let init
599599
else false
600600
in
601601
let advised_deps =
602-
[OpamStateConfig.(Lazy.force !r.makecmd); "m4"; "cc"]
602+
if OpamStd.Sys.(os () = Win32) then
603+
[]
604+
else
605+
[OpamStateConfig.(Lazy.force !r.makecmd); "m4"; "cc"]
603606
in
604607
(match List.filter (not @* check_external_dep) advised_deps with
605608
| [] -> ()

src/client/opamCommands.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,10 @@ let config =
859859
if OpamStateConfig.(!r.current_switch) = None then `Ok () else
860860
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
861861
`Ok (OpamConfigCommand.env st
862-
~csh:(shell=`csh) ~sexp ~fish:(shell=`fish) ~inplace_path)
862+
~cmd:(shell=`cmd) ~csh:(shell=`csh) ~sexp ~fish:(shell=`fish) ~inplace_path)
863863
| Some `revert_env, [] ->
864864
`Ok (OpamConfigCommand.print_eval_env
865-
~csh:(shell=`csh) ~sexp ~fish:(shell=`fish)
865+
~cmd:(shell=`cmd) ~csh:(shell=`csh) ~sexp ~fish:(shell=`fish)
866866
(OpamEnv.add [] []))
867867
| Some `setup, [] ->
868868
let user = all || user in
@@ -885,7 +885,7 @@ let config =
885885
Main options\n\
886886
\ -l, --list %s\n\
887887
\ -a, --all %s\n\
888-
\ --shell=<bash|sh|csh|zsh|fish>\n\
888+
\ --shell=<bash|sh|csh|zsh|fish|cmd>\n\
889889
\ Configure assuming the given shell.\n\
890890
\n\
891891
User configuration\n\
@@ -1150,10 +1150,10 @@ let env =
11501150
if OpamStateConfig.(!r.current_switch) <> None then
11511151
OpamSwitchState.with_ `Lock_none gt @@ fun st ->
11521152
OpamConfigCommand.env st
1153-
~csh:(shell=`csh) ~sexp ~fish:(shell=`fish) ~inplace_path
1153+
~cmd:(shell=`cmd) ~csh:(shell=`csh) ~sexp ~fish:(shell=`fish) ~inplace_path
11541154
| true ->
11551155
OpamConfigCommand.print_eval_env
1156-
~csh:(shell=`csh) ~sexp ~fish:(shell=`fish)
1156+
~cmd:(shell=`cmd) ~csh:(shell=`csh) ~sexp ~fish:(shell=`fish)
11571157
(OpamEnv.add [] [])
11581158
in
11591159
Term.(const env $global_options $shell_opt $sexp $inplace_path $revert),

src/client/opamConfigCommand.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,31 @@ let rec print_fish_env env =
177177
k (OpamStd.Env.escape_single_quotes ~using_backslashes:true v));
178178
print_fish_env r
179179

180-
let print_eval_env ~csh ~sexp ~fish env =
180+
let print_cmd_env env =
181+
List.iter (fun (k, v, _) -> OpamConsole.msg "set %s=%s\n" k v) env
182+
183+
let print_eval_env ~cmd ~csh ~sexp ~fish env =
181184
if sexp then
182185
print_sexp_env env
183186
else if csh then
184187
print_csh_env env
185188
else if fish then
186189
print_fish_env env
190+
else if cmd then
191+
if OpamStd.Sys.tty_out then begin
192+
log "parent-putenv";
193+
OpamEnv.set_cmd_env env
194+
end else begin
195+
log "cmd-stdout";
196+
print_cmd_env env
197+
end
187198
else
188199
print_env env
189200

190-
let env st ~csh ~sexp ~fish ~inplace_path =
201+
let env st ~cmd ~csh ~sexp ~fish ~inplace_path =
191202
log "config-env";
192203
let env = OpamEnv.get_opam ~force_path:(not inplace_path) st in
193-
print_eval_env ~csh ~sexp ~fish env
204+
print_eval_env ~cmd ~csh ~sexp ~fish env
194205

195206
let subst gt fs =
196207
log "config-substitute";

src/client/opamConfigCommand.mli

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
open OpamTypes
1515
open OpamStateTypes
1616

17-
(** Display the current environment. Booleans csh, sexp and fish set an alternative
18-
output (unspecified if more than one is true, sh-style by default).
17+
(** Display the current environment. Booleans cmd, csh, sexp and fish set an
18+
alternative output (unspecified if more than one is true, sh-style by
19+
default).
1920
[inplace_path] changes how the PATH variable is updated when there is already
2021
an opam entry: either at the same rank, or pushed in front. *)
2122
val env:
22-
'a switch_state -> csh:bool -> sexp:bool -> fish:bool -> inplace_path:bool ->
23-
unit
23+
'a switch_state -> cmd:bool -> csh:bool -> sexp:bool -> fish:bool ->
24+
inplace_path:bool -> unit
2425

2526
(** Like [env] but allows to specify the precise env to print rather than
2627
compute it from a switch state *)
27-
val print_eval_env: csh:bool -> sexp:bool -> fish:bool -> env -> unit
28+
val print_eval_env: cmd:bool -> csh:bool -> sexp:bool -> fish:bool -> env -> unit
2829

2930
(** Display the content of all available variables; global summary if the list
3031
is empty, package name "-" is understood as global configuration *)

src/core/opamStd.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,11 @@ module OpamSys = struct
888888
| "zsh" -> `zsh
889889
| "bash" -> `bash
890890
| "fish" -> `fish
891-
| _ -> `sh
891+
| _ ->
892+
if os () = Win32 then
893+
`cmd
894+
else
895+
`sh
892896

893897
let executable_name =
894898
if os () = Win32 then
@@ -902,7 +906,11 @@ module OpamSys = struct
902906

903907
let guess_shell_compat () =
904908
try shell_of_string (Filename.basename (Env.get "SHELL"))
905-
with Not_found -> `sh
909+
with Not_found ->
910+
if os () = Win32 then
911+
`cmd
912+
else
913+
`sh
906914

907915
let guess_dot_profile shell =
908916
let home f =

src/core/opamStd.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,10 @@ module Sys : sig
497497
val executable_name : string -> string
498498

499499
(** Guess the shell compat-mode *)
500-
val guess_shell_compat: unit -> [`csh|`zsh|`sh|`bash|`fish]
500+
val guess_shell_compat: unit -> [`csh|`zsh|`sh|`bash|`fish|`cmd]
501501

502502
(** Guess the location of .profile *)
503-
val guess_dot_profile: [`csh|`zsh|`sh|`bash|`fish] -> string
503+
val guess_dot_profile: [`csh|`zsh|`sh|`bash|`fish|`cmd] -> string
504504

505505
(** The separator character used in the PATH variable (varies depending on
506506
OS) *)

src/format/opamTypes.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ type universe = {
299299
type pin_kind = [ `version | OpamUrl.backend ]
300300

301301
(** Shell compatibility modes *)
302-
type shell = [`fish|`csh|`zsh|`sh|`bash]
302+
type shell = [`fish|`csh|`zsh|`sh|`bash|`cmd]
303303

304304
(** {2 Generic command-line definitions with filters} *)
305305

src/format/opamTypesBase.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let string_of_shell = function
4747
| `zsh -> "zsh"
4848
| `sh -> "sh"
4949
| `bash -> "bash"
50+
| `cmd -> "Windows Command Processor"
5051

5152
let file_null = ""
5253
let pos_file filename = OpamFilename.to_string filename, -1, -1

0 commit comments

Comments
 (0)