diff --git a/bin/main.ml b/bin/main.ml index 28f6539f..68afeee3 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1131,9 +1131,8 @@ let exec = raise Already_reported | Some real_prog, _ -> 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 - restore_cwd_and_execve common real_prog argv env + restore_cwd_and_execve common real_prog argv context.env in ( Term.(const go $ common @@ -1233,7 +1232,7 @@ let utop = ) |> Scheduler.go ~log ~common in Build_system.finalize build_system; restore_cwd_and_execve common utop_path (Array.of_list (utop_path :: args)) - (Context.env_for_exec context) + context.env in let name_ = Arg.info [] ~docv:"PATH" in ( Term.(const go diff --git a/src/bin.mli b/src/bin.mli index 94fce500..0c927b00 100644 --- a/src/bin.mli +++ b/src/bin.mli @@ -1,5 +1,7 @@ (** OCaml binaries *) +val path_sep : char + (** Contents of [PATH] *) val path : Path.t list diff --git a/src/context.ml b/src/context.ml index 3cce4ab6..b358f05c 100644 --- a/src/context.ml +++ b/src/context.ml @@ -253,6 +253,31 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin ~targets () = else env in + let env = + let cwd = Sys.getcwd () in + let extend_var var v = + let v = Filename.concat cwd (Path.to_string v) in + match Env.get env var with + | None -> (var, v) + | Some prev -> (var, sprintf "%s%c%s" v Bin.path_sep prev) + in + let vars = + [ extend_var "CAML_LD_LIBRARY_PATH" + (Path.relative + (Config.local_install_dir ~context:name) + "lib/stublibs") + ; extend_var "OCAMLPATH" + (Path.relative + (Config.local_install_dir ~context:name) + "lib") + ; extend_var "PATH" + (Config.local_install_bin_dir ~context:name) + ; extend_var "MANPATH" + (Config.local_install_man_dir ~context:name) + ] + in + Env.extend env ~vars:(Env.Map.of_list_exn vars) + in let stdlib_dir = Path.of_string (Ocaml_config.standard_library ocfg) in let natdynlink_supported = Ocaml_config.natdynlink_supported ocfg in let version = Ocaml_config.version ocfg in @@ -408,33 +433,6 @@ let install_ocaml_libdir t = | None -> Fiber.return None -(* CR-someday jdimino: maybe we should just do this for [t.env] directly? *) -let env_for_exec t = - let sep = if Sys.win32 then ';' else ':' in - let cwd = Sys.getcwd () in - let extend_var var v = - let v = Filename.concat cwd (Path.to_string v) in - match Env.get t.env var with - | None -> (var, v) - | Some prev -> (var, sprintf "%s%c%s" v sep prev) - in - let vars = - [ extend_var "CAML_LD_LIBRARY_PATH" - (Path.relative - (Config.local_install_dir ~context:t.name) - "lib/stublibs") - ; extend_var "OCAMLPATH" - (Path.relative - (Config.local_install_dir ~context:t.name) - "lib") - ; extend_var "PATH" - (Config.local_install_bin_dir ~context:t.name) - ; extend_var "MANPATH" - (Config.local_install_man_dir ~context:t.name) - ] - in - Env.extend t.env ~vars:(Env.Map.of_list_exn vars) - let compiler t (mode : Mode.t) = match mode with | Byte -> Some t.ocamlc diff --git a/src/context.mli b/src/context.mli index a1b54065..0513d3f7 100644 --- a/src/context.mli +++ b/src/context.mli @@ -130,8 +130,6 @@ val opam_config_var : t -> string -> string option Fiber.t val install_prefix : t -> Path.t Fiber.t val install_ocaml_libdir : t -> Path.t option Fiber.t -val env_for_exec : t -> Env.t - (** Return the compiler needed for this compilation mode *) val compiler : t -> Mode.t -> Path.t option