@@ -91,24 +91,29 @@ embedFile fp =
9191
9292-- | Maybe embed a single file in your source code depending on whether or not file exists.
9393--
94−-- Warning: Does not use `qAddDependentFile` to force a recompile depending on changes to or appearance of the file.
94+-- Warning: When a build is compiled with the file missing, a recompile when the file exists might not trigger an embed of the file.
95+-- You might try to fix this by doing a clean build.
9596--
9697-- > import qualified Data.ByteString
9798-- >
9899-- > maybeMyFile :: Maybe Data.ByteString.ByteString
99100-- > maybeMyFile = $(embedFileIfExists "dirName/fileName")
100101embedFileIfExists :: FilePath -> Q Exp
101−embedFileIfExists fp = runIO maybeFile >>= maybeBsToExp
102+embedFileIfExists fp = do
103+ mbs <- runIO maybeFile
104+ case mbs of
105+ Nothing -> [| Nothing |]
106+ Just bs -> do
107+#if MIN_VERSION_template_haskell(2,7,0)
108+ qAddDependentFile fp
109+#endif
110+ [| Just $(bsToExp bs) |]
102111 where
103112 maybeFile :: IO (Maybe B.ByteString)
104113 maybeFile =
105114 either (const Nothing) Just <$>
106115 tryJust (guard . isDoesNotExistError) (B.readFile fp)
107116
108− maybeBsToExp :: Maybe B.ByteString -> Q Exp
109− maybeBsToExp Nothing = [| Nothing |]
110− maybeBsToExp (Just bs) = [| Just $(bsToExp bs) |]
111−
112117-- | Embed a single existing file in your source code
113118-- out of list a list of paths supplied.
114119--