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 <rudi.grinberg@gmail.com>
This commit is contained in:
Rudi Grinberg 2018-07-10 16:27:33 +07:00
parent 4769f9df9f
commit b12517debb
7 changed files with 77 additions and 58 deletions

View File

@ -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

View File

@ -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

46
src/shared_stanza.ml Normal file
View File

@ -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

23
src/shared_stanza.mli Normal file
View File

@ -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

View File

@ -1,4 +1,5 @@
open Import
open Shared_stanza
open Jbuild
module A = Action

View File

@ -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

View File

@ -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