From 20fe7a9d2007be9e9745675ed4f5a2f99ad02858 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 11:41:35 +0700 Subject: [PATCH 01/12] Refactor workspace type Make the opam workspace include the shared fields from a base type Signed-off-by: Rudi Grinberg --- src/context.ml | 3 +- src/workspace.ml | 79 ++++++++++++++++++++++++----------------------- src/workspace.mli | 17 +++++----- 3 files changed, 52 insertions(+), 47 deletions(-) diff --git a/src/context.ml b/src/context.ml index 677c3685..2d07634a 100644 --- a/src/context.ml +++ b/src/context.ml @@ -454,7 +454,8 @@ let create_for_opam ?root ~env ~targets ~profile ~switch ~name let create ?merlin ~env def = match (def : Workspace.Context.t) with | Default { targets; profile; _ } -> default ~env ~profile ~targets ?merlin () - | Opam { name; switch; root; targets; profile; _ } -> + | Opam { base = { targets ; profile ; loc = _ } + ; name; switch; root; merlin = _ } -> create_for_opam ?root ~env ~profile ~switch ~name ?merlin ~targets () let which t s = which ~cache:t.which_cache ~path:t.path s diff --git a/src/workspace.ml b/src/workspace.ml index 65999fa1..4a4c296d 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -40,60 +40,63 @@ module Context = struct name) end - module Opam = struct - type t = - { loc : Loc.t - ; name : string - ; profile : string - ; switch : string - ; root : string option - ; merlin : bool - ; targets : Target.t list - } - - let t ~profile ~x = - field "switch" string >>= fun switch -> - field "name" Name.t ~default:switch >>= fun name -> - field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets -> - field_o "root" string >>= fun root -> - field_b "merlin" >>= fun merlin -> - field "profile" string ~default:profile >>= fun profile -> - loc >>= fun loc -> - return { loc - ; switch - ; name - ; root - ; merlin - ; targets = Target.add targets x - ; profile - } - end - - module Default = struct + module Base = struct type t = { loc : Loc.t ; profile : string ; targets : Target.t list } - let t ~profile ~x = + let t ~profile = field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets -> field "profile" string ~default:profile >>= fun profile -> - loc - >>= fun loc -> - return { loc - ; targets = Target.add targets x - ; profile + loc >>= fun loc -> + return + { targets + ; profile + ; loc + } + end + + module Opam = struct + type t = + { base : Base.t + ; name : string + ; switch : string + ; root : string option + ; merlin : bool + } + + let t ~profile ~x = + Base.t ~profile >>= fun base -> + field "switch" string >>= fun switch -> + field "name" Name.t ~default:switch >>= fun name -> + field_o "root" string >>= fun root -> + field_b "merlin" >>= fun merlin -> + let base = { base with targets = Target.add base.targets x } in + return { base + ; switch + ; name + ; root + ; merlin } end + module Default = struct + type t = Base.t + + let t ~profile ~x = + Base.t ~profile >>= fun t -> + return { t with targets = Target.add t.targets x } + end + type t = Default of Default.t | Opam of Opam.t let loc = function | Default x -> x.loc - | Opam x -> x.loc + | Opam x -> x.base.loc let t ~profile ~x = sum @@ -121,7 +124,7 @@ module Context = struct let targets = function | Default x -> x.targets - | Opam x -> x.targets + | Opam x -> x.base.targets let all_names t = let n = name t in diff --git a/src/workspace.mli b/src/workspace.mli index 19c04bdc..a73e7c6c 100644 --- a/src/workspace.mli +++ b/src/workspace.mli @@ -8,24 +8,25 @@ module Context : sig | Native | Named of string end - module Opam : sig + module Base : sig type t = { loc : Loc.t - ; name : string ; profile : string + ; targets : Target.t list + } + end + module Opam : sig + type t = + { base : Base.t + ; name : string ; switch : string ; root : string option ; merlin : bool - ; targets : Target.t list } end module Default : sig - type t = - { loc : Loc.t - ; profile : string - ; targets : Target.t list - } + type t = Base.t end type t = Default of Default.t | Opam of Opam.t From 61d7e49e0703d23719353aa3126f5eb8dbe29068 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 13:24:21 +0700 Subject: [PATCH 02/12] Move env stanza parsing to Env.t This will be necessary to allow this stanza in Workspace Signed-off-by: Rudi Grinberg --- src/jbuild.ml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/jbuild.ml b/src/jbuild.ml index 38c6eb67..e7aa3b2a 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -1626,11 +1626,6 @@ module Stanzas = struct (let%map () = Syntax.since Stanza.syntax (1, 0) and t = Tests.single in [Tests t]) - ; "env", - (let%map () = Syntax.since Stanza.syntax (1, 0) - and loc = loc - and rules = repeat Env.rule in - [Env { loc; rules }]) ] let jbuild_parser = From 4769f9df9f5e3327229ff887196a336e18deb412 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 16:14:21 +0700 Subject: [PATCH 03/12] Plumb through env node workspace -> context -> super context Signed-off-by: Rudi Grinberg --- bin/main.ml | 1 + src/context.ml | 23 ++++++++++++++--------- src/context.mli | 3 +++ src/jbuild.mli | 2 ++ src/workspace.ml | 4 ++++ src/workspace.mli | 1 + 6 files changed, 25 insertions(+), 9 deletions(-) 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 From b12517debb110608281d92c65c52bcb8ff731ac1 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 16:27:33 +0700 Subject: [PATCH 04/12] Move Env stanza to Shared_stanza module To break dependency cycles. This shared_stanza module doesn't have any dependencies on actions. Signed-off-by: Rudi Grinberg --- src/jbuild.ml | 39 ++++-------------------------------- src/jbuild.mli | 20 ------------------- src/shared_stanza.ml | 46 +++++++++++++++++++++++++++++++++++++++++++ src/shared_stanza.mli | 23 ++++++++++++++++++++++ src/super_context.ml | 1 + src/workspace.ml | 4 ++-- src/workspace.mli | 2 +- 7 files changed, 77 insertions(+), 58 deletions(-) create mode 100644 src/shared_stanza.ml create mode 100644 src/shared_stanza.mli diff --git a/src/jbuild.ml b/src/jbuild.ml index e7aa3b2a..dd7af3d0 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -1517,39 +1517,6 @@ module Documentation = struct ) end -module Env = struct - type config = - { flags : Ordered_set_lang.Unexpanded.t - ; ocamlc_flags : Ordered_set_lang.Unexpanded.t - ; ocamlopt_flags : Ordered_set_lang.Unexpanded.t - } - - type pattern = - | Profile of string - | Any - - type t = - { loc : Loc.t - ; rules : (pattern * config) list - } - - let config = - let%map flags = field_oslu "flags" - and ocamlc_flags = field_oslu "ocamlc_flags" - and ocamlopt_flags = field_oslu "ocamlopt_flags" - in - { flags; ocamlc_flags; ocamlopt_flags } - - let rule = - enter - (let%map pat = - match_keyword [("_", return Any)] - ~fallback:(string >>| fun s -> Profile s) - and configs = fields config - in - (pat, configs)) -end - type Stanza.t += | Library of Library.t | Executables of Executables.t @@ -1558,7 +1525,6 @@ type Stanza.t += | Alias of Alias_conf.t | Copy_files of Copy_files.t | Documentation of Documentation.t - | Env of Env.t | Tests of Tests.t module Stanzas = struct @@ -1695,7 +1661,10 @@ module Stanzas = struct "\n--> included from %s" (line_loc x)))) in - match List.filter_map stanzas ~f:(function Env e -> Some e | _ -> None) with + match + List.filter_map stanzas + ~f:(function Shared_stanza.Env e -> Some e | _ -> None) + with | _ :: e :: _ -> Loc.fail e.loc "The 'env' stanza cannot appear more than once" | _ -> stanzas diff --git a/src/jbuild.mli b/src/jbuild.mli index 902c3b6b..2c432ff8 100644 --- a/src/jbuild.mli +++ b/src/jbuild.mli @@ -351,25 +351,6 @@ module Documentation : sig } end -module Env : sig - type config = - { flags : Ordered_set_lang.Unexpanded.t - ; ocamlc_flags : Ordered_set_lang.Unexpanded.t - ; ocamlopt_flags : Ordered_set_lang.Unexpanded.t - } - - type pattern = - | Profile of string - | Any - - type t = - { loc : Loc.t - ; rules : (pattern * config) list - } - - val t : t Sexp.Of_sexp.t -end - module Tests : sig type t = { exes : Executables.t @@ -387,7 +368,6 @@ type Stanza.t += | Alias of Alias_conf.t | Copy_files of Copy_files.t | Documentation of Documentation.t - | Env of Env.t | Tests of Tests.t module Stanzas : sig diff --git a/src/shared_stanza.ml b/src/shared_stanza.ml new file mode 100644 index 00000000..dc8b772a --- /dev/null +++ b/src/shared_stanza.ml @@ -0,0 +1,46 @@ +open Import +open Stanza.Of_sexp + +let field_oslu name = Ordered_set_lang.Unexpanded.field name + +module Env = struct + type config = + { flags : Ordered_set_lang.Unexpanded.t + ; ocamlc_flags : Ordered_set_lang.Unexpanded.t + ; ocamlopt_flags : Ordered_set_lang.Unexpanded.t + } + + type pattern = + | Profile of string + | Any + + type t = + { loc : Loc.t + ; rules : (pattern * config) list + } + + let config = + let%map flags = field_oslu "flags" + and ocamlc_flags = field_oslu "ocamlc_flags" + and ocamlopt_flags = field_oslu "ocamlopt_flags" + in + { flags; ocamlc_flags; ocamlopt_flags } + + let rule = + enter + (let%map pat = + match_keyword [("_", return Any)] + ~fallback:(string >>| fun s -> Profile s) + and configs = fields config + in + (pat, configs)) + + let t = + Syntax.since Stanza.syntax (1, 0) >>= fun () -> + loc >>= fun loc -> + repeat rule >>| fun rules -> + { loc; rules } +end + +type Stanza.t += + | Env of Env.t diff --git a/src/shared_stanza.mli b/src/shared_stanza.mli new file mode 100644 index 00000000..1f6f2a3a --- /dev/null +++ b/src/shared_stanza.mli @@ -0,0 +1,23 @@ +open Import + +module Env : sig + type config = + { flags : Ordered_set_lang.Unexpanded.t + ; ocamlc_flags : Ordered_set_lang.Unexpanded.t + ; ocamlopt_flags : Ordered_set_lang.Unexpanded.t + } + + type pattern = + | Profile of string + | Any + + type t = + { loc : Loc.t + ; rules : (pattern * config) list + } + + val t : t Sexp.Of_sexp.t +end + +type Stanza.t += + | Env of Env.t diff --git a/src/super_context.ml b/src/super_context.ml index 67424618..d3cf06d7 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -1,4 +1,5 @@ open Import +open Shared_stanza open Jbuild module A = Action diff --git a/src/workspace.ml b/src/workspace.ml index 339ac294..11e03412 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -45,11 +45,11 @@ module Context = struct { loc : Loc.t ; profile : string ; targets : Target.t list - ; env : Jbuild.Env.t option + ; env : Shared_stanza.Env.t option } let t ~profile = - field_o "env" Jbuild.Env.t >>= fun env -> + field_o "env" Shared_stanza.Env.t >>= fun env -> field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets -> field "profile" string ~default:profile diff --git a/src/workspace.mli b/src/workspace.mli index 5062f5f8..fb891d7a 100644 --- a/src/workspace.mli +++ b/src/workspace.mli @@ -13,7 +13,7 @@ module Context : sig { loc : Loc.t ; profile : string ; targets : Target.t list - ; env : Jbuild.Env.t option + ; env : Shared_stanza.Env.t option } end module Opam : sig From 4860461ba3f47f2a2e36f35eee0392660c77c616 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 16:35:43 +0700 Subject: [PATCH 05/12] Pun inherit_from field Signed-off-by: Rudi Grinberg --- src/super_context.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/super_context.ml b/src/super_context.ml index d3cf06d7..164920c8 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -624,7 +624,7 @@ let create in Hashtbl.add t.env ctx_dir { dir = ctx_dir - ; inherit_from = inherit_from + ; inherit_from ; scope = scope ; config = config ; ocaml_flags = None From a82e783f15b3b893bb064c500d7436dbefbc5c11 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 16:41:54 +0700 Subject: [PATCH 06/12] re-arrange short match to go to the top Signed-off-by: Rudi Grinberg --- src/super_context.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/super_context.ml b/src/super_context.ml index 164920c8..ed8aa288 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -420,6 +420,7 @@ end = struct let rec get t ~dir = match Hashtbl.find t.env dir with + | Some node -> node | None -> begin match Path.parent dir with | None -> raise_notrace Exit @@ -428,7 +429,6 @@ end = struct Hashtbl.add t.env dir node; node end - | Some node -> node let get t ~dir = match get t ~dir with From 78786e09d40b8c8aa27f08226e96f58cc8f305f4 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 10 Jul 2018 17:11:46 +0700 Subject: [PATCH 07/12] Initialize env_node from Super_context.create Signed-off-by: Rudi Grinberg --- src/super_context.ml | 29 ++++++++++++------- .../test-cases/workspaces/run.t | 4 +++ .../test-cases/workspaces/workspace-env/dune | 0 .../workspaces/workspace-env/dune-project | 1 + .../workspaces/workspace-env/dune-workspace | 7 +++++ 5 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 test/blackbox-tests/test-cases/workspaces/workspace-env/dune create mode 100644 test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project create mode 100644 test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace diff --git a/src/super_context.ml b/src/super_context.ml index ed8aa288..816ccd74 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -612,33 +612,40 @@ let create ; env = Hashtbl.create 128 } in + let context_env_node = lazy ( + let config = + match context.env_node with + | Some s -> s + | None -> { loc = Loc.none; rules = [] } + in + { Env_node. + dir = context.build_dir + ; inherit_from = None + ; scope = Scope.DB.find_by_dir scopes context.build_dir + ; config + ; ocaml_flags = None + } + ) in List.iter stanzas ~f:(fun { Dir_with_jbuild. ctx_dir; scope; stanzas; _ } -> List.iter stanzas ~f:(function | Env config -> let inherit_from = if ctx_dir = Scope.root scope then - None + context_env_node else - Some (lazy (Env.get t ~dir:(Path.parent_exn ctx_dir))) + lazy (Env.get t ~dir:(Path.parent_exn ctx_dir)) in Hashtbl.add t.env ctx_dir { dir = ctx_dir - ; inherit_from + ; inherit_from = Some inherit_from ; scope = scope ; config = config ; ocaml_flags = None } | _ -> ())); if not (Hashtbl.mem t.env context.build_dir) then - Hashtbl.add t.env context.build_dir - { Env_node. - dir = context.build_dir - ; inherit_from = None - ; scope = Scope.DB.find_by_dir scopes context.build_dir - ; config = { loc = Loc.none; rules = [] } - ; ocaml_flags = None - }; + Hashtbl.add t.env context.build_dir (Lazy.force context_env_node); t module Libs = struct open Build.O diff --git a/test/blackbox-tests/test-cases/workspaces/run.t b/test/blackbox-tests/test-cases/workspaces/run.t index e33d288a..bafc3847 100644 --- a/test/blackbox-tests/test-cases/workspaces/run.t +++ b/test/blackbox-tests/test-cases/workspaces/run.t @@ -47,3 +47,7 @@ see how we can set a "native" target. Which is the default. Entering directory 'targets-native' Entering directory 'targets-native' message from targets-native test + +Workspaces also allow you to set the env for a context: + + $ dune printenv --root workspace-env --profile default \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/workspace-env/dune b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune new file mode 100644 index 00000000..e69de29b diff --git a/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project new file mode 100644 index 00000000..b2559fa0 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-project @@ -0,0 +1 @@ +(lang dune 1.0) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace new file mode 100644 index 00000000..30a26e35 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/workspace-env/dune-workspace @@ -0,0 +1,7 @@ +(lang dune 1.0) + +(context + (default + (env + (default + (flags (:standard -machin)))))) \ No newline at end of file From 78e18716ce9a3c92c623f0ccf467cbf4067d432d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 13 Jul 2018 15:52:21 +0200 Subject: [PATCH 08/12] Rename Shared_stanaza to Dune_env Signed-off-by: Rudi Grinberg --- src/context.ml | 2 +- src/context.mli | 2 +- src/{shared_stanza.ml => dune_env.ml} | 15 +++++++++------ src/{shared_stanza.mli => dune_env.mli} | 8 +++++--- src/jbuild.ml | 3 ++- src/super_context.ml | 8 ++++---- src/workspace.ml | 4 ++-- src/workspace.mli | 2 +- 8 files changed, 25 insertions(+), 19 deletions(-) rename src/{shared_stanza.ml => dune_env.ml} (82%) rename src/{shared_stanza.mli => dune_env.mli} (81%) diff --git a/src/context.ml b/src/context.ml index 2a91fb4d..d005a9a6 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 : Shared_stanza.Env.t option + ; env_node : Dune_env.Stanza.t option ; path : Path.t list ; toplevel_path : Path.t option ; ocaml_bin : Path.t diff --git a/src/context.mli b/src/context.mli index af23a195..7cf4fe37 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 : Shared_stanza.Env.t option + env_node : Dune_env.Stanza.t option ; (** [PATH] *) path : Path.t list diff --git a/src/shared_stanza.ml b/src/dune_env.ml similarity index 82% rename from src/shared_stanza.ml rename to src/dune_env.ml index dc8b772a..1227d7d7 100644 --- a/src/shared_stanza.ml +++ b/src/dune_env.ml @@ -1,9 +1,11 @@ -open Import -open Stanza.Of_sexp +type stanza = Stanza.t = .. -let field_oslu name = Ordered_set_lang.Unexpanded.field name +module Stanza = struct + open Import + open Stanza.Of_sexp + + let field_oslu name = Ordered_set_lang.Unexpanded.field name -module Env = struct type config = { flags : Ordered_set_lang.Unexpanded.t ; ocamlc_flags : Ordered_set_lang.Unexpanded.t @@ -40,7 +42,8 @@ module Env = struct loc >>= fun loc -> repeat rule >>| fun rules -> { loc; rules } + end -type Stanza.t += - | Env of Env.t +type stanza += + | T of Stanza.t diff --git a/src/shared_stanza.mli b/src/dune_env.mli similarity index 81% rename from src/shared_stanza.mli rename to src/dune_env.mli index 1f6f2a3a..afe45c3a 100644 --- a/src/shared_stanza.mli +++ b/src/dune_env.mli @@ -1,6 +1,8 @@ open Import -module Env : sig +type stanza = Stanza.t = .. + +module Stanza : sig type config = { flags : Ordered_set_lang.Unexpanded.t ; ocamlc_flags : Ordered_set_lang.Unexpanded.t @@ -19,5 +21,5 @@ module Env : sig val t : t Sexp.Of_sexp.t end -type Stanza.t += - | Env of Env.t +type stanza += + | T of Stanza.t diff --git a/src/jbuild.ml b/src/jbuild.ml index dd7af3d0..be30a42a 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -1592,6 +1592,7 @@ module Stanzas = struct (let%map () = Syntax.since Stanza.syntax (1, 0) and t = Tests.single in [Tests t]) + ; "env", Dune_env.Stanza.t >>| fun x -> [Dune_env.T x] ] let jbuild_parser = @@ -1663,7 +1664,7 @@ module Stanzas = struct in match List.filter_map stanzas - ~f:(function Shared_stanza.Env e -> Some e | _ -> None) + ~f:(function Dune_env.T e -> Some e | _ -> None) with | _ :: e :: _ -> Loc.fail e.loc "The 'env' stanza cannot appear more than once" diff --git a/src/super_context.ml b/src/super_context.ml index 816ccd74..f0992784 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -1,5 +1,5 @@ open Import -open Shared_stanza +(* open Dune_env.Stanza *) open Jbuild module A = Action @@ -29,7 +29,7 @@ module Env_node = struct { dir : Path.t ; inherit_from : t Lazy.t option ; scope : Scope.t - ; config : Env.t + ; config : Dune_env.Stanza.t ; mutable ocaml_flags : Ocaml_flags.t option } end @@ -449,7 +449,7 @@ end = struct in let flags = match List.find_map node.config.rules ~f:(fun (pat, cfg) -> - match (pat : Env.pattern), profile t with + match (pat : Dune_env.Stanza.pattern), profile t with | Any, _ -> Some cfg | Profile a, b -> Option.some_if (a = b) cfg) with @@ -629,7 +629,7 @@ let create List.iter stanzas ~f:(fun { Dir_with_jbuild. ctx_dir; scope; stanzas; _ } -> List.iter stanzas ~f:(function - | Env config -> + | Dune_env.T config -> let inherit_from = if ctx_dir = Scope.root scope then context_env_node diff --git a/src/workspace.ml b/src/workspace.ml index 11e03412..f331d5fa 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -45,11 +45,11 @@ module Context = struct { loc : Loc.t ; profile : string ; targets : Target.t list - ; env : Shared_stanza.Env.t option + ; env : Dune_env.Stanza.t option } let t ~profile = - field_o "env" Shared_stanza.Env.t >>= fun env -> + field_o "env" Dune_env.Stanza.t >>= fun env -> field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets -> field "profile" string ~default:profile diff --git a/src/workspace.mli b/src/workspace.mli index fb891d7a..f3d73ebe 100644 --- a/src/workspace.mli +++ b/src/workspace.mli @@ -13,7 +13,7 @@ module Context : sig { loc : Loc.t ; profile : string ; targets : Target.t list - ; env : Shared_stanza.Env.t option + ; env : Dune_env.Stanza.t option } end module Opam : sig From bac0a35785bd56abd7dd6cfba2637f257f79a1fa Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 13 Jul 2018 15:52:56 +0200 Subject: [PATCH 09/12] Accept corrections Signed-off-by: Rudi Grinberg --- test/blackbox-tests/test-cases/workspaces/run.t | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/blackbox-tests/test-cases/workspaces/run.t b/test/blackbox-tests/test-cases/workspaces/run.t index bafc3847..68895ba7 100644 --- a/test/blackbox-tests/test-cases/workspaces/run.t +++ b/test/blackbox-tests/test-cases/workspaces/run.t @@ -50,4 +50,10 @@ see how we can set a "native" target. Which is the default. Workspaces also allow you to set the env for a context: - $ dune printenv --root workspace-env --profile default \ No newline at end of file + $ dune printenv --root workspace-env --profile default + Entering directory 'workspace-env' + ( + (flags (-w -40 -machin)) + (ocamlc_flags (-g)) + (ocamlopt_flags (-g)) + ) From 655c10164d92df85fbdfef92b6e4bdd75fc92e40 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 18 Jul 2018 13:45:10 +0200 Subject: [PATCH 10/12] Use syntax extension for parsing stanza Signed-off-by: Rudi Grinberg --- src/dune_env.ml | 8 ++++---- src/jbuild.ml | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dune_env.ml b/src/dune_env.ml index 1227d7d7..7f88ac71 100644 --- a/src/dune_env.ml +++ b/src/dune_env.ml @@ -1,7 +1,6 @@ type stanza = Stanza.t = .. module Stanza = struct - open Import open Stanza.Of_sexp let field_oslu name = Ordered_set_lang.Unexpanded.field name @@ -38,9 +37,10 @@ module Stanza = struct (pat, configs)) let t = - Syntax.since Stanza.syntax (1, 0) >>= fun () -> - loc >>= fun loc -> - repeat rule >>| fun rules -> + let%map () = Syntax.since Stanza.syntax (1, 0) + and loc = loc + and rules = repeat rule + in { loc; rules } end diff --git a/src/jbuild.ml b/src/jbuild.ml index be30a42a..2f793065 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -1592,7 +1592,9 @@ module Stanzas = struct (let%map () = Syntax.since Stanza.syntax (1, 0) and t = Tests.single in [Tests t]) - ; "env", Dune_env.Stanza.t >>| fun x -> [Dune_env.T x] + ; "env", + (let%map x = Dune_env.Stanza.t in + [Dune_env.T x]) ] let jbuild_parser = From 14030a8ad5b3202b7b282cf635574478cc0ff4eb Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 19 Jul 2018 12:14:25 +0200 Subject: [PATCH 11/12] Remove unused open Signed-off-by: Rudi Grinberg --- src/super_context.ml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/super_context.ml b/src/super_context.ml index f0992784..7dc19eff 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -1,5 +1,4 @@ open Import -(* open Dune_env.Stanza *) open Jbuild module A = Action From 1f0bee0cf756f5e2852ad2e65dad7f7983e6a625 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 19 Jul 2018 13:11:42 +0200 Subject: [PATCH 12/12] Rename base to common Signed-off-by: Rudi Grinberg --- src/workspace.ml | 10 +++++----- src/workspace.mli | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/workspace.ml b/src/workspace.ml index f331d5fa..f4780297 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -40,7 +40,7 @@ module Context = struct name) end - module Base = struct + module Common = struct type t = { loc : Loc.t ; profile : string @@ -65,7 +65,7 @@ module Context = struct module Opam = struct type t = - { base : Base.t + { base : Common.t ; name : string ; switch : string ; root : string option @@ -73,7 +73,7 @@ module Context = struct } let t ~profile ~x = - Base.t ~profile >>= fun base -> + Common.t ~profile >>= fun base -> field "switch" string >>= fun switch -> field "name" Name.t ~default:switch >>= fun name -> field_o "root" string >>= fun root -> @@ -88,10 +88,10 @@ module Context = struct end module Default = struct - type t = Base.t + type t = Common.t let t ~profile ~x = - Base.t ~profile >>= fun t -> + Common.t ~profile >>= fun t -> return { t with targets = Target.add t.targets x } end diff --git a/src/workspace.mli b/src/workspace.mli index f3d73ebe..fa5fd6a4 100644 --- a/src/workspace.mli +++ b/src/workspace.mli @@ -8,7 +8,7 @@ module Context : sig | Native | Named of string end - module Base : sig + module Common : sig type t = { loc : Loc.t ; profile : string @@ -18,7 +18,7 @@ module Context : sig end module Opam : sig type t = - { base : Base.t + { base : Common.t ; name : string ; switch : string ; root : string option @@ -27,7 +27,7 @@ module Context : sig end module Default : sig - type t = Base.t + type t = Common.t end type t = Default of Default.t | Opam of Opam.t