2007-02-07 00:59:16 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 07:47:00 -07:00
|
|
|
(* *)
|
2007-02-07 00:59:16 -08:00
|
|
|
(* ocamlbuild *)
|
|
|
|
(* *)
|
|
|
|
(* Nicolas Pouillard, Berke Durak, projet Gallium, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2007 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2009-03-03 08:54:58 -08:00
|
|
|
|
2007-02-07 00:59:16 -08:00
|
|
|
(* Original author: Berke Durak *)
|
2007-11-22 10:34:22 -08:00
|
|
|
(* Ocamlbuild_executor *)
|
2007-02-07 00:59:16 -08:00
|
|
|
|
|
|
|
(** UNIX-specific module for running tasks in parallel and properly multiplexing their outputs. *)
|
|
|
|
|
2007-11-22 10:34:22 -08:00
|
|
|
type error =
|
|
|
|
| Subcommand_failed
|
|
|
|
| Subcommand_got_signal
|
|
|
|
| Io_error
|
|
|
|
| Exceptionl_condition
|
|
|
|
|
|
|
|
(** [execute ~ticker ~period ~display ~exit commands] will execute the commands
|
|
|
|
in [commands] in parallel, correctly multiplexing their outputs.
|
|
|
|
|
2007-11-28 08:11:46 -08:00
|
|
|
A command is a function that given a unit [()] returns the shell command
|
|
|
|
string to execute, commands are functions in order to do some job just
|
|
|
|
before executing the command. These functions will be called once. If
|
|
|
|
specified, it will call [ticker] at least every [period] seconds. If
|
|
|
|
specified, it will call [display f] when it wishes to print something;
|
|
|
|
[display] should then call [f] with then channel on which [f] should
|
|
|
|
print.
|
2007-11-22 10:34:22 -08:00
|
|
|
|
2007-11-28 09:21:59 -08:00
|
|
|
Note that if the shell command to execute is the empty string [""], it's
|
|
|
|
considered as a no-op.
|
|
|
|
|
2007-11-22 10:34:22 -08:00
|
|
|
Note that [f] must be idempotent as it may well be called twice, once for
|
|
|
|
the log file, once for the actual output.
|
|
|
|
|
|
|
|
If one of the commands fails, it will exit with an appropriate error code,
|
2007-02-07 00:59:16 -08:00
|
|
|
calling [cleanup] before.
|
2007-11-22 10:34:22 -08:00
|
|
|
|
|
|
|
All exits are done trough the call to the given [exit] function, if not
|
|
|
|
supplied Pervasives.exit is used.
|
2007-02-07 00:59:16 -08:00
|
|
|
*)
|
|
|
|
val execute :
|
|
|
|
?max_jobs:int ->
|
|
|
|
?ticker:(unit -> unit) ->
|
|
|
|
?period:float ->
|
|
|
|
?display:((out_channel -> unit) -> unit) ->
|
2007-11-22 10:34:22 -08:00
|
|
|
exit:(error -> unit) ->
|
2007-11-28 08:11:46 -08:00
|
|
|
((unit -> string) list list) ->
|
2007-02-07 00:59:16 -08:00
|
|
|
(bool list * exn) option
|