Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jbuilder exec from sub dirs & utop #339

Merged
merged 2 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -868,7 +874,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
Expand Down Expand Up @@ -964,7 +970,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
Expand Down
2 changes: 1 addition & 1 deletion src/utop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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@ ]@];@."
Expand Down