Stream: Dune devs & users

Topic: Generated files in version control


view this post on Zulip Karl Palmskog (Sep 04 2020 at 08:53):

Let's say I have a file src/template that is used to generate the file theories/result.v using some tool that is difficult to run, and I add a rule

(rule
 (target result.v)
 (deps ../src/template)
 (action (run <complicated-tool-command>)))

To avoid everyone having to run this tool and this command, I add theories/result.v into version control. This works fine using a Makefile. However, dune will complain:

Error: Multiple rules generated for
_build/default/theories/result.v:
- file present in source tree
- theories/dune:XX
Hint: rm -f theories/result.v

How can I avoid this error and get the usual make behavior, i.e., result.v is only regenerated if it is older than template?

view this post on Zulip Rudi Grinberg (Sep 04 2020 at 09:07):

You have two options:

view this post on Zulip Rudi Grinberg (Sep 04 2020 at 09:24):

To avoid everyone having to run this tool and this command

It also depend on how users are using your library. If they are just cloning it running $ dune build, I recommend the 2nd approach. If they are installing it from opam, then the 1st approach is better.

view this post on Zulip Karl Palmskog (Sep 04 2020 at 10:07):

thanks, I'm going with fallback for now, this looks as follows for the benefit of others reading this:

(rule
 (target result.v)
 (deps ../src/template)
 (action (run <complicated-tool-command>))
 (mode fallback))

view this post on Zulip Rudi Grinberg (Sep 04 2020 at 19:50):

Sounds good. Just for reference, fallback was added to support ./configure like configuration. The idea would be that you'd have a ./configure script that would generate config.ml in the source. Without this step, there would be a fallback rule to create a default configuration.


Last updated: Jun 03 2023 at 18:01 UTC