- assert (tactic = "file");
- assert (List.length targs = 1);
- let targ = List.hd targs in
- not (Sys.file_exists targ)
+ let env =
+ let params =
+ try List.combine params targs
+ with Invalid_argument _ ->
+ failwithf "%a: calling tactic ‘%s’ with wrong number of arguments"
+ Ast.string_loc loc tactic in
+ List.fold_left (fun env (k, v) -> Ast.Env.add k v env) env params in
+
+ (* Add some standard variables to the environment. *)
+ let env = Ast.Env.add "<" (Ast.EList (Ast.noloc, deps)) env in
+ let env =
+ match deps with
+ | [] -> env
+ | d :: _ -> Ast.Env.add "^" d env in
+ let code = Ast.to_shell_script env loc code in
+ let code = "set -e\nset -x\n\n" ^ code in
+ let r = Sys.command code in
+ if r = 99 (* means "needs rebuild" *) then true
+ else if r = 0 (* means "doesn't need rebuild" *) then false
+ else (
+ eprintf "*** tactic ‘%s’ failed with exit code %d\n" tactic r;
+ exit 1
+ )