[Haskell-cafe] How to use cabal's data-files feature and run in-place?

Antoine Latter aslatter at gmail.com
Fri Apr 22 06:27:10 CEST 2011


On Thu, Apr 21, 2011 at 8:46 PM, Richard Cobbe <cobbe at ccs.neu.edu> wrote:
> I'm running Haskell Platform 2011.2.0.1 on a MacOS 10.6.7 machine (the
> machine is 64-bit, but I'm running the 32-bit platform).
>
> I'm writing an application for personal use, and I'd like to use Cabal to
> package it up and handle installation.  This way, when I'm working on the
> program, I won't break the reasonably stable installed version and can
> continue to use it.
>
> (I'm not committed to cabal by any means; suggestions for other ways to
> accomplish the same thing are more than welcome!)
>
> I've got some data files I'd like to package with the application, and
> Cabal's data-files field is the obvious way to do that.  The immediate
> problem, then, is how to access the files -- I can use the generated
> Paths_pkg module for the "installed" copy of the app, but then I can't run
> the thing in-place in ghci in the development directory.
>
> I did some googling and came across a blog post
> (http://neilmitchell.blogspot.com/2008/02/adding-data-files-using-cabal.html)
> which suggested that I provide my own Paths_pkg.hs file that points to the
> files' location in the development copy.  When I build with Cabal, the
> generated form of this module would override my hand-written one, and it
> should therefore work in the installed case as well.
>
> Unfortunately, that's not happening.  Cabal is clearly generating the
> module; I can see it in dist/build/autogen.  But my copy is overriding the
> autogenerated one, even for cabal builds -- at least, that's what I'm
> seeing when I run the binary out of dist/build/<package>/<executable>.
>
> Is there a way to be able to use data files in both contexts?
>
> FWIW, I'm running cabal as
>
>    runhaskell Setup.hs configure --user
>    runhaskell Setup.hs build

1. A side note - using the 'cabal' command line tool is easier for
many tasks than 'runhaskell Setup'. In particular, it does a user
install by default.

2. Here's what I do for the paths situation:

In the package description, create a CPP option so you know you're
compiling via Cabal:

> Cpp-options: -DCABAL

Then create a module to wrap around the autogenerated paths module,
making sure to put the CPP Language pragma at the top:

> {-# LANGUAGE CPP #-}

You can then use #ifdef CABAL to decide to re-export the Cabal
autogenerated paths functionality, or to use the ones you've written
yourself (based on the current directory or whatever you need).

I hope that this helps! I don't have any examples on hand at the moment.

Antoine

>
> Thanks much,
>
> Richard
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



More information about the Haskell-Cafe mailing list