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