Skip to content

Commit

Permalink
refactor: move cram stanza details to cram module (#9401)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Dec 7, 2023
1 parent bbd4ec4 commit 02b79b4
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 98 deletions.
27 changes: 25 additions & 2 deletions src/dune_rules/cram/cram_stanza.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,25 @@ include Stanza.Make (struct
end)

let decode =
let* () = Dune_lang.Syntax.since Stanza.syntax (2, 7)
and+ project = Dune_project.get_exn ()
and+ loc = loc in
let* () =
let+ () = return () in
if not (Dune_project.cram project)
then
User_warning.emit
~loc
~is_error:(Dune_project.dune_version project >= (3, 0))
[ Pp.text "Cram tests are not enabled in this project." ]
~hints:
[ Pp.text
"You can enable cram tests by adding (cram enable) to your dune-project \
file."
]
in
fields
(let+ loc = loc
and+ applies_to = field "applies_to" decode_applies_to ~default:default_applies_to
(let+ applies_to = field "applies_to" decode_applies_to ~default:default_applies_to
and+ alias = field_o "alias" Dune_lang.Alias.decode
and+ deps = field_o "deps" (Bindings.decode Dep_conf.decode)
and+ enabled_if = Enabled_if.decode ~allowed_vars:Any ~since:None ()
Expand All @@ -54,3 +70,10 @@ let decode =
in
{ loc; alias; deps; enabled_if; locks; applies_to; package; runtest_alias })
;;

let stanza =
[ ( "cram"
, let+ t = decode in
List.singleton (make_stanza t) )
]
;;
2 changes: 1 addition & 1 deletion src/dune_rules/cram/cram_stanza.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ type t =

include Stanza.S with type t := t

val decode : t Dune_lang.Decoder.t
val stanza : (string * Stanza.t list Dune_lang.Decoder.t) list
178 changes: 83 additions & 95 deletions src/dune_rules/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2336,101 +2336,89 @@ module Stanzas = struct
type constructors = Stanza.Parser.t list

let stanzas : constructors =
Site_stanzas.all
@ [ ( "library"
, let+ x = Library.decode in
let base = [ Library.make_stanza x ] in
match Library_redirect.Local.of_lib x with
| None -> base
| Some r -> Library_redirect.Local.make_stanza r :: base )
; ( "foreign_library"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (2, 0)
and+ x = Foreign.Library.decode in
[ Foreign.Library.make_stanza x ] )
; "executable", Executables.single >>| execs
; "executables", Executables.multi >>| execs
; ( "rule"
, let+ loc = loc
and+ x = Rule.decode in
[ Rule.make_stanza { x with loc } ] )
; ( "ocamllex"
, let+ loc = loc
and+ x = Rule.ocamllex in
rules (Rule.ocamllex_to_rule loc x) )
; ( "ocamlyacc"
, let+ loc = loc
and+ x = Rule.ocamlyacc in
rules (Rule.ocamlyacc_to_rule loc x) )
; ( "install"
, let+ x = Install_conf.decode in
[ Install_conf.make_stanza x ] )
; ( "alias"
, let+ x = Alias_conf.decode in
[ Alias_conf.make_stanza x ] )
; ( "copy_files"
, let+ x = Copy_files.decode in
[ Copy_files.make_stanza x ] )
; ( "copy_files#"
, let+ x = Copy_files.decode in
[ Copy_files.make_stanza { x with add_line_directive = true } ] )
; ( "include"
, let+ loc = loc
and+ fn = relative_file in
[ Include.make_stanza (loc, fn) ] )
; ( "documentation"
, let+ d = Documentation.decode in
[ Documentation.make_stanza d ] )
; ( "jbuild_version"
, let+ () = Dune_lang.Syntax.deleted_in Stanza.syntax (1, 0)
and+ _ = Jbuild_version.decode in
[] )
; ( "tests"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 0)
and+ t = Tests.multi in
[ Tests.make_stanza t ] )
; ( "test"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 0)
and+ t = Tests.single in
[ Tests.make_stanza t ] )
; ( "external_variant"
, let+ () = Dune_lang.Syntax.deleted_in Stanza.syntax (2, 6) in
[] )
; ( "env"
, let+ x = Dune_env.decode in
[ Dune_env.make_stanza x ] )
; ( "include_subdirs"
, let* project = Dune_project.get_exn () in
let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 1)
and+ t =
let enable_qualified = Dune_project.is_extension_set project Coq_stanza.key in
Include_subdirs.decode ~enable_qualified
and+ loc = loc in
[ Include_subdirs.make_stanza (loc, t) ] )
; ( "toplevel"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 7)
and+ t = Toplevel.decode in
[ Toplevel.make_stanza t ] )
; ( "deprecated_library_name"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (2, 0)
and+ t = Deprecated_library_name.decode in
[ Deprecated_library_name.make_stanza t ] )
; ( "cram"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (2, 7)
and+ t = Cram_stanza.decode
and+ project = Dune_project.get_exn ()
and+ loc = loc in
if not (Dune_project.cram project)
then
User_warning.emit
~loc
~is_error:(Dune_project.dune_version project >= (3, 0))
[ Pp.text "Cram tests are not enabled in this project." ]
~hints:
[ Pp.text
"You can enable cram tests by adding (cram enable) to your \
dune-project file."
];
[ Cram_stanza.make_stanza t ] )
List.concat
[ Site_stanzas.all
; Cram_stanza.stanza
; [ ( "library"
, let+ x = Library.decode in
let base = [ Library.make_stanza x ] in
match Library_redirect.Local.of_lib x with
| None -> base
| Some r -> Library_redirect.Local.make_stanza r :: base )
; ( "foreign_library"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (2, 0)
and+ x = Foreign.Library.decode in
[ Foreign.Library.make_stanza x ] )
; "executable", Executables.single >>| execs
; "executables", Executables.multi >>| execs
; ( "rule"
, let+ loc = loc
and+ x = Rule.decode in
[ Rule.make_stanza { x with loc } ] )
; ( "ocamllex"
, let+ loc = loc
and+ x = Rule.ocamllex in
rules (Rule.ocamllex_to_rule loc x) )
; ( "ocamlyacc"
, let+ loc = loc
and+ x = Rule.ocamlyacc in
rules (Rule.ocamlyacc_to_rule loc x) )
; ( "install"
, let+ x = Install_conf.decode in
[ Install_conf.make_stanza x ] )
; ( "alias"
, let+ x = Alias_conf.decode in
[ Alias_conf.make_stanza x ] )
; ( "copy_files"
, let+ x = Copy_files.decode in
[ Copy_files.make_stanza x ] )
; ( "copy_files#"
, let+ x = Copy_files.decode in
[ Copy_files.make_stanza { x with add_line_directive = true } ] )
; ( "include"
, let+ loc = loc
and+ fn = relative_file in
[ Include.make_stanza (loc, fn) ] )
; ( "documentation"
, let+ d = Documentation.decode in
[ Documentation.make_stanza d ] )
; ( "jbuild_version"
, let+ () = Dune_lang.Syntax.deleted_in Stanza.syntax (1, 0)
and+ _ = Jbuild_version.decode in
[] )
; ( "tests"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 0)
and+ t = Tests.multi in
[ Tests.make_stanza t ] )
; ( "test"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 0)
and+ t = Tests.single in
[ Tests.make_stanza t ] )
; ( "external_variant"
, let+ () = Dune_lang.Syntax.deleted_in Stanza.syntax (2, 6) in
[] )
; ( "env"
, let+ x = Dune_env.decode in
[ Dune_env.make_stanza x ] )
; ( "include_subdirs"
, let* project = Dune_project.get_exn () in
let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 1)
and+ t =
let enable_qualified =
Dune_project.is_extension_set project Coq_stanza.key
in
Include_subdirs.decode ~enable_qualified
and+ loc = loc in
[ Include_subdirs.make_stanza (loc, t) ] )
; ( "toplevel"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (1, 7)
and+ t = Toplevel.decode in
[ Toplevel.make_stanza t ] )
; ( "deprecated_library_name"
, let+ () = Dune_lang.Syntax.since Stanza.syntax (2, 0)
and+ t = Deprecated_library_name.decode in
[ Deprecated_library_name.make_stanza t ] )
]
]
;;

Expand Down

0 comments on commit 02b79b4

Please sign in to comment.