Improve the behavior of "jbuilder exec" on Windows

This commit is contained in:
Jeremie Dimino 2017-05-31 14:40:58 +01:00
parent f18afbf8aa
commit f210b32fd0
1 changed files with 29 additions and 22 deletions

View File

@ -757,8 +757,7 @@ let exec =
let go common context prog args =
set_common common ~targets:[];
let log = Log.create () in
Future.Scheduler.go ~log
(Main.setup ~log common >>= fun setup ->
let setup = Future.Scheduler.go ~log (Main.setup ~log common) in
let context =
match List.find setup.contexts ~f:(fun c -> c.name = context) with
| Some ctx -> ctx
@ -774,11 +773,19 @@ let exec =
| Some real_prog ->
let real_prog = Path.to_string real_prog in
let env = Context.env_for_exec context in
let argv = Array.of_list (prog :: args) in
if Sys.win32 then
Future.run ~env Strict real_prog args
let pid =
Unix.create_process_env real_prog argv env
Unix.stdin Unix.stdout Unix.stderr
in
match snd (Unix.waitpid [] pid) with
| WEXITED 0 -> ()
| WEXITED n -> exit n
| WSIGNALED _ -> exit 255
| WSTOPPED _ -> assert false
else
Unix.execve real_prog (Array.of_list (prog :: args)) env
)
Unix.execve real_prog argv env
in
( Term.(const go
$ common