4

我使用生成了一个 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 文件本身中读取它?

4

1 回答 1

0

好吧,您可以编写一些 TH 代码来解析 cabal 文件以确定 hs-source-dirs,但我认为这太过分了。只需在有问题的文件路径前加上“..”即可。您还需要编辑设置并使用 glob 功能。

于 2011-09-13T02:53:19.943 回答