Merge pull request #339 from rgrinberg/fix-jbuilder-exec-utop

Fix jbuilder exec from sub dirs & utop
This commit is contained in:
François Bobot 2017-12-01 13:41:21 +01:00 committed by GitHub
commit 13fed1f1ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 14 deletions

View File

@ -45,19 +45,25 @@ let set_common c ~targets =
; targets
]
let execve =
let restore_cwd_and_execve common prog argv env =
let prog =
if Filename.is_relative prog then
Filename.concat common.root prog
else
prog
in
Sys.chdir initial_cwd;
if Sys.win32 then
fun prog argv env ->
let pid = Unix.create_process_env 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
let pid = Unix.create_process_env 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
Unix.execve prog argv env
module Main = struct
include Jbuilder.Main
@ -871,7 +877,7 @@ let exec =
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
execve real_prog argv env
restore_cwd_and_execve common real_prog argv env
in
( Term.(const go
$ common
@ -967,7 +973,7 @@ let utop =
(setup.build_system, context, Path.to_string target)
) |> Future.Scheduler.go ~log in
Build_system.dump_trace build_system;
execve utop_path (Array.of_list (utop_path :: args))
restore_cwd_and_execve common utop_path (Array.of_list (utop_path :: args))
(Context.env_for_exec context)
in
let name_ = Arg.info [] ~docv:"PATH" in

View File

@ -11,7 +11,7 @@ let pp_ml fmt include_dirs =
let pp_include fmt =
let pp_sep fmt () = Format.fprintf fmt "@ ; " in
Format.pp_print_list ~pp_sep (fun fmt p ->
Format.fprintf fmt "%S" (Path.to_string p)
Format.fprintf fmt "%S" (Path.to_absolute_filename p)
) fmt
in
Format.fprintf fmt "@[<v 2>Clflags.include_dirs :=@ [ %a@ ]@];@."