Search code examples
haskellcode-generationcabal

How to create haskell cabal package as output of haskell code?


The Haskell project I am working on generates code(and tests for it) that is intended to be used as an independent Haskell library. I want to wrap it in a cabal project, so it can be included as a dependency.

I searched for a library interface for the cabal, so I can create a cabal project at a given directory by calling some functions, but found none.

I could, of course, just run bash commands from Haskell, but it looks ugly to me.

Is there any tool that will solve my problem in a nice way?


Solution

  • You want the Cabal package. You can parse an existing cabal file, change stuff in the data structures, and regenerate the text representation.

    Edit in answer to comment:

    I don't know of any tutorials. The links I gave are for the Haddock docs, and the mapping between data types and Cabal file text is pretty straightforward. So you should probably start by writing the code to produce a PackageDescription value and then call writePackageDescription on it.

    Note the existence of emptyPackageDescription, which lets you just specify the fields you want.

    (Removed link to pretty printer class because PackageDescription isn't a member.)