@@ -8,8 +8,12 @@ type exec_context =
88 }
99
1010let get_std_output : _ -> Process.std_output_to = function
11- | None -> Terminal
12- | Some fn -> File fn
11+ | None -> Terminal
12+ | Some (fn , oc ) ->
13+ Opened_file { filename = fn
14+ ; tail = false
15+ ; desc = Channel oc }
16+
1317
1418let exec_run_direct ~ectx ~dir ~env ~stdout_to ~stderr_to prog args =
1519 begin match ectx.context with
@@ -40,7 +44,7 @@ let exec_echo stdout_to str =
4044 Fiber. return
4145 (match stdout_to with
4246 | None -> print_string str; flush stdout
43- | Some fn -> Io. write_file fn str)
47+ | Some ( _ , oc ) -> output_string oc str)
4448
4549let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
4650 match (t : Action.t ) with
@@ -56,6 +60,15 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
5660 | Redirect (Stdout, fn , Echo s ) ->
5761 Io. write_file fn (String. concat s ~sep: " " );
5862 Fiber. return ()
63+ | Redirect (outputs , fn , Run (Ok prog , args )) ->
64+ let out = Process. File fn in
65+ let stdout_to, stderr_to =
66+ match outputs with
67+ | Stdout -> (out, get_std_output stderr_to)
68+ | Stderr -> (get_std_output stdout_to, out)
69+ | Outputs -> (out, out)
70+ in
71+ exec_run_direct ~ectx ~dir ~env ~stdout_to ~stderr_to prog args
5972 | Redirect (outputs , fn , t ) ->
6073 redirect ~ectx ~dir outputs fn t ~env ~stdout_to ~stderr_to
6174 | Ignore (outputs , t ) ->
@@ -65,9 +78,12 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
6578 | Echo strs -> exec_echo stdout_to (String. concat strs ~sep: " " )
6679 | Cat fn ->
6780 Io. with_file_in fn ~f: (fun ic ->
68- match stdout_to with
69- | None -> Io. copy_channels ic stdout
70- | Some fn -> Io. with_file_out fn ~f: (fun oc -> Io. copy_channels ic oc));
81+ let oc =
82+ match stdout_to with
83+ | None -> stdout
84+ | Some (_ , oc ) -> oc
85+ in
86+ Io. copy_channels ic oc);
7187 Fiber. return ()
7288 | Copy (src , dst ) ->
7389 Io. copy_file ~src ~dst () ;
@@ -179,16 +195,16 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
179195 Fiber. return ()
180196
181197and redirect outputs fn t ~ectx ~dir ~env ~stdout_to ~stderr_to =
182- (* We resolve the path to an absolute one here to ensure no
183- Chdir actions change the eventual path of the file *)
184- let out = Some (Path. to_absolute fn) in
198+ let oc = Io. open_out fn in
199+ let out = Some (fn, oc) in
185200 let stdout_to, stderr_to =
186201 match outputs with
187202 | Stdout -> (out, stderr_to)
188203 | Stderr -> (stdout_to, out)
189204 | Outputs -> (out, out)
190205 in
191- exec t ~ectx ~dir ~env ~stdout_to ~stderr_to
206+ exec t ~ectx ~dir ~env ~stdout_to ~stderr_to >> | fun () ->
207+ close_out oc
192208
193209and exec_list l ~ectx ~dir ~env ~stdout_to ~stderr_to =
194210 match l with
0 commit comments