Search code examples
shake-build-system

shake build without producing a file for every input file


Building .html files from .md files for a web site, I have some .md files which should not produce an output .html (e.g. because not ready for publication). What is the best way to achieve this with shake?

I have a want for html files and a rule which searches the corresponding .md file, but some do not produce the .html and shake stops with the error Error, rule finished running but did not produce file:.

What is the best way to deal with this case?


Solution

  • The current restriction is that every file must produce a result. Some other build systems are slightly more lax about that, but my experience is it's nearly always a source of bugs - although in some cases it is useful (e.g. yours). The options are:

    • If you can easily detect that a file doesn't require an output creating for it you can do that before the want - namely by turning the want into an action that calls need, but only on a subset of the outputs.
    • If detecting you don't need to create anything is expensive you can have a rule that always produces a file, but sometimes produces an empty file, and then a separate rule that depends on that file and copies over only the ones with content.

    Unfortunately, neither of these situations is ideal. At one point Shake had the option to make failure to create a file a valid result, which could be reintroduced if there was sufficient demand.