如何根据Yesod应用程序构建程序

时间:2016-12-26 17:48:58

标签: haskell yesod haskell-stack

我使用stack new project yesod-postgres创建了Yesod应用程序。在Web应用程序旁边,我想创建另一个使用相同数据库模型和数据库连接的程序。

我在cabal文件中添加了第二个executable部分(第一部分的副本),其名称与main-is: myprogram.hs不同。我现在可以成功运行stack build && stack exec myprogram

问题是构建总是花费超过1分钟:

$ stack build
project-0.0.0: unregistering
yesod-persistent-1.4.0.6: configure
yesod-persistent-1.4.0.6: build
yesod-persistent-1.4.0.6: copy/register
yesod-form-1.4.9: configure
yesod-form-1.4.9: build
yesod-form-1.4.9: copy/register
yesod-auth-1.4.15: configure
yesod-auth-1.4.15: build
yesod-auth-1.4.15: copy/register
yesod-1.4.3.1: configure
yesod-1.4.3.1: build
yesod-1.4.3.1: copy/register
classy-prelude-yesod-0.12.8: configure
classy-prelude-yesod-0.12.8: build
classy-prelude-yesod-0.12.8: copy/register
project-0.0.0: build
Preprocessing library project-0.0.0...
In-place registering project-0.0.0...
Preprocessing executable 'myprogram' for project-0.0.0...
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/myprogram/myprogram ...
Preprocessing executable 'project' for project-0.0.0...
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/project/project ...
project-0.0.0: copy/register
Installing library in
/home/jakob/projects/project/project/.stack-work/install/x86_64-linux/lts-6.27/7.10.3/lib/x86_6
4-linux-ghc-7.10.3/project-0.0.0-1qruVQVcU0k2yXxF1Z1w7r
Installing executable(s) in
/home/jakob/projects/project/project/.stack-work/install/x86_64-linux/lts-6.27/7.10.3/bin
Registering project-0.0.0...
Completed 6 action(s).

如何加快构建过程?我怎样才能防止堆栈每次都重建yesod依赖?

1 个答案:

答案 0 :(得分:3)

这不是特定于添加第二个可执行文件;即使是使用单个可执行文件的新yesod-postgres项目,也会发生这种情况。

相反,它似乎是Stack的lts-6.27包集(可能还有其他?)中的错误。这是一个解决方法。在stack.yaml中,添加以下extra-dep:

extra-deps:
- yesod-persistent-1.4.0.6

并运行stack build。然后,第二个stack build应该运行而不重建任何东西。