haskell 堆栈工具如何检测文件的脏度?

How does the haskell stack tool detect dirtiness of files?

我正在开发一个带有堆栈的 Haskell 项目,该项目生成一个二进制文件,其中静态资产嵌入到可执行文件(例如图像)中。这是通过模板 Haskell 完成的 - 我有一个名为 Static 的模块,它调用一个 TH 函数,该函数读取目录中的文件并将其嵌入。

更新静态资产时,我希望构建过程将更新的文件嵌入到二进制文件中。我试图通过 运行 touch Static.hs; stack build 来实现这一点,即更新调用 TH 然后构建的 haskell 源文件的时间戳。但是,这不会导致堆栈认为需要重建文件。

堆栈(或者可能是底层的 cabal 工具)如何检测源文件是否需要重建,是否有推荐的方法来解决我的上述问题?

调用 qAddDependentFile in your TemplateHaskell. It tells GHC that the module depends on an extra file. Stack also uses that information from GHC to be aware that the package depends on the extra file. The file-embed 包可以轻松嵌入文件,它会为您处理这些细节。