Skip to content

Commit

Permalink
Add (locks) to (mdx) stanza
Browse files Browse the repository at this point in the history
This adds a (locks) field to the mdx stanza. This field is versioned
against the extension.

Closes ocaml#5489

Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed May 13, 2022
1 parent 862162f commit f5ac1ee
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
- Support `(binaries)` in `(env)` in dune-workspace files (#5560, fix #5555,
@emillon)

- (mdx) stanza: add support for (locks). (#5628, fixes #5489, @emillon)

3.1.1 (19/04/2022)
------------------

Expand Down
3 changes: 3 additions & 0 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,9 @@ Where ``<optional-fields>`` are:
Note that this feature is completely separate from ``(packages)``, which
specifies some dependencies.

- ``(locks <lock-names>)`` specifies that the action of running the tests
holds the specified locks. See the :ref:`locks` section for more details.

Upgrading from Version 0.1
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
16 changes: 15 additions & 1 deletion src/dune_rules/mdx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type t =
; enabled_if : Blang.t
; package : Package.t option
; libraries : Lib_dep.t list
; locks : String_with_vars.t list
}

let enabled_if t = t.enabled_if
Expand All @@ -138,7 +139,10 @@ let syntax =
let name = "mdx" in
let desc = "mdx extension to verify code blocks in .md files" in
Dune_lang.Syntax.create ~name ~desc
[ ((0, 1), `Since (2, 4)); ((0, 2), `Since (3, 0)) ]
[ ((0, 1), `Since (2, 4))
; ((0, 2), `Since (3, 0))
; ((0, 3), `Since (3, 2))
]

let default_files =
let has_extension ext s = String.equal ext (Filename.extension s) in
Expand Down Expand Up @@ -169,6 +173,11 @@ let decode =
field "libraries" ~default:[]
(Dune_lang.Syntax.since syntax (0, 2)
>>> Dune_file.Lib_deps.decode Executable)
and+ locks =
field "locks"
(Dune_lang.Syntax.since syntax (0, 3)
>>> repeat String_with_vars.decode)
~default:[]
in
{ loc
; version
Expand All @@ -179,6 +188,7 @@ let decode =
; libraries
; enabled_if
; package
; locks
})

let () =
Expand Down Expand Up @@ -214,6 +224,9 @@ let gen_rules_for_single_file stanza ~sctx ~dir ~expander ~mdx_prog
let files = Files.from_source_file ~mdx_dir src in
(* Add the rule for generating the .mdx.deps file with ocaml-mdx deps *)
let open Memo.O in
let* locks =
Memo.List.map stanza.locks ~f:(Expander.No_deps.expand_path expander)
in
let* () =
Super_context.add_rule sctx ~loc ~dir (Deps.rule ~dir ~mdx_prog files)
and* () =
Expand Down Expand Up @@ -257,6 +270,7 @@ let gen_rules_for_single_file stanza ~sctx ~dir ~expander ~mdx_prog
>>> Action_builder.with_no_targets (Action_builder.dyn_deps dyn_deps)
>>> Command.run ~dir:(Path.build dir) ~stdout_to:files.corrected
executable command_line
>>| Action.Full.add_locks locks
>>| Action.Full.add_sandbox sandbox
in
Super_context.add_rule sctx ~loc ~dir mdx_action
Expand Down
29 changes: 29 additions & 0 deletions test/blackbox-tests/test-cases/mdx-stanza/locks.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Version 0.2 of the mdx stanza does not support (locks):

$ cat > dune-project << EOF
> (lang dune 3.2)
> (using mdx 0.2)
> EOF

$ cat > dune << EOF
> (mdx
> (locks l))
> EOF

$ dune build
File "dune", line 2, characters 1-10:
2 | (locks l))
^^^^^^^^^
Error: 'locks' is only available since version 0.3 of mdx extension to verify
code blocks in .md files. Please update your dune-project file to have (using
mdx 0.3).
[1]

In version 0.3, it is accepted:

$ cat > dune-project << EOF
> (lang dune 3.2)
> (using mdx 0.3)
> EOF

$ dune build

0 comments on commit f5ac1ee

Please sign in to comment.