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 dune lang (not the extension). Tests are a bit flaky for now.

Closes: ocaml#5489
Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
emillon committed Apr 27, 2022
1 parent ce51dc2 commit 6e5b1c7
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/dune_rules/mdx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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 Down Expand Up @@ -170,6 +171,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 Stanza.syntax (3, 2)
>>> repeat String_with_vars.decode)
~default:[]
in
{ loc
; version
Expand All @@ -180,6 +186,7 @@ let decode =
; libraries
; enabled_if
; package
; locks
})

let () =
Expand Down Expand Up @@ -215,6 +222,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 @@ -258,6 +268,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
72 changes: 72 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,72 @@
With interleaving

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

$ mkdir a b

$ cat > a/dune << EOF
> (mdx)
> EOF

$ cp a/dune b/dune

$ cat > a/README.md << 'EOF'
> ```sh
> $ echo begin a >> ../../../log.txt
> $ sleep 1
> $ echo end a >> ../../../log.txt
> ```
> EOF

$ cat > b/README.md << 'EOF'
> ```sh
> $ echo begin b >> ../../../log.txt
> $ sleep 1
> $ echo end b >> ../../../log.txt
> ```
> EOF

$ dune runtest -j 4

$ cat log.txt
begin a
begin b
end a
end b

$ dune clean

Without interleaving

$ cat > a/dune << EOF
> (mdx
> (locks /l))
$ cp a/dune b/dune

$ rm log.txt

$ dune runtest -j 4

$ cat log.txt
begin a
end a
begin b
end b

Version check

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

$ dune runtest
File "a/dune", line 2, characters 1-11:
2 | (locks /l))
^^^^^^^^^^
Error: 'locks' is only available since version 3.2 of the dune language.
Please update your dune-project file to have (lang dune 3.2).
[1]

0 comments on commit 6e5b1c7

Please sign in to comment.