diff --git a/CHANGES.md b/CHANGES.md index cf899ae38ec..1c09a7ebf6f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -119,6 +119,10 @@ Unreleased - Handle "Too many links" errors when using Dune cache on Windows (#6993, @nojb) +- Allow the `cinaps` stanza to set a custom alias. By default, if the alias is + not set then the cinaps actions will be attached to both `@cinaps` and + `@runtest` (#6988, @rgrinberg) + 3.6.2 (2022-12-21) ------------------ diff --git a/src/dune_rules/cinaps.ml b/src/dune_rules/cinaps.ml index 0960dd1ae9d..657ef911afe 100644 --- a/src/dune_rules/cinaps.ml +++ b/src/dune_rules/cinaps.ml @@ -8,17 +8,21 @@ type t = ; preprocessor_deps : Dep_conf.t list ; runtime_deps : Dep_conf.t list ; cinaps_version : Syntax.Version.t + ; alias : Alias.Name.t option } let name = "cinaps" +let cinaps_alias = Alias.Name.of_string name + type Stanza.t += T of t let syntax = Dune_lang.Syntax.create ~name ~desc:"the cinaps extension" - [ ((1, 0), `Since (1, 11)); ((1, 1), `Since (3, 5)) ] - -let alias = Alias.make (Alias.Name.of_string name) + [ ((1, 0), `Since (1, 11)) + ; ((1, 1), `Since (3, 5)) + ; ((1, 2), `Since (3, 7)) + ] let decode = let open Dune_lang.Decoder in @@ -33,6 +37,7 @@ let decode = field ~default:[] "runtime_deps" (Dune_lang.Syntax.since syntax (1, 1) >>> repeat Dep_conf.decode) and+ cinaps_version = Dune_lang.Syntax.get_exn syntax + and+ alias = field_o "alias" Alias.Name.decode (* TODO use this field? *) and+ _flags = Ocaml_flags.Spec.decode in { loc @@ -42,6 +47,7 @@ let decode = ; preprocessor_deps ; runtime_deps ; cinaps_version + ; alias }) let () = @@ -160,9 +166,14 @@ let gen_rules sctx t ~dir ~scope = (Path.Build.extend_basename fn ~suffix:".cinaps-corrected")) )) in - let cinaps_alias = alias ~dir in + let cinaps_alias = + Alias.make ~dir @@ Option.value t.alias ~default:cinaps_alias + in let* () = Super_context.add_alias_action sctx ~dir ~loc:(Some loc) cinaps_alias action in - Rules.Produce.Alias.add_deps (Alias.runtest ~dir) - (Action_builder.alias cinaps_alias) + match t.alias with + | Some _ -> Memo.return () + | None -> + Rules.Produce.Alias.add_deps (Alias.runtest ~dir) + (Action_builder.alias cinaps_alias) diff --git a/test/blackbox-tests/test-cases/cinaps/custom-alias.t b/test/blackbox-tests/test-cases/cinaps/custom-alias.t new file mode 100644 index 00000000000..7a74238e3b4 --- /dev/null +++ b/test/blackbox-tests/test-cases/cinaps/custom-alias.t @@ -0,0 +1,21 @@ +Custom alias for the cinaps + + $ cat > dune-project < (lang dune 3.7) + > (using cinaps 1.2) + > EOF + + $ cat > dune < (cinaps + > (files foo.ml) + > (alias foo)) + > EOF + + $ touch foo.ml + + $ dune build @foo --display short + cinaps .cinaps.a7811055/cinaps.ml-gen + ocamlc .cinaps.a7811055/.cinaps.eobjs/byte/dune__exe__Cinaps.{cmi,cmo,cmt} + ocamlopt .cinaps.a7811055/.cinaps.eobjs/native/dune__exe__Cinaps.{cmx,o} + ocamlopt .cinaps.a7811055/cinaps.exe + cinaps alias foo