From 3f535b1e7b0aaabe2887e7958f01c8dcc2f1a1f2 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Fri, 13 Nov 2020 17:17:28 +0100 Subject: [PATCH] Use create_process instead of execvp 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 #295, ocaml/dune#3849. --- CHANGES.md | 1 + bin/test.ml | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b9fd2dd5b..c4c379879 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/bin/test.ml b/bin/test.ml index cab24b068..d1f5be645 100644 --- a/bin/test.ml +++ b/bin/test.ml @@ -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