From 8d04b4bd26597721c1463f6ab96b705a6caae53b Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 27 Dec 2019 20:26:43 +0000 Subject: [PATCH] Actually run goal code. --- src/eval.ml | 9 ++++++++- src/utils.ml | 25 +++++++++++++++++++++++++ src/utils.mli | 6 ++++++ tests/file2.c | 0 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/file2.c diff --git a/src/eval.ml b/src/eval.ml index daa13b6..9fc6e5c 100644 --- a/src/eval.ml +++ b/src/eval.ml @@ -17,6 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) +open Printf + open Utils let rec evaluate_targets env exprs = @@ -94,7 +96,12 @@ and run_goal env loc name args (params, patterns, deps, code) = | [] -> env | d :: _ -> Ast.Env.add "^" d env in let code = Ast.to_shell_script env loc code in - Printf.printf "running : %s\n" code + printf "%s\n%!" (trim code); + let r = Sys.command code in + if r <> 0 then ( + eprintf "*** goal ‘%s’ failed with exit code %d\n" name r; + exit 1 + ) ); (* Check all targets were updated (else it's an error). *) diff --git a/src/utils.ml b/src/utils.ml index ef11975..235167d 100644 --- a/src/utils.ml +++ b/src/utils.ml @@ -54,3 +54,28 @@ let rec string_find s sub = -1 (* not found *) in loop 0 + +let isspace c = + c = ' ' + (* || c = '\f' *) || c = '\n' || c = '\r' || c = '\t' (* || c = '\v' *) + +let triml ?(test = isspace) str = + let i = ref 0 in + let n = ref (String.length str) in + while !n > 0 && test str.[!i]; do + decr n; + incr i + done; + if !i = 0 then str + else String.sub str !i !n + +let trimr ?(test = isspace) str = + let n = ref (String.length str) in + while !n > 0 && test str.[!n-1]; do + decr n + done; + if !n = String.length str then str + else String.sub str 0 !n + +let trim ?(test = isspace) str = + trimr ~test (triml ~test str) diff --git a/src/utils.mli b/src/utils.mli index 0f61751..cb99fad 100644 --- a/src/utils.mli +++ b/src/utils.mli @@ -28,3 +28,9 @@ val filter_map : ('a -> 'b option) -> 'a list -> 'b list val string_find : string -> string -> int (** [string_find str sub] finds the index of [sub] in [str]. If not found, returns -1. *) + +val isspace : char -> bool +val triml : ?test:(char -> bool) -> string -> string +val trimr : ?test:(char -> bool) -> string -> string +val trim : ?test:(char -> bool) -> string -> string +(** Trim strings at left, right or both. *) diff --git a/tests/file2.c b/tests/file2.c new file mode 100644 index 0000000..e69de29 -- 1.8.3.1