【发布时间】:2011-11-15 16:53:36
【问题描述】:
我使用yesod init 生成了一个Yesod 存根网站,并且能够运行yesod devel 进行测试。但是,我通常将实际的haskell 源代码放在主项目目录的子目录src 中,即<project>.cabal 文件所在位置的下一级。
但是,当我将 yesod 站点移动到 src 并更改 cabal 文件以添加行 hs-source-dir: src 时,我收到类似于以下内容的错误 -
src/Model.hs:12:57:
Exception when trying to run compile-time code:
config/models: openFile: does not exist (No such file or directory)
Code: persistFile "config/models"
In the second argument of `share', namely
`$(persistFile "config/models")'
In the expression:
share
[mkPersist sqlSettings, mkMigrate "migrateAll"]
($(persistFile "config/models"))
看起来 Yesod 使用了大量编译时生成的代码,这些代码需要对各个目录的路径进行硬编码。解决此问题的最佳方法是什么?我最理想的做法是不要在整个代码库中硬编码“src”的路径。有没有办法从 cabal 文件本身中读取它?
【问题讨论】: