From 63af8747a72d724161b6a65f4fbb110211f8f8fd Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 25 Apr 2018 16:33:25 +0700 Subject: [PATCH] Change std_output_to and opened_file to use Path.t --- src/action.ml | 7 +++++-- src/process.ml | 17 ++++++++++------- src/process.mli | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/action.ml b/src/action.ml index 4d91dcf3..fb7426ed 100644 --- a/src/action.ml +++ b/src/action.ml @@ -612,7 +612,10 @@ open Fiber.O let get_std_output : _ -> Process.std_output_to = function | 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 File = struct @@ -766,7 +769,7 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to = Io.write_file fn s; Fiber.return () | 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 = match outputs with | Stdout -> (out, get_std_output stderr_to) diff --git a/src/process.ml b/src/process.ml index 9a5ab24a..5b2f52ed 100644 --- a/src/process.ml +++ b/src/process.ml @@ -31,11 +31,11 @@ let map_result type std_output_to = | Terminal - | File of string + | File of Path.t | Opened_file of opened_file and opened_file = - { filename : string + { filename : Path.t ; desc : opened_file_desc ; tail : bool } @@ -126,16 +126,18 @@ module Fancy = struct match stdout_to, stderr_to with | (File fn1 | Opened_file { filename = fn1; _ }), (File fn2 | Opened_file { filename = fn2; _ }) when fn1 = fn2 -> - sprintf "%s &> %s" s fn1 + sprintf "%s &> %s" s (Path.to_string fn1) | _ -> let s = match stdout_to with | 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 match stderr_to with | 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 | Internal_job -> @@ -190,7 +192,8 @@ end let get_std_output ~default = function | Terminal -> (default, None) | 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)) | Opened_file { desc; tail; _ } -> 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 fn = Temp.create "jbuild" ".output" in 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) ~f:(fun () -> let x = f fn in diff --git a/src/process.mli b/src/process.mli index 41a53585..9b16d3f0 100644 --- a/src/process.mli +++ b/src/process.mli @@ -17,11 +17,11 @@ type ('a, 'b) failure_mode = (** Where to redirect standard output *) type std_output_to = | Terminal - | File of string + | File of Path.t | Opened_file of opened_file and opened_file = - { filename : string + { filename : Path.t ; desc : opened_file_desc ; tail : bool (** If [true], the descriptor is closed after starting the command *)