gpt4 book ai didi

haskell - 如何减少 .cabal 文件的构建依赖字段中的重复?

转载 作者:行者123 更新时间:2023-12-01 23:29:30 25 4
gpt4 key购买 nike

这是一个 .cabal 文件:

Name:                myprogram
Version: 0.1
-- blah blah blah
Cabal-version: >=1.9.2

Executable myprogram
HS-source-dirs: src
Main-is: Main.hs
Build-depends: attoparsec == 0.10.*,
base == 4.3.*,
-- long long list of packages

Test-Suite test
HS-source-dirs: test, src
Type: exitcode-stdio-1.0
Main-is: Main.hs
Build-depends: attoparsec == 0.10.*,
base == 4.3.*,
-- long long list of packages
QuickCheck == 2.4.*

有什么方法可以用“与可执行文件相同,加上 QuickCheck”替换测试套件的一长串构建依赖包?

编辑:版本信息。

  • cabal-dev 0.9
  • cabal-install 0.10.2
  • Cabal 库 1.10.2.0
  • GHC 7.0.4
  • Haskell 平台 2011.4.0.0

最佳答案

注意:被 phadej 建议常见节的答案取代。

<小时/>

Is there any way I can replace the long list of build-depends packages for the test suite with "same as for the executable, plus QuickCheck"?

据我所知,没有。但是,有一种方法可以通过将项目构建为三个目标来仅提及一次 build-depends 包列表:

  1. 一个包含所有代码的库,并且需要很长的构建依赖项列表。
  2. 一种可执行文件,仅包含一个文件,并且依赖于上面的基础和库。
  3. 依赖于上面的库以及您正在使用的测试包的测试套件。

也许这种方法就是 indygemma 的答案所建议的,但正如 Norman Ramsey 在评论中指出的那样,那里提出的 Cabal 文件并不能完全实现它。以下是 Cabal 文件中所需内容的要点。对于适合我的完整示例,您可以查看 this Cabal file .

name: my-program
version: ...

library
hs-source-dirs: src-lib
build-depends: base, containers, ...
exposed-modules: My.Program.Main, ...

executable my-program
hs-source-dirs: src-exec
main-is: my-program.hs
Build-depends: base, my-program

test-suite tests
type: exitcode-stdio-1.0
hs-source-dirs: src-test
main-is: tests.hs
other-modules: ...
build-depends: base, my-program, test-framework, ...

要点:

  • 这三个目标有三个独立的源目录。这对于在构建其他目标时阻止 GHC 重新编译库文件是必要的。

  • 所有应用程序代码都在库中。可执行文件只是一个包装器,如下所示:

    import My.Program.Main (realMain)
    main = realMain
  • 该库公开了测试所需的所有模块。

最后一点强调了这种方法的缺点:您最终必须公开内部模块。这种方法的主要好处是减少了 Cabal 文件中的重复,也许更重要的是,减少了构建过程中的重复:库代码将仅构建一次,然后链接到可执行文件和测试套件中.

关于haskell - 如何减少 .cabal 文件的构建依赖字段中的重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10163604/

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