gpt4 book ai didi

haskell - 使用带有 cabal 的 Makefile?

转载 作者:行者123 更新时间:2023-12-04 08:52:33 28 4
gpt4 key购买 nike

我正在做一个玩具项目,以此将我对 Haskell 的享受从理论转移到实践,让自己对 cabal 更加满意, HUnit , ETC。

我刚刚在我的项目中添加了一个 Makefile:

test: dist/build
cabal-dev test

dist/build: dist/setup-config src/*.hs tests/*.hs
cabal-dev build
touch dist/build

dist/setup-config: ToyProject.cabal
cabal-dev configure --enable-tests

因为:
  • cabal-dev install --enable-tests看起来有点矫枉过正(并警告我重新安装)
  • cabal-dev configure --enable-tests && cabal-dev build && cabal-dev test正在做不必要的工作,并且保持关于我是否需要重新配置的状态很无聊
  • 两人都打了很多字

  • 我担心我可能会使用 Make that cabal 重新创建功能或 cabal-dev已经给了我,但是
    我对两者都不够熟悉,不知道这是否属实,如果是,我会怎么做。

    Makefile 在这里是否合适,或者是否有更直接的方法来执行此操作,只需使用 cabal/ cabal-dev ?

    最佳答案

    下面是我与 Cabal 包一起使用的 Makefile 的简化版本
    我正在与另一个依赖于的 Haskell 程序并行开发
    在 Cabal 包上(我经常并行编辑它们,所以我有
    Cabal 包作为程序的构建依赖项,使用另一个
    生成文件:P)。目标是:

  • 只运行 cabal如果某些源文件实际上已更改。我
    在一个非常慢的上网本上使用这个 Makefile
    依赖解决步骤需要 10 秒,所以我想
    避免运行 cabal install如果可能的话。
  • 在单独的构建中进行独立调试和定期构建
    目录默认情况下,如果您使用分析进行 Cabal 构建
    ( --ghc-options=-fprof-auto ),然后是一个没有分析的,
    Cabal 将重新开始,从头开始重新编译所有文件。
    将构建放在单独的构建目录中可以避免这个问题。

  • 我不确定 (2) 是否对您感兴趣,但 (1) 可能是,我明白了
    你只在成功而不是失败时触摸构建目录,而我
    预计这将无法正常工作。

    这是生成文件:
    cabal-install: dist

    cabal-install-debug: prof-dist

    # You will need to extend this if your cabal build depends on non
    # haskell files (here '.lhs' and '.hs' files).
    SOURCE = $(shell find src -name '*.lhs' -o -name '*.hs')

    # If 'cabal install' fails in building or installing, the
    # timestamp on the build dir -- 'dist' or 'prof-dist', stored in
    # the make target variable '$@' here -- may still be updated. So,
    # we set the timestamp on the build dir to a long time in the past
    # with 'touch --date "@0" $@' in case cabal fails.
    CABAL_INSTALL = \
    cabal install $(CABAL_OPTIONS) \
    || { touch --date "@0" $@ ; \
    exit 42 ; }

    dist: $(SOURCE)
    $(CABAL_INSTALL)

    # Build in a non-default dir, so that we can have debug and non-debug
    # versions compiled at the same time.
    #
    # Added '--disable-optimization' because '-O' messes with
    # 'Debug.Trace.trace' and other 'unsafePerformIO' hacks.
    prof-dist: CABAL_OPTIONS += --ghc-options="-fprof-auto" --builddir=prof-dist --disable-optimization
    prof-dist: $(SOURCE)
    $(CABAL_INSTALL)

    关于haskell - 使用带有 cabal 的 Makefile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18649427/

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