0

I have a package where most of the .hs files are generated from some spec files by a Haskell processor (stored in a subdirectory).

At present this preprocessor is run manually, and so does not work particularly well with version control or when used as part of a larger stack.

I would like Cabal to run this processor, for example from Setup.hs, so that the package can be built using cabal build or by stack as part of a larger project without needing separate manual steps.

The input files are not 1-1 with the output .hs files: instead, a pile of .csv files are read in, and then a differently arranged pile of .hs files are output. I think this means I can't use cabal's preprocessor support.

For my present development purposes I have bodged a call to stack build && stack exec gen-exe at the start of Setup.hs. This runs sometimes too many times (for example it runs on register at the end of a build; and sometimes not enough (for example, it does not run if one of the input .csv files changes, so a manual clean is necessary).

Is this achieveable in cabal, and if so, what do I need to put where to run my build commands frequently enough and not too frequently?

(This is an inherited package... please don't blame me)

Ben Clifford
  • 1,398
  • 1
  • 12
  • 23
  • Have you tried writing your own custom build script (`Setup.hs`?) Cabal only supports a fixed set of preprocessors known to it, anyways. You will have to program the logic for not re-creating your files when there is no need. E.g. see [here](http://stackoverflow.com/questions/7370029/any-example-of-a-custom-preprocessor-in-haskell) and [here](http://stackoverflow.com/questions/16256987/haskell-packaging-cabal-package-with-custom-preprocessors) (these look like duplicates to me. Any reason you think they aren't?) – user2407038 Oct 26 '16 at 13:20
  • I have. The preprocessor support in the question you link is (as I understand it) only one source file => one post-processed Haskell file, which is not how this operates. That's what I meant by: "I think this means I can't use cabal's preprocessor support." That also doesn't address the case where Setup.hs is not run at all because cabal thinks nothing needs rebuilding. – Ben Clifford Oct 26 '16 at 13:57
  • You don't necessarily use `hookedPreProcessors` but maybe `preConf` or `postConf` or whatever suits your needs (hard to tell what those actually are). Even if you used `PreProcessor` you could simply ignore the `FilePath` arguments and find the files yourself (although this seems dirty..). And `Setup.hs` is *always* run when you execute a custom build script, it may just decide that it has nothing to do (but if you put your code in `main` **outside** of the cabal options, it will be run every time) – user2407038 Oct 26 '16 at 14:11
  • ah, maybe it's stack optimising away any invocation of cabal, then. – Ben Clifford Oct 27 '16 at 11:35

0 Answers0