From 8cda4349fae6d54c0b356511583b0deb84d25ee9 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 20 Jul 2018 11:59:23 +0200 Subject: [PATCH] Use toplevel env stanza from workspace file This should be the top most env stanza when it's available Signed-off-by: Rudi Grinberg --- src/context.ml | 30 ++++++++++++++++++++---------- src/context.mli | 3 ++- src/super_context.ml | 28 +++++++++++++++++----------- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/context.ml b/src/context.ml index d005a9a6..3f5f6358 100644 --- a/src/context.ml +++ b/src/context.ml @@ -26,7 +26,7 @@ type t = ; for_host : t option ; implicit : bool ; build_dir : Path.t - ; env_node : Dune_env.Stanza.t option + ; env_nodes : Dune_env.Stanza.t list ; path : Path.t list ; toplevel_path : Path.t option ; ocaml_bin : Path.t @@ -131,7 +131,7 @@ let ocamlpath_sep = else Bin.path_sep -let create ~(kind : Kind.t) ~path ~env ~env_node ~name ~merlin ~targets +let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets ~profile () = let opam_var_cache = Hashtbl.create 128 in (match kind with @@ -334,7 +334,7 @@ let create ~(kind : Kind.t) ~path ~env ~env_node ~name ~merlin ~targets ; kind ; profile ; merlin - ; env_node + ; env_nodes ; for_host = host ; build_dir ; path @@ -410,11 +410,11 @@ let create ~(kind : Kind.t) ~path ~env ~env_node ~name ~merlin ~targets let opam_config_var t var = opam_config_var ~env:t.env ~cache:t.opam_var_cache var -let default ?(merlin=true) ~env_node ~env ~targets () = - create ~kind:Default ~path:Bin.path ~env ~env_node ~name:"default" +let default ?(merlin=true) ~env_nodes ~env ~targets () = + create ~kind:Default ~path:Bin.path ~env ~env_nodes ~name:"default" ~merlin ~targets () -let create_for_opam ?root ~env ~env_node ~targets ~profile ~switch ~name +let create_for_opam ?root ~env ~env_nodes ~targets ~profile ~switch ~name ?(merlin=false) () = match Bin.opam with | None -> Utils.program_not_found "opam" @@ -452,16 +452,26 @@ let create_for_opam ?root ~env ~env_node ~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 ~env_node + create ~kind:(Opam { root; switch }) ~profile ~targets ~path ~env ~env_nodes ~name ~merlin () -let create ?merlin ~env def = +let create ?merlin ?workspace_env ~env def = + let env_nodes = + match workspace_env with + | None -> Option.to_list + | Some s -> + begin function + | None -> [s] + | Some x -> [x; s] + end + in match (def : Workspace.Context.t) with | Default { targets; profile; env = env_node ; loc = _ } -> - default ~env ~env_node ~profile ~targets ?merlin () + default ~env ~env_nodes:(env_nodes env_node) ~profile ~targets ?merlin () | Opam { base = { targets ; profile ; env = env_node ; loc = _ } ; name; switch; root; merlin = _ } -> - create_for_opam ?root ~env_node ~env ~profile ~switch ~name ?merlin ~targets () + create_for_opam ?root ~env_nodes:(env_nodes 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 7cf4fe37..88546438 100644 --- a/src/context.mli +++ b/src/context.mli @@ -51,7 +51,7 @@ type t = build_dir : Path.t ; (** env node that this context was initialized with *) - env_node : Dune_env.Stanza.t option + env_nodes : Dune_env.Stanza.t list ; (** [PATH] *) path : Path.t list @@ -125,6 +125,7 @@ val compare : t -> t -> Ordering.t val create : ?merlin:bool + -> ?workspace_env:Dune_env.Stanza.t -> env:Env.t -> Workspace.Context.t -> t list Fiber.t diff --git a/src/super_context.ml b/src/super_context.ml index 7dc19eff..3632bd68 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -612,18 +612,24 @@ let create } in let context_env_node = lazy ( - let config = - match context.env_node with - | Some s -> s - | None -> { loc = Loc.none; rules = [] } + let make ~inherit_from ~config = + { Env_node. + dir = context.build_dir + ; scope = Scope.DB.find_by_dir scopes context.build_dir + ; ocaml_flags = None + ; inherit_from + ; config + } in - { Env_node. - dir = context.build_dir - ; inherit_from = None - ; scope = Scope.DB.find_by_dir scopes context.build_dir - ; config - ; ocaml_flags = None - } + match context.env_nodes with + | [] -> + make ~config:{ loc = Loc.none; rules = [] } ~inherit_from:None + | [config] -> + make ~config ~inherit_from:None + | [context; workspace] -> + make ~config:context + ~inherit_from:(Some (lazy (make ~inherit_from:None ~config:workspace))) + | _::_::_::_ -> assert false ) in List.iter stanzas ~f:(fun { Dir_with_jbuild. ctx_dir; scope; stanzas; _ } ->