gpt4 book ai didi

haskell - Yesod应用程序源位于子目录中

转载 作者:行者123 更新时间:2023-12-02 19:41:02 26 4
gpt4 key购买 nike

我使用 yesod init 生成了 Yesod stub 网站并能够运行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 文件本身读取它吗?

最佳答案

好吧,您可以编写一些TH代码来解析cabal文件以确定hs-source-dirs,但我认为这太过分了。只需在相关文件路径前面添加一个“..”即可。您还需要编辑设置并使用 glob 函数。

关于haskell - Yesod应用程序源位于子目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7394433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com