Self-tuning with Cabal

Introduce the Makefile as shown below:

stage1 : Stage1.hs ghc -o stage1 Stage1.hs Stage1.hs : stage0 stage0 > Stage1.hs stage0 : Stage0.hs ghc -o stage0 Stage0.hs 

The current directory will first contain Makefile and Stage0.hs, as well as create stage1.

Here are the questions:

  • How can I do this completely inside Cabal? Should I only do this with hooks? (for example, this or this .) What if the hook needs to depend on another program in the package to be created?
  • What if Setup.hs becomes so complex that it requires its own dependency management?
  • Is there a bonded package that does similar things? If Happy included a cabalized test program that depended on Happy Call, that would be a great example.
+8
haskell cabal
source share
1 answer

Bondage is difficult when it comes to such situations.

As you said, if you can squeeze everything into Setup.hs , you can minimize the amount of headaches.

If you have really complex preprocessors, I would suggest doing this:

  • Make one package for each preprocessor with its own dependencies, etc. Thus, for stage0 you will have a file-bondage:

     Name: mypackage-stage0 Version: 0.1 -- ... Executable mpk-stage0 Default-language: Haskell2010 Main-is: Stage0.hs -- ... 
  • For stage1 you need to generate the source code, so add a Setup.hs to Setup.hs for mypackage-stage1 that launches the mpk-stage0 :

     main = defaultMainWithHooks simpleUserHooks { preBuild = -- ... something involving `system "mpk-stage1 Stage1.hs"` -- Note that shell redirection `> bla.hs` doesn't necessarily work -- on all platforms, so make your `mpk-stage1` executable take an -- output file argument } 

    Then you add the dependency based on the assembly in the previous step:

     Executable mpk-stage1 -- ... Main-is: Stage1.hs Build-tools: mypackage-stage0 

    This should work in recent versions of cabal; otherwise, you may need to add a Build-depends: dependency.

  • You will need to rebuild each package in turn each time you perform a cascading change (this is necessary because cabal does not manage dependency changes between projects), so you need a script that does for project in mypackage-stage0 mypackage-stage1; do (cd $project; cabal install); done for project in mypackage-stage0 mypackage-stage1; do (cd $project; cabal install); done for project in mypackage-stage0 mypackage-stage1; do (cd $project; cabal install); done or something like that.

Cabal was never built for such a project, so it will be difficult if you want to do something like this. You should consider using the Haskell template instead if you want to generate code in a more consistent way.

+5
source share

All Articles