diff --git a/bin/main.ml b/bin/main.ml index 02d7d7c1..df1433f9 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -574,6 +574,7 @@ let installed_libraries = (Default { loc = Loc.of_pos __POS__ ; targets = [Native] ; profile = Config.default_build_profile + ; env = None }) ~env >>= fun ctxs -> diff --git a/src/context.ml b/src/context.ml index 2d07634a..2a91fb4d 100644 --- a/src/context.ml +++ b/src/context.ml @@ -26,6 +26,7 @@ type t = ; for_host : t option ; implicit : bool ; build_dir : Path.t + ; env_node : Shared_stanza.Env.t option ; path : Path.t list ; toplevel_path : Path.t option ; ocaml_bin : Path.t @@ -130,7 +131,8 @@ let ocamlpath_sep = else Bin.path_sep -let create ~(kind : Kind.t) ~path ~env ~name ~merlin ~targets ~profile () = +let create ~(kind : Kind.t) ~path ~env ~env_node ~name ~merlin ~targets + ~profile () = let opam_var_cache = Hashtbl.create 128 in (match kind with | Opam { root; _ } -> @@ -332,6 +334,7 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin ~targets ~profile () = ; kind ; profile ; merlin + ; env_node ; for_host = host ; build_dir ; path @@ -407,10 +410,11 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin ~targets ~profile () = let opam_config_var t var = opam_config_var ~env:t.env ~cache:t.opam_var_cache var -let default ?(merlin=true) ~env ~targets () = - create ~kind:Default ~path:Bin.path ~env ~name:"default" ~merlin ~targets () +let default ?(merlin=true) ~env_node ~env ~targets () = + create ~kind:Default ~path:Bin.path ~env ~env_node ~name:"default" + ~merlin ~targets () -let create_for_opam ?root ~env ~targets ~profile ~switch ~name +let create_for_opam ?root ~env ~env_node ~targets ~profile ~switch ~name ?(merlin=false) () = match Bin.opam with | None -> Utils.program_not_found "opam" @@ -448,15 +452,16 @@ let create_for_opam ?root ~env ~targets ~profile ~switch ~name | Some s -> Bin.parse_path s in let env = Env.extend env ~vars in - create ~kind:(Opam { root; switch }) ~profile ~targets ~path ~env ~name - ~merlin () + create ~kind:(Opam { root; switch }) ~profile ~targets ~path ~env ~env_node + ~name ~merlin () let create ?merlin ~env def = match (def : Workspace.Context.t) with - | Default { targets; profile; _ } -> default ~env ~profile ~targets ?merlin () - | Opam { base = { targets ; profile ; loc = _ } + | Default { targets; profile; env = env_node ; loc = _ } -> + default ~env ~env_node ~profile ~targets ?merlin () + | Opam { base = { targets ; profile ; env = env_node ; loc = _ } ; name; switch; root; merlin = _ } -> - create_for_opam ?root ~env ~profile ~switch ~name ?merlin ~targets () + create_for_opam ?root ~env_node ~env ~profile ~switch ~name ?merlin ~targets () let which t s = which ~cache:t.which_cache ~path:t.path s diff --git a/src/context.mli b/src/context.mli index 733bd9d0..af23a195 100644 --- a/src/context.mli +++ b/src/context.mli @@ -50,6 +50,9 @@ type t = ; (** Directory where artifact are stored, for instance "_build/default" *) build_dir : Path.t + ; (** env node that this context was initialized with *) + env_node : Shared_stanza.Env.t option + ; (** [PATH] *) path : Path.t list diff --git a/src/jbuild.mli b/src/jbuild.mli index 840d6ff9..902c3b6b 100644 --- a/src/jbuild.mli +++ b/src/jbuild.mli @@ -366,6 +366,8 @@ module Env : sig { loc : Loc.t ; rules : (pattern * config) list } + + val t : t Sexp.Of_sexp.t end module Tests : sig diff --git a/src/workspace.ml b/src/workspace.ml index 4a4c296d..339ac294 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -45,9 +45,11 @@ module Context = struct { loc : Loc.t ; profile : string ; targets : Target.t list + ; env : Jbuild.Env.t option } let t ~profile = + field_o "env" Jbuild.Env.t >>= fun env -> field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets -> field "profile" string ~default:profile @@ -57,6 +59,7 @@ module Context = struct { targets ; profile ; loc + ; env } end @@ -138,6 +141,7 @@ module Context = struct ; targets = [Option.value x ~default:Target.Native] ; profile = Option.value profile ~default:Config.default_build_profile + ; env = None } end diff --git a/src/workspace.mli b/src/workspace.mli index a73e7c6c..5062f5f8 100644 --- a/src/workspace.mli +++ b/src/workspace.mli @@ -13,6 +13,7 @@ module Context : sig { loc : Loc.t ; profile : string ; targets : Target.t list + ; env : Jbuild.Env.t option } end module Opam : sig