Skip to content

Commit

Permalink
Attach actions from cinaps to @cinaps and @runtest
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Rebours <[email protected]>
  • Loading branch information
NathanReb committed Nov 4, 2019
1 parent ad4c739 commit 2fda82a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
2.0.0 (unreleased)
------------------

- Attach cinaps stanza actions to both `@runtest` and `@cinaps` aliases
(#2831, @NathanReb)

- Introduce `alias` and `package` fields to the `rule` stanza. This is the
preferred way of attaching rules to aliases. (#2744, @rgrinberg)

Expand Down
2 changes: 2 additions & 0 deletions src/dune/build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ let progn ts =
let+ actions = all ts in
Action.Progn actions

let noop = return (Action.progn [])

let merge_files_dyn ~target paths =
let action =
let+ sources, extras =
Expand Down
2 changes: 2 additions & 0 deletions src/dune/build.mli
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ val mkdir : Path.Build.t -> Action.t t
(** Merge a list of actions *)
val progn : Action.t t list -> Action.t t

val noop : Action.t t

val record_lib_deps : Lib_deps_info.t -> unit t

(** {1 Analysis} *)
Expand Down
15 changes: 11 additions & 4 deletions src/dune/cinaps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Stanza.t += T of t
let syntax =
Dune_lang.Syntax.create ~name:"cinaps" ~desc:"the cinaps extension" [ (1, 0) ]

let alias = Alias.(make (Name.of_string "cinaps"))

let decode =
let open Dune_lang.Decoder in
fields
Expand Down Expand Up @@ -99,9 +101,8 @@ let gen_rules sctx t ~dir ~scope =
~program:{ name; main_module_name; loc }
~linkages:[ Exe.Linkage.native_or_custom (Super_context.context sctx) ]
~promote:None;
Super_context.add_alias_action sctx ~dir ~loc:(Some loc) ~stamp:"cinaps"
(Alias.runtest ~dir)
(let module A = Action in
let action =
let module A = Action in
let cinaps_exe = Path.build cinaps_exe in
let+ () = Build.path cinaps_exe in
A.chdir (Path.build dir)
Expand All @@ -110,4 +111,10 @@ let gen_rules sctx t ~dir ~scope =
:: List.map cinapsed_files ~f:(fun fn ->
let fn = Path.build fn in
A.diff ~optional:true fn
(Path.extend_basename fn ~suffix:".cinaps-corrected")) )))
(Path.extend_basename fn ~suffix:".cinaps-corrected")) ))
in
Super_context.add_alias_action sctx ~dir ~loc:(Some loc) ~stamp:"cinaps"
(alias ~dir) action;
Super_context.add_alias_action sctx ~dir ~loc:(Some loc) ~stamp:"cinaps"
(Alias.runtest ~dir)
(Build.alias (alias ~dir) >>> Build.noop)
30 changes: 22 additions & 8 deletions test/blackbox-tests/test-cases/cinaps/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,30 @@ Test of cinaps integration
> (*$*)
> let x = 1
> "EOF"
sh: line 4: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')

The cinaps actions should be attached to the runtest alias:

$ dune runtest --diff-command diff
sh (internal) (exit 1)
(cd _build/default && /usr/bin/sh -c 'diff test.ml test.ml.cinaps-corrected')
1a2
> hello
[1]

but also to the cinaps alias:

$ dune build @cinaps --diff-command diff
sh (internal) (exit 1)
(cd _build/default && /usr/bin/sh -c 'diff test.ml test.ml.cinaps-corrected')
1a2
> hello
[1]

The cinaps stanza offers a promotion workflow:

$ dune runtest --auto-promote
File "test.ml", line 1, characters 0-0:
Files _build/default/test.ml and _build/default/test.ml.cinaps-corrected differ.
Error: Files _build/default/test.ml and
_build/default/test.ml.cinaps-corrected differ.
Promoting _build/default/test.ml.cinaps-corrected to test.ml.
[1]
$ cat test.ml
(*$ print_endline "\nhello" *)
hello
(*$*)
let x = 1
"EOF"

0 comments on commit 2fda82a

Please sign in to comment.