Change std_output_to and opened_file to use Path.t
This commit is contained in:
parent
b02c61f63c
commit
63af8747a7
|
@ -612,7 +612,10 @@ open Fiber.O
|
||||||
|
|
||||||
let get_std_output : _ -> Process.std_output_to = function
|
let get_std_output : _ -> Process.std_output_to = function
|
||||||
| None -> Terminal
|
| None -> Terminal
|
||||||
| Some (fn, oc) -> Opened_file { filename = fn; tail = false; desc = Channel oc }
|
| Some (fn, oc) ->
|
||||||
|
Opened_file { filename = (Path.of_string fn)
|
||||||
|
; tail = false
|
||||||
|
; desc = Channel oc }
|
||||||
|
|
||||||
module Promotion = struct
|
module Promotion = struct
|
||||||
module File = struct
|
module File = struct
|
||||||
|
@ -766,7 +769,7 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
|
||||||
Io.write_file fn s;
|
Io.write_file fn s;
|
||||||
Fiber.return ()
|
Fiber.return ()
|
||||||
| Redirect (outputs, fn, Run (Ok prog, args)) ->
|
| Redirect (outputs, fn, Run (Ok prog, args)) ->
|
||||||
let out = Process.File (Path.to_string fn) in
|
let out = Process.File fn in
|
||||||
let stdout_to, stderr_to =
|
let stdout_to, stderr_to =
|
||||||
match outputs with
|
match outputs with
|
||||||
| Stdout -> (out, get_std_output stderr_to)
|
| Stdout -> (out, get_std_output stderr_to)
|
||||||
|
|
|
@ -31,11 +31,11 @@ let map_result
|
||||||
|
|
||||||
type std_output_to =
|
type std_output_to =
|
||||||
| Terminal
|
| Terminal
|
||||||
| File of string
|
| File of Path.t
|
||||||
| Opened_file of opened_file
|
| Opened_file of opened_file
|
||||||
|
|
||||||
and opened_file =
|
and opened_file =
|
||||||
{ filename : string
|
{ filename : Path.t
|
||||||
; desc : opened_file_desc
|
; desc : opened_file_desc
|
||||||
; tail : bool
|
; tail : bool
|
||||||
}
|
}
|
||||||
|
@ -126,16 +126,18 @@ module Fancy = struct
|
||||||
match stdout_to, stderr_to with
|
match stdout_to, stderr_to with
|
||||||
| (File fn1 | Opened_file { filename = fn1; _ }),
|
| (File fn1 | Opened_file { filename = fn1; _ }),
|
||||||
(File fn2 | Opened_file { filename = fn2; _ }) when fn1 = fn2 ->
|
(File fn2 | Opened_file { filename = fn2; _ }) when fn1 = fn2 ->
|
||||||
sprintf "%s &> %s" s fn1
|
sprintf "%s &> %s" s (Path.to_string fn1)
|
||||||
| _ ->
|
| _ ->
|
||||||
let s =
|
let s =
|
||||||
match stdout_to with
|
match stdout_to with
|
||||||
| Terminal -> s
|
| Terminal -> s
|
||||||
| File fn | Opened_file { filename = fn; _ } -> sprintf "%s > %s" s fn
|
| File fn | Opened_file { filename = fn; _ } ->
|
||||||
|
sprintf "%s > %s" s (Path.to_string fn)
|
||||||
in
|
in
|
||||||
match stderr_to with
|
match stderr_to with
|
||||||
| Terminal -> s
|
| Terminal -> s
|
||||||
| File fn | Opened_file { filename = fn; _ } -> sprintf "%s 2> %s" s fn
|
| File fn | Opened_file { filename = fn; _ } ->
|
||||||
|
sprintf "%s 2> %s" s (Path.to_string fn)
|
||||||
|
|
||||||
let pp_purpose ppf = function
|
let pp_purpose ppf = function
|
||||||
| Internal_job ->
|
| Internal_job ->
|
||||||
|
@ -190,7 +192,8 @@ end
|
||||||
let get_std_output ~default = function
|
let get_std_output ~default = function
|
||||||
| Terminal -> (default, None)
|
| Terminal -> (default, None)
|
||||||
| File fn ->
|
| File fn ->
|
||||||
let fd = Unix.openfile fn [O_WRONLY; O_CREAT; O_TRUNC; O_SHARE_DELETE] 0o666 in
|
let fd = Unix.openfile (Path.to_string fn)
|
||||||
|
[O_WRONLY; O_CREAT; O_TRUNC; O_SHARE_DELETE] 0o666 in
|
||||||
(fd, Some (Fd fd))
|
(fd, Some (Fd fd))
|
||||||
| Opened_file { desc; tail; _ } ->
|
| Opened_file { desc; tail; _ } ->
|
||||||
let fd =
|
let fd =
|
||||||
|
@ -328,7 +331,7 @@ let run ?dir ?stdout_to ?stderr_to ~env ?(purpose=Internal_job) fail_mode
|
||||||
let run_capture_gen ?dir ~env ?(purpose=Internal_job) fail_mode prog args ~f =
|
let run_capture_gen ?dir ~env ?(purpose=Internal_job) fail_mode prog args ~f =
|
||||||
let fn = Temp.create "jbuild" ".output" in
|
let fn = Temp.create "jbuild" ".output" in
|
||||||
map_result fail_mode
|
map_result fail_mode
|
||||||
(run_internal ?dir ~stdout_to:(File (Path.to_string fn))
|
(run_internal ?dir ~stdout_to:(File fn)
|
||||||
~env ~purpose fail_mode prog args)
|
~env ~purpose fail_mode prog args)
|
||||||
~f:(fun () ->
|
~f:(fun () ->
|
||||||
let x = f fn in
|
let x = f fn in
|
||||||
|
|
|
@ -17,11 +17,11 @@ type ('a, 'b) failure_mode =
|
||||||
(** Where to redirect standard output *)
|
(** Where to redirect standard output *)
|
||||||
type std_output_to =
|
type std_output_to =
|
||||||
| Terminal
|
| Terminal
|
||||||
| File of string
|
| File of Path.t
|
||||||
| Opened_file of opened_file
|
| Opened_file of opened_file
|
||||||
|
|
||||||
and opened_file =
|
and opened_file =
|
||||||
{ filename : string
|
{ filename : Path.t
|
||||||
; desc : opened_file_desc
|
; desc : opened_file_desc
|
||||||
; tail : bool
|
; tail : bool
|
||||||
(** If [true], the descriptor is closed after starting the command *)
|
(** If [true], the descriptor is closed after starting the command *)
|
||||||
|
|
Loading…
Reference in New Issue