Represent env_nodes using a record rather than a list

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-30 14:13:09 +02:00
parent 2836a3c6b0
commit 024438e3cc
3 changed files with 25 additions and 14 deletions

View File

@ -18,6 +18,13 @@ module Kind = struct
]) ])
end end
module Env_nodes = struct
type t =
{ context: Dune_env.Stanza.t option
; workspace: Dune_env.Stanza.t option
}
end
type t = type t =
{ name : string { name : string
; kind : Kind.t ; kind : Kind.t
@ -26,7 +33,7 @@ type t =
; for_host : t option ; for_host : t option
; implicit : bool ; implicit : bool
; build_dir : Path.t ; build_dir : Path.t
; env_nodes : Dune_env.Stanza.t list ; env_nodes : Env_nodes.t
; path : Path.t list ; path : Path.t list
; toplevel_path : Path.t option ; toplevel_path : Path.t option
; ocaml_bin : Path.t ; ocaml_bin : Path.t
@ -456,14 +463,11 @@ let create_for_opam ?root ~env ~env_nodes ~targets ~profile ~switch ~name
~name ~merlin () ~name ~merlin ()
let create ?merlin ?workspace_env ~env def = let create ?merlin ?workspace_env ~env def =
let env_nodes = let env_nodes context =
match workspace_env with { Env_nodes.
| None -> Option.to_list context
| Some s -> ; workspace = workspace_env
begin function }
| None -> [s]
| Some x -> [x; s]
end
in in
match (def : Workspace.Context.t) with match (def : Workspace.Context.t) with
| Default { targets; profile; env = env_node ; loc = _ } -> | Default { targets; profile; env = env_node ; loc = _ } ->

View File

@ -30,6 +30,13 @@ module Kind : sig
type t = Default | Opam of Opam.t type t = Default | Opam of Opam.t
end end
module Env_nodes : sig
type t =
{ context: Dune_env.Stanza.t option
; workspace: Dune_env.Stanza.t option
}
end
type t = type t =
{ name : string { name : string
; kind : Kind.t ; kind : Kind.t
@ -51,7 +58,7 @@ type t =
build_dir : Path.t build_dir : Path.t
; (** env node that this context was initialized with *) ; (** env node that this context was initialized with *)
env_nodes : Dune_env.Stanza.t list env_nodes : Env_nodes.t
; (** [PATH] *) ; (** [PATH] *)
path : Path.t list path : Path.t list

View File

@ -622,14 +622,14 @@ let create
} }
in in
match context.env_nodes with match context.env_nodes with
| [] -> | { context = None; workspace = None } ->
make ~config:{ loc = Loc.none; rules = [] } ~inherit_from: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 make ~config ~inherit_from:None
| [context; workspace] -> | { context = Some context ; workspace = Some workspace } ->
make ~config:context make ~config:context
~inherit_from:(Some (lazy (make ~inherit_from:None ~config:workspace))) ~inherit_from:(Some (lazy (make ~inherit_from:None ~config:workspace)))
| _::_::_::_ -> assert false
) in ) in
List.iter stanzas List.iter stanzas
~f:(fun { Dir_with_jbuild. ctx_dir; scope; stanzas; _ } -> ~f:(fun { Dir_with_jbuild. ctx_dir; scope; stanzas; _ } ->