diff --git a/src/context.ml b/src/context.ml index 3f5f6358..31242d42 100644 --- a/src/context.ml +++ b/src/context.ml @@ -18,6 +18,13 @@ module Kind = struct ]) end +module Env_nodes = struct + type t = + { context: Dune_env.Stanza.t option + ; workspace: Dune_env.Stanza.t option + } +end + type t = { name : string ; kind : Kind.t @@ -26,7 +33,7 @@ type t = ; for_host : t option ; implicit : bool ; build_dir : Path.t - ; env_nodes : Dune_env.Stanza.t list + ; env_nodes : Env_nodes.t ; path : Path.t list ; toplevel_path : Path.t option ; ocaml_bin : Path.t @@ -456,14 +463,11 @@ let create_for_opam ?root ~env ~env_nodes ~targets ~profile ~switch ~name ~name ~merlin () 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 + let env_nodes context = + { Env_nodes. + context + ; workspace = workspace_env + } in match (def : Workspace.Context.t) with | Default { targets; profile; env = env_node ; loc = _ } -> diff --git a/src/context.mli b/src/context.mli index 88546438..954434c0 100644 --- a/src/context.mli +++ b/src/context.mli @@ -30,6 +30,13 @@ module Kind : sig type t = Default | Opam of Opam.t end +module Env_nodes : sig + type t = + { context: Dune_env.Stanza.t option + ; workspace: Dune_env.Stanza.t option + } +end + type t = { name : string ; kind : Kind.t @@ -51,7 +58,7 @@ type t = build_dir : Path.t ; (** env node that this context was initialized with *) - env_nodes : Dune_env.Stanza.t list + env_nodes : Env_nodes.t ; (** [PATH] *) path : Path.t list diff --git a/src/super_context.ml b/src/super_context.ml index 3632bd68..c4eb27b6 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -622,14 +622,14 @@ let create } in match context.env_nodes with - | [] -> + | { context = None; workspace = None } -> make ~config:{ loc = Loc.none; rules = [] } ~inherit_from:None - | [config] -> + | { context = Some config; workspace = None } + | { context = None; workspace = Some config } -> make ~config ~inherit_from:None - | [context; workspace] -> + | { context = Some context ; workspace = Some 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; _ } ->