user1887615
user1887615

Reputation: 123

cabal: how to add text file as a build dependency

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)

Upvotes: 6

Views: 775

Answers (1)

user1065942
user1065942

Reputation:

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

Upvotes: 2

Related Questions