Skip to content

Commit

Permalink
Use create_process instead of execvp
Browse files Browse the repository at this point in the history
On Windows, execvp creates a separate process, which can confuse dune
when it is waiting for the mdx process. This causes it to miss that the
output file has been created. This affects mdx's test suite and
possibly users of the mdx stanza. Instead we create a process and
immediately wait for it in the parent.

See realworldocaml#295, ocaml/dune#3849.
  • Loading branch information
emillon committed Nov 18, 2020
1 parent 122c513 commit 3f535b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Report `#require` directive errors (#276, @gpetiot)
- Handle no such file exception: the input file and the values of options `--root` and `--prelude` are checked (#292, @gpetiot)
- Keep locations from parsing instead of recomputing the lines, providing better error messages (#241, @gpetiot)
- Use `create_process` instead of `execvp` to call `mdx-test` from `mdx`. This fixes part of the test suite on Windows (#299, @emillon)

#### Security

Expand Down
7 changes: 6 additions & 1 deletion bin/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ let run (`Setup ()) _ _ _ _ _ _ _ _ _ _ =
let argv = Array.sub Sys.argv 1 (Array.length Sys.argv - 1) in
argv.(0) <- cmd;
Log.debug (fun l -> l "executing %a" Fmt.(Dump.array string) argv);
Unix.execvp cmd argv
let pid = Unix.create_process cmd argv Unix.stdin Unix.stdout Unix.stderr in
let _pid, status = Unix.waitpid [] pid in
let exit_code =
match status with WEXITED n -> n | WSIGNALED _ -> 1 | WSTOPPED _ -> 1
in
exit exit_code

open Cmdliner

Expand Down

0 comments on commit 3f535b1

Please sign in to comment.