Skip to content

Commit

Permalink
feature(rules): custom alias for cinaps
Browse files Browse the repository at this point in the history
Allow setting the alias used to run cinaps actions.

This is done to override the behavior of attaching the cinaps action to
both the `cinaps` and `runtest` aliases.

Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: d35a6315-e4ef-40d1-9527-783dcd82029a -->
  • Loading branch information
rgrinberg committed Feb 4, 2023
1 parent f7cf8d4 commit f52444b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ Unreleased
- Fix dependency cycle when installing files to the bin section with
`glob_files` (#6764, fixes #6708, @gridbugs)

- 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)
------------------

Expand Down
23 changes: 17 additions & 6 deletions src/dune_rules/cinaps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -42,6 +47,7 @@ let decode =
; preprocessor_deps
; runtime_deps
; cinaps_version
; alias
})

let () =
Expand Down Expand Up @@ -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)
21 changes: 21 additions & 0 deletions test/blackbox-tests/test-cases/cinaps/custom-alias.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Custom alias for the cinaps

$ cat > dune-project <<EOF
> (lang dune 3.7)
> (using cinaps 1.2)
> EOF

$ cat > dune <<EOF
> (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

0 comments on commit f52444b

Please sign in to comment.