Dune: Update vs create target

I’d like for dune to

  1. Create the Menhir parser.messages file it it does not exist and
  2. Update the parser.messages file if it does and my parser.mly has changed.

I defined two rules

(rule
 (targets parser.messages)
 (mode fallback)
 (action
  (with-stdout-to
   %{targets}
   (run menhir --list-errors %{targets}))))

(rule
 (targets parser.messages)
 (deps parser.mly)
 (action
  (with-stdout-to
   %{targets}
   (run menhir --update-errors %{targets}))))

but this doesn’t work since dune requires 1 rule to target 1 file.

Can I have my cake and eat it too?

Looks like I misunderstood how Menhir works.

Dune support for .messages is being worked on: Add `.messages` support for Menhir by nojb · Pull Request #11753 · ocaml/dune · GitHub. You may find useful information there. And I encourage you to chime in if you have any suggestions.

You may also find useful information in the following post: Dune wish list for 2023 - #60 by zozozo.

Cheers,
Nicolas

2 Likes

It’s worth mentioning that the general solution for the Dune question (not specific to Menhir) is that you have to create an intermediary file for each rule, e.g. print --list-errors to parser.messages.list. You only need to promote the final file, parser.messages, to your source tree.

1 Like