Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(rules): custom alias for cinaps #6991

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------

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