@@ -8,12 +8,8 @@ type exec_context =
88 }
99
1010let get_std_output : _ -> Process.std_output_to = function
11- | None -> Terminal
12- | Some (fn , oc ) ->
13- Opened_file { filename = fn
14- ; tail = false
15- ; desc = Channel oc }
16-
11+ | None -> Terminal
12+ | Some fn -> File fn
1713
1814let exec_run_direct ~ectx ~dir ~env ~stdout_to ~stderr_to prog args =
1915 begin match ectx.context with
@@ -44,7 +40,7 @@ let exec_echo stdout_to str =
4440 Fiber. return
4541 (match stdout_to with
4642 | None -> print_string str; flush stdout
47- | Some ( _ , oc ) -> output_string oc str)
43+ | Some fn -> Io. write_file fn str)
4844
4945let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
5046 match (t : Action.t ) with
@@ -60,15 +56,6 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
6056 | Redirect (Stdout, fn , Echo s ) ->
6157 Io. write_file fn (String. concat s ~sep: " " );
6258 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
7259 | Redirect (outputs , fn , t ) ->
7360 redirect ~ectx ~dir outputs fn t ~env ~stdout_to ~stderr_to
7461 | Ignore (outputs , t ) ->
@@ -78,12 +65,9 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
7865 | Echo strs -> exec_echo stdout_to (String. concat strs ~sep: " " )
7966 | Cat fn ->
8067 Io. with_file_in fn ~f: (fun ic ->
81- let oc =
82- match stdout_to with
83- | None -> stdout
84- | Some (_ , oc ) -> oc
85- in
86- Io. copy_channels ic oc);
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));
8771 Fiber. return ()
8872 | Copy (src , dst ) ->
8973 Io. copy_file ~src ~dst () ;
@@ -195,16 +179,16 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
195179 Fiber. return ()
196180
197181and redirect outputs fn t ~ectx ~dir ~env ~stdout_to ~stderr_to =
198- let oc = Io. open_out fn in
199- let out = Some (fn, oc) in
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
200185 let stdout_to, stderr_to =
201186 match outputs with
202187 | Stdout -> (out, stderr_to)
203188 | Stderr -> (stdout_to, out)
204189 | Outputs -> (out, out)
205190 in
206- exec t ~ectx ~dir ~env ~stdout_to ~stderr_to >> | fun () ->
207- close_out oc
191+ exec t ~ectx ~dir ~env ~stdout_to ~stderr_to
208192
209193and exec_list l ~ectx ~dir ~env ~stdout_to ~stderr_to =
210194 match l with
0 commit comments