diff --git a/bin/main.ml b/bin/main.ml index 153fe74f9f5..1b80277b728 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -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 @@ -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 @@ -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 diff --git a/src/utop.ml b/src/utop.ml index 67f5928886d..7cc8f6cdbc7 100644 --- a/src/utop.ml +++ b/src/utop.ml @@ -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 "@[Clflags.include_dirs :=@ [ %a@ ]@];@."