Lookup bash in the PATH

Closes #36
This commit is contained in:
Jeremie Dimino 2017-03-24 11:04:24 +00:00
parent 37b1125f03
commit 8e64aa0990
3 changed files with 26 additions and 21 deletions

View File

@ -307,18 +307,14 @@ module Mini_shexp = struct
Printf.fprintf oc "# 1 %S\n" (Path.to_string fn);
copy_channels ic oc));
return ()
| System cmd -> begin
let path, arg, err =
Utils.system_shell ~needed_to:"interpret (system ...) actions"
| System cmd ->
let path, arg =
Utils.system_shell_exn ~needed_to:"interpret (system ...) actions"
in
match err with
| Some err -> err.fail ()
| None ->
run ~dir ~env ~env_extra ~stdout_to ~stderr_to path [arg; cmd]
end
run ~dir ~env ~env_extra ~stdout_to ~stderr_to path [arg; cmd]
| Bash cmd ->
run ~dir ~env ~env_extra ~stdout_to ~stderr_to
(Path.absolute "/bin/bash")
(Utils.bash_exn ~needed_to:"interpret (bash ...) actions")
["-e"; "-u"; "-o"; "pipefail"; "-c"; cmd]
| Update_file (fn, s) ->
let fn = Path.to_string fn in

View File

@ -1,6 +1,6 @@
open Import
let system_shell =
let system_shell_exn =
let cmd, arg, os =
if Sys.win32 then
("cmd", "/c", "on Windows")
@ -10,14 +10,20 @@ let system_shell =
let bin = lazy (Bin.which cmd) in
fun ~needed_to ->
match Lazy.force bin with
| Some path -> (path, arg, None)
| Some path -> (path, arg)
| None ->
(Path.absolute ("/" ^ cmd),
arg,
Some { fail = fun () ->
die "I need %s to %s but I couldn't find it :(\n\
Who doesn't have %s%s?!"
cmd needed_to cmd os })
die "I need %s to %s but I couldn't find it :(\n\
Who doesn't have %s%s?!"
cmd needed_to cmd os
let bash_exn =
let bin = lazy (Bin.which "bash") in
fun ~needed_to ->
match Lazy.force bin with
| Some path -> path
| None ->
die "I need bash to %s but I couldn't find it :("
needed_to
let signal_name =
let table =

View File

@ -1,10 +1,13 @@
(** Utilities that can't go in [Import] *)
open Import
open! Import
(** Return the absolute path to the shell, the argument to pass it (-c or /c) and a
failure in case the shell can't be found. *)
val system_shell : needed_to:string -> Path.t * string * fail option
(** Return the absolute path to the shell and the argument to pass it (-c or /c). Raise in
case in cannot be found. *)
val system_shell_exn : needed_to:string -> Path.t * string
(** Same as [system_shell_exn] but for bash *)
val bash_exn : needed_to:string -> Path.t
(** Convert a signal number to a name: INT, TERM, ... *)
val signal_name : int -> string