简体   繁体   English

构建haskell软件包时如何获取堆栈以运行额外的命令?

[英]How to get stack to run extra commands when building a haskell package?

I had made a script for compiling my haskell programs (so far just simple scripts consisting in a single source file) that contained, before the call to ghc, the following lines: 我制作了一个脚本来编译我的haskell程序(到目前为止,只是一个包含在单个源文件中的简单脚本),该脚本在调用ghc之前包含以下几行:

echo "Running hlint"
hlint ${1}
echo "Running scan"
~/.cabal/bin/scan -j False ${1}
echo "Running doctest"
~/.cabal/bin/doctest ${1}

( ${1} referring to the single .hs source file.) ${1}指单个.hs源文件。)

How to get some equivalent checking done when using stack to manage and build my programs? 使用堆栈管理和构建程序时,如何进行等效检查?

I would like to setup some global configuration that would have these commands run automatically on the source code when calling stack build in any of my projects. 我想设置一些全局配置,当在我的任何项目中调用stack build时,这些命令将在源代码上自动运行。

Stack provides a --exec flag which allows you to do this. Stack提供了--exec标志,您可以执行此操作。 Check the 'Flags' documentation for a full example, but we can see a command like: 查看“标志”文档中的完整示例,但是我们可以看到类似以下的命令:

$ stack build --test --exec "echo Hi!"

Where --exec is the 'do other stuff' and --test runs the tests. --exec是“做其他事情”,而--test运行测试。

Related to your example, it could look like: 与您的示例相关,它可能类似于:

stack build \
  --exec "hlint foo" \
  --exec "~/.cabal/bin/scan -j False bar"
  --exec "~/.cabal/bin/doctest baz"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM