我使用生成了一个 Yesod 存根网站yesod init
,并且能够运行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 文件本身中读取它?