Improve the behavior of "jbuilder exec" on Windows
This commit is contained in:
parent
f18afbf8aa
commit
f210b32fd0
51
bin/main.ml
51
bin/main.ml
|
@ -757,28 +757,35 @@ let exec =
|
||||||
let go common context prog args =
|
let go common context prog args =
|
||||||
set_common common ~targets:[];
|
set_common common ~targets:[];
|
||||||
let log = Log.create () in
|
let log = Log.create () in
|
||||||
Future.Scheduler.go ~log
|
let setup = Future.Scheduler.go ~log (Main.setup ~log common) in
|
||||||
(Main.setup ~log common >>= fun setup ->
|
let context =
|
||||||
let context =
|
match List.find setup.contexts ~f:(fun c -> c.name = context) with
|
||||||
match List.find setup.contexts ~f:(fun c -> c.name = context) with
|
| Some ctx -> ctx
|
||||||
| Some ctx -> ctx
|
| None ->
|
||||||
| None ->
|
Format.eprintf "@{<Error>Error@}: Context %S not found!@." context;
|
||||||
Format.eprintf "@{<Error>Error@}: Context %S not found!@." context;
|
die ""
|
||||||
die ""
|
in
|
||||||
in
|
let path = Config.local_install_bin_dir ~context:context.name :: context.path in
|
||||||
let path = Config.local_install_bin_dir ~context:context.name :: context.path in
|
match Bin.which ~path prog with
|
||||||
match Bin.which ~path prog with
|
| None ->
|
||||||
| None ->
|
Format.eprintf "@{<Error>Error@}: Program %S not found!@." prog;
|
||||||
Format.eprintf "@{<Error>Error@}: Program %S not found!@." prog;
|
die ""
|
||||||
die ""
|
| Some real_prog ->
|
||||||
| Some real_prog ->
|
let real_prog = Path.to_string real_prog in
|
||||||
let real_prog = Path.to_string real_prog in
|
let env = Context.env_for_exec context in
|
||||||
let env = Context.env_for_exec context in
|
let argv = Array.of_list (prog :: args) in
|
||||||
if Sys.win32 then
|
if Sys.win32 then
|
||||||
Future.run ~env Strict real_prog args
|
let pid =
|
||||||
else
|
Unix.create_process_env real_prog argv env
|
||||||
Unix.execve real_prog (Array.of_list (prog :: args)) 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 argv env
|
||||||
in
|
in
|
||||||
( Term.(const go
|
( Term.(const go
|
||||||
$ common
|
$ common
|
||||||
|
|
Loading…
Reference in New Issue