Change Action to include the context's exec env
This commit is contained in:
parent
3c7e6adc73
commit
2634477def
|
@ -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
|
||||
|
|
|
@ -735,7 +735,16 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
|
|||
| Run (Error e, _) ->
|
||||
Prog.Not_found.raise e
|
||||
| Run (Ok prog, args) ->
|
||||
exec_run ~ectx ~dir ~env ~stdout_to ~stderr_to prog args
|
||||
exec_run ~ectx ~dir ~env:(
|
||||
match ectx.context with
|
||||
| None ->
|
||||
Sexp.code_error "context isn't available to this run action"
|
||||
[ "action", sexp_of_t t
|
||||
; "dir", Path.sexp_of_t dir
|
||||
; "env", Env.sexp_of_t env ]
|
||||
| Some ctx ->
|
||||
Env.extend_env ctx.env env
|
||||
) ~stdout_to ~stderr_to prog args
|
||||
| Chdir (dir, t) ->
|
||||
exec t ~ectx ~dir ~env ~stdout_to ~stderr_to
|
||||
| Setenv (var, value, t) ->
|
||||
|
|
|
@ -253,6 +253,32 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin ~targets () =
|
|||
else
|
||||
env
|
||||
in
|
||||
let env =
|
||||
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 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: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 +434,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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue