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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With