From 8e64aa0990d77f5754f40643663064803f6c0cee Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Fri, 24 Mar 2017 11:04:24 +0000 Subject: [PATCH] Lookup bash in the PATH Closes #36 --- src/action.ml | 14 +++++--------- src/utils.ml | 22 ++++++++++++++-------- src/utils.mli | 11 +++++++---- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/action.ml b/src/action.ml index 50e0092f..551958bb 100644 --- a/src/action.ml +++ b/src/action.ml @@ -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 diff --git a/src/utils.ml b/src/utils.ml index 6935486f..7641f26d 100644 --- a/src/utils.ml +++ b/src/utils.ml @@ -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 = diff --git a/src/utils.mli b/src/utils.mli index 6a1980e6..d37dbb35 100644 --- a/src/utils.mli +++ b/src/utils.mli @@ -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