Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cabal: how to add text file as a build dependency

Tags:

haskell

cabal

I use a simple text file to generate some code with TemplateHaskell and runIO.

...    
curdir <- runIO $ getCurrentDirectory
addDependentFile $ curdir ++ "/spec.txt"
bs <- runIO $ BS.readFile "spec.txt"
...

Everything works great when used with ghci. The problem is that cabal has no idea I need that file for building, and I get this when I do cabal build.

Exception when trying to run compile-time code:
  spec.txt: openFile: does not exist (No such file or directory)
like image 301
user1887615 Avatar asked Mar 31 '13 15:03

user1887615


1 Answers

take a look at flag data-files:

http://www.haskell.org/cabal/users-guide/developing-packages.html#accessing-data-files-from-package-code

by the way, I recommend EclipseFP for your jobs. It provide a convenient way to edit cabal file. that's why i can find that flag. It really reduce trivial works.

http://www.haskell.org/haskellwiki/Haskell_IDE#EclipseFP_plugin_for_Eclipse_IDE

=============================================================================

sorry for misunderstanding.

I think cabal doesn't really matter here. ghc runs openFile at compile-time.

that means openFile is still runned at another "run-time" to produce code.

the "run-time" result is just can't find the file

maybe the current directory is not as you think.

try to use setCurrentDirectory or show curdir and check it before getCurrentDirectory

if it doesn't work. please show whole code for testing

like image 167
snow Avatar answered Nov 06 '22 16:11

snow