Skip to content

Commit 05fdc42

Browse files
committed
Add CHANGES and simplify some code
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent 27e45aa commit 05fdc42

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ next
6262
- Add `"odoc" {with-doc}` to the dependencies in the generated `.opam` files.
6363
(#3667, @kit-ty-kate)
6464

65+
- Do not allow user actions to capture dune's stdin (#3677, fixes #3672,
66+
@rgrinberg)
67+
6568
2.6.1 (02/07/2020)
6669
------------------
6770

src/dune/process.ml

+22-16
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ type purpose =
146146
| Internal_job
147147
| Build_job of Path.Build.Set.t
148148

149+
let io_to_redirection_path (kind : Io.kind) =
150+
match kind with
151+
| Terminal -> None
152+
| Null -> Some (Lazy.force Io.null_path)
153+
| File fn -> Some (Path.to_string fn)
154+
149155
let command_line_enclosers ~dir ~(stdout_to : Io.output Io.t)
150156
~(stderr_to : Io.output Io.t) ~(stdin_from : Io.input Io.t) =
151157
let quote fn = String.quote_for_shell (Path.to_string fn) in
@@ -156,26 +162,26 @@ let command_line_enclosers ~dir ~(stdout_to : Io.output Io.t)
156162
in
157163
let suffix =
158164
match stdin_from.kind with
159-
| Null -> suffix
160-
| Terminal -> suffix
165+
| Null
166+
| Terminal ->
167+
suffix
161168
| File fn -> suffix ^ " < " ^ quote fn
162169
in
163170
let suffix =
164-
match (stdout_to.kind, stderr_to.kind) with
165-
| File fn1, File fn2 when Path.equal fn1 fn2 -> " &> " ^ quote fn1
166-
| _ -> (
167-
let suffix =
168-
match stdout_to.kind with
169-
| Terminal -> suffix
170-
| Null ->
171-
suffix ^ " > " ^ String.quote_for_shell (Lazy.force Io.null_path)
172-
| File fn -> suffix ^ " > " ^ quote fn
171+
match
172+
( io_to_redirection_path stdout_to.kind
173+
, io_to_redirection_path stderr_to.kind )
174+
with
175+
| Some fn1, Some fn2 when String.equal fn1 fn2 ->
176+
" &> " ^ String.quote_for_shell fn1
177+
| path_out, path_err ->
178+
let add_to_suffix suffix path redirect =
179+
match path with
180+
| None -> suffix
181+
| Some path -> suffix ^ redirect ^ String.quote_for_shell path
173182
in
174-
match stderr_to.kind with
175-
| Terminal -> suffix
176-
| Null ->
177-
suffix ^ " 2> " ^ String.quote_for_shell (Lazy.force Io.null_path)
178-
| File fn -> suffix ^ " 2> " ^ quote fn )
183+
let suffix = add_to_suffix suffix path_out " > " in
184+
add_to_suffix suffix path_err " 2> "
179185
in
180186
(prefix, suffix)
181187

0 commit comments

Comments
 (0)