From cdaa05d9feb15768b3bd28544613a79beeac3b83 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Thu, 3 Oct 2024 21:14:47 +1000 Subject: [PATCH] refactor: pass workspace root to restore_cwd_and_execve Signed-off-by: Stephen Sherratt --- bin/coq/coqtop.ml | 2 +- bin/exec.ml | 6 ++++-- bin/import.ml | 12 ++++-------- bin/ocaml/utop.ml | 2 +- bin/tools/ocamllsp.ml | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/bin/coq/coqtop.ml b/bin/coq/coqtop.ml index 660562531409..41ab4df2efcb 100644 --- a/bin/coq/coqtop.ml +++ b/bin/coq/coqtop.ml @@ -153,7 +153,7 @@ let term = in Fiber.return (coqtop, argv, env) in - restore_cwd_and_execve common coqtop argv env + restore_cwd_and_execve (Common.root common) coqtop argv env ;; let command = Cmd.v info term diff --git a/bin/exec.ml b/bin/exec.ml index 2118a1a2b987..9ca1a6ac7344 100644 --- a/bin/exec.ml +++ b/bin/exec.ml @@ -79,7 +79,9 @@ module Command_to_exec = struct environment, returning the new process' pid *) let spawn_process (common : Common.t) path ~args ~env = let pid = - let prog = string_path_relative_to_specified_root common (Path.to_string path) in + let prog = + string_path_relative_to_specified_root (Common.root common) (Path.to_string path) + in let env = Env.to_unix env |> Spawn.Env.of_list in let argv = prog :: args in let cwd = Spawn.Working_dir.Path Fpath.initial_cwd in @@ -298,7 +300,7 @@ module Exec_context = struct in let prog = Path.to_string path in let argv = prog :: args in - restore_cwd_and_execve common prog argv env + restore_cwd_and_execve (Common.root common) prog argv env ;; let run_eager_watch t common config = diff --git a/bin/import.ml b/bin/import.ml index f795d2ea540a..100a9e112da4 100644 --- a/bin/import.ml +++ b/bin/import.ml @@ -237,16 +237,12 @@ module Scheduler = struct ;; end -let string_path_relative_to_specified_root (common : Common.t) path = - if Filename.is_relative path - then ( - let root = Common.root common in - Filename.concat root.dir path) - else path +let string_path_relative_to_specified_root (root : Workspace_root.t) path = + if Filename.is_relative path then Filename.concat root.dir path else path ;; -let restore_cwd_and_execve common prog argv env = - let prog = string_path_relative_to_specified_root common prog in +let restore_cwd_and_execve root prog argv env = + let prog = string_path_relative_to_specified_root root prog in Proc.restore_cwd_and_execve prog argv ~env ;; diff --git a/bin/ocaml/utop.ml b/bin/ocaml/utop.ml index 35196beef482..17f09222aabb 100644 --- a/bin/ocaml/utop.ml +++ b/bin/ocaml/utop.ml @@ -56,7 +56,7 @@ let term = ~f:(fun dir env -> Env_path.cons ~var:Ocaml.Env.caml_ld_library_path env ~dir) ~init:env in - restore_cwd_and_execve common utop_path (utop_path :: args) env + restore_cwd_and_execve (Common.root common) utop_path (utop_path :: args) env ;; let command = Cmd.v info term diff --git a/bin/tools/ocamllsp.ml b/bin/tools/ocamllsp.ml index 8f3ca407d43c..eeb66f31128f 100644 --- a/bin/tools/ocamllsp.ml +++ b/bin/tools/ocamllsp.ml @@ -51,7 +51,7 @@ let term = let open Fiber.O in let* () = Lock_dev_tool.lock_ocamllsp () |> Memo.run in let+ () = build_ocamllsp common in - run_ocamllsp common ~args) + run_ocamllsp (Common.root common) ~args) ;; let info =