2018-02-06 14:39:03 +00:00
|
|
|
(** Running external programs *)
|
2016-11-03 16:44:09 +00:00
|
|
|
|
2017-02-27 11:37:28 +00:00
|
|
|
open Import
|
|
|
|
|
2017-03-20 14:34:28 +00:00
|
|
|
type accepted_codes =
|
|
|
|
| These of int list
|
|
|
|
| All
|
|
|
|
|
2017-02-27 11:37:28 +00:00
|
|
|
(** How to handle sub-process failures *)
|
|
|
|
type ('a, 'b) failure_mode =
|
|
|
|
| Strict : ('a, 'a) failure_mode
|
|
|
|
(** Fail if the process exits with anything else than [0] *)
|
2017-03-20 14:34:28 +00:00
|
|
|
| Accept : accepted_codes -> ('a, ('a, int) result) failure_mode
|
2018-02-06 14:39:03 +00:00
|
|
|
(** Accept the following non-zero exit codes, and return [Error
|
|
|
|
code] if the process exists with one of these codes. *)
|
2017-02-27 11:37:28 +00:00
|
|
|
|
2017-02-27 14:15:30 +00:00
|
|
|
(** Where to redirect standard output *)
|
2017-03-13 08:10:33 +00:00
|
|
|
type std_output_to =
|
2017-02-27 14:15:30 +00:00
|
|
|
| Terminal
|
2018-04-25 09:33:25 +00:00
|
|
|
| File of Path.t
|
2017-02-27 14:15:30 +00:00
|
|
|
| Opened_file of opened_file
|
|
|
|
|
|
|
|
and opened_file =
|
2018-04-25 09:33:25 +00:00
|
|
|
{ filename : Path.t
|
2017-02-27 14:15:30 +00:00
|
|
|
; desc : opened_file_desc
|
|
|
|
; tail : bool
|
|
|
|
(** If [true], the descriptor is closed after starting the command *)
|
|
|
|
}
|
|
|
|
|
|
|
|
and opened_file_desc =
|
|
|
|
| Fd of Unix.file_descr
|
|
|
|
| Channel of out_channel
|
|
|
|
|
2018-02-06 14:39:03 +00:00
|
|
|
(** Why a Fiber.t was run *)
|
2017-03-30 16:36:58 +00:00
|
|
|
type purpose =
|
|
|
|
| Internal_job
|
2018-05-23 16:47:56 +00:00
|
|
|
| Build_job of Path.Set.t
|
2017-03-30 16:36:58 +00:00
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
(** [run ?dir ?stdout_to prog args] spawns a sub-process and wait for its termination *)
|
|
|
|
val run
|
2018-04-25 06:25:07 +00:00
|
|
|
: ?dir:Path.t
|
2017-03-13 08:10:33 +00:00
|
|
|
-> ?stdout_to:std_output_to
|
|
|
|
-> ?stderr_to:std_output_to
|
2018-03-29 15:58:41 +00:00
|
|
|
-> env:Env.t
|
2017-03-30 16:36:58 +00:00
|
|
|
-> ?purpose:purpose
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (unit, 'a) failure_mode
|
2018-04-25 09:30:18 +00:00
|
|
|
-> Path.t
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string list
|
2018-02-06 14:39:03 +00:00
|
|
|
-> 'a Fiber.t
|
2016-12-02 13:54:32 +00:00
|
|
|
|
|
|
|
(** Run a command and capture its output *)
|
|
|
|
val run_capture
|
2018-04-25 06:25:07 +00:00
|
|
|
: ?dir:Path.t
|
2018-03-29 15:58:41 +00:00
|
|
|
-> env:Env.t
|
2017-03-30 16:36:58 +00:00
|
|
|
-> ?purpose:purpose
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (string, 'a) failure_mode
|
2018-04-25 09:30:18 +00:00
|
|
|
-> Path.t
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string list
|
2018-02-06 14:39:03 +00:00
|
|
|
-> 'a Fiber.t
|
2016-12-02 13:54:32 +00:00
|
|
|
val run_capture_line
|
2018-04-25 06:25:07 +00:00
|
|
|
: ?dir:Path.t
|
2018-03-29 15:58:41 +00:00
|
|
|
-> env:Env.t
|
2017-03-30 16:36:58 +00:00
|
|
|
-> ?purpose:purpose
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (string, 'a) failure_mode
|
2018-04-25 09:30:18 +00:00
|
|
|
-> Path.t
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string list
|
2018-02-06 14:39:03 +00:00
|
|
|
-> 'a Fiber.t
|
2016-12-02 13:54:32 +00:00
|
|
|
val run_capture_lines
|
2018-04-25 06:25:07 +00:00
|
|
|
: ?dir:Path.t
|
2018-03-29 15:58:41 +00:00
|
|
|
-> env:Env.t
|
2017-03-30 16:36:58 +00:00
|
|
|
-> ?purpose:purpose
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (string list, 'a) failure_mode
|
2018-04-25 09:30:18 +00:00
|
|
|
-> Path.t
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string list
|
2018-02-06 14:39:03 +00:00
|
|
|
-> 'a Fiber.t
|
2017-03-07 10:14:16 +00:00
|
|
|
|