Use qAddDependentFile when building with template-haskell >= 2.7

Lets the compiler rebuild when embedded files change.
This commit is contained in:
Tristan Ravitch 2012-04-07 12:24:29 -05:00
parent 42b3d61d4c
commit 96e8649a72

View File

@ -23,6 +23,9 @@ import Language.Haskell.TH.Syntax
#endif
, Q
, runIO
#if MIN_VERSION_template_haskell(2,7,0)
, Quasi(qAddDependentFile)
#endif
)
import System.Directory (doesDirectoryExist, doesFileExist,
getDirectoryContents)
@ -42,7 +45,11 @@ import System.IO.Unsafe (unsafePerformIO)
-- > myFile :: Data.ByteString.ByteString
-- > myFile = $(embedFile "dirName/fileName")
embedFile :: FilePath -> Q Exp
embedFile fp = (runIO $ B.readFile fp) >>= bsToExp
embedFile fp =
#if MIN_VERSION_template_haskell(2,7,0)
qAddDependentFile fp >>
#endif
(runIO $ B.readFile fp) >>= bsToExp
-- | Embed a directory recusrively in your source code.
--
@ -61,6 +68,9 @@ getDir = fileList
pairToExp :: (FilePath, B.ByteString) -> Q Exp
pairToExp (path, bs) = do
#if MIN_VERSION_template_haskell(2,7,0)
qAddDependentFile path
#endif
exp' <- bsToExp bs
return $! TupE [LitE $ StringL path, exp']