
On Mon, 2007-05-28 at 20:35 +0100, Neil Mitchell wrote:
Hi Duncan,
list the support files in the "data-files:" stanza in the .cabal file. Then import the Paths_<pkg> module that Cabal generates for you. It exports a few functions including:
getDataDir :: IO FilePath
A few questions:
1) How do I test this? I'll need to develop in Hugs and GHC without going through Cabal building. Should I fake up a Paths_<pkg> module?
Or just use cabal and copy the .hs module it generates.
2) Is there any reasonable limit on the number of data files? Is 1000 too many?
They have to be listed in the .cabal file, so you might get bored adding them all and decide to send in a patch to support glob/wildcards :-)
3) Can I create files in this DataDir directory?
Probably not necessarily. For example if under unix you install the package globally then the data dir will probably be in some read-only directory under /usr/share. If it's a per-user install it might be writable. For per-user writable stuff you probably want getAppUserDataDirectory from System.Directory.
It does seem that creating a new Paths_<pkg> module and include it is not very pleasant. It requires everyone to compile from source to get the paths working, which doesn't make much sense.
As Isaac mentioned, on windows it is relocatable I think. You can see the code than Cabal generates. If you want patches so it'll work with yhc without using #ifdefs and using dynamic tests instead then I'm happy to look at patches that do that. This isn't set in stone and if you have better general workable solutions then do suggest them. Duncan