diff --git a/CHANGES.md b/CHANGES.md index 16c36c5bb00d..bb89ab9f8fb2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/src/dune/alias.ml b/src/dune/alias.ml index b7b766713d82..87ed466acce0 100644 --- a/src/dune/alias.ml +++ b/src/dune/alias.ml @@ -197,6 +197,8 @@ let check = make_standard (Name.of_string "check") let fmt = make_standard (Name.of_string "fmt") +let cinaps = make_standard (Name.of_string "cinaps") + let encode { dir; name } = let open Dune_lang.Encoder in record [ ("dir", Dpath.encode (Path.build dir)); ("name", Name.encode name) ] diff --git a/src/dune/alias.mli b/src/dune/alias.mli index 2e1754591623..1267e8e1e1be 100644 --- a/src/dune/alias.mli +++ b/src/dune/alias.mli @@ -73,6 +73,8 @@ val check : dir:Path.Build.t -> t val fmt : dir:Path.Build.t -> t +val cinaps : dir:Path.Build.t -> t + (** Return the underlying stamp file *) val stamp_file : t -> Path.Build.t diff --git a/src/dune/build.ml b/src/dune/build.ml index 7510f5ed0792..b55a891f6142 100644 --- a/src/dune/build.ml +++ b/src/dune/build.ml @@ -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 = diff --git a/src/dune/build.mli b/src/dune/build.mli index 0126772aed8f..60805c012483 100644 --- a/src/dune/build.mli +++ b/src/dune/build.mli @@ -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} *) diff --git a/src/dune/cinaps.ml b/src/dune/cinaps.ml index 8425e1c3361e..37f3237a379d 100644 --- a/src/dune/cinaps.ml +++ b/src/dune/cinaps.ml @@ -99,9 +99,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) @@ -110,4 +109,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.cinaps ~dir) action; + Super_context.add_alias_action sctx ~dir ~loc:(Some loc) ~stamp:"cinaps" + (Alias.runtest ~dir) + (Build.alias (Alias.cinaps ~dir) >>> Build.noop) diff --git a/test/blackbox-tests/test-cases/cinaps/run.t b/test/blackbox-tests/test-cases/cinaps/run.t index 42442afff8b2..8d34bdf2b537 100644 --- a/test/blackbox-tests/test-cases/cinaps/run.t +++ b/test/blackbox-tests/test-cases/cinaps/run.t @@ -14,16 +14,29 @@ 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 + File "test.ml", line 1, characters 0-0: + Error: Files _build/default/test.ml and + _build/default/test.ml.cinaps-corrected differ. + [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"