György Andrasek
György Andrasek

Reputation: 8277

Cabal rebuild on embedded file change

I'm using the file-embed package thusly:

import qualified Data.ByteString as B
import qualified Data.ByteString.Internal as B (w2c)
import qualified Data.FileEmbed as E

initWindow = do
    b <- Gtk.builderNew
    let glade = map B.w2c $ B.unpack $ $(E.embedFile "window.glade") in
        Gtk.builderAddFromString b glade
    ...

Is it possible to make cabal rebuild this file even when only the glade file changes?

Upvotes: 5

Views: 436

Answers (1)

dflemstr
dflemstr

Reputation: 26147

Support for this will be/has been added in GHC 7.4/7.6. The problem is that the compiler doesn't allow TemplateHaskell splices to add file dependencies yet. See this ticket for more information.

When this change lands, you can use the following code to create a new embedFile' function:

import Data.FileEmbed

import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Lib

embedFile' :: FilePath -> Q Exp
embedFile' path = do
  qAddDependentFile path
  embedFile path

This has to be in a separate module from where you use the TH function.

Upvotes: 4

Related Questions