haskell - 为什么 `stack build` 会更改我的 .cabal 文件?

标签 haskell cabal haskell-stack euterpea

我正在尝试构建一个使用 Euterpea 的项目.

正在运行 stack build我收到以下错误,提示我需要添加 Euterpeabuild-depends我的部分 .cabal文件。

$ sb
composition-0.1.0.0: build (lib + exe)
Preprocessing library composition-0.1.0.0...
[2 of 2] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0/build/Lib.o )

/home/matthew/backup/composition/composition/src/Lib.hs:5:1: error:
    Failed to load interface for ‘Euterpea’
    It is a member of the hidden package ‘Euterpea-2.0.4’.
    Perhaps you need to add ‘Euterpea’ to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

--  While building package composition-0.1.0.0 using:
      /home/matthew/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0 build lib:composition exe:composition-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

我添加 Euterpea那里,还有library我的部分 .cabal文件如下。

library
  hs-source-dirs:
      src
  build-depends:   base >= 4.7 && < 5
                 , Euterpea
  exposed-modules:
      Lib
  other-modules:
      Paths_composition
  default-language: Haskell2010

但是,当我运行 stack build 时同样,它给出了同样的错误——并改变了我的 .cabal使用 library 将文件恢复到原来的状态部分然后看起来像

library
  hs-source-dirs:
      src
  build-depends:
      base >= 4.7 && < 5
  exposed-modules:
      Lib
  other-modules:
      Paths_composition
  default-language: Haskell2010

为什么是stack build改变我的 cabal文件?我以前从未见过这种情况。


边注: 不确定是否相关,但 .cabal文件的格式似乎与通常不同。与以前的项目一样,我通过运行 stack new <project-name> 自动初始化.我不知道我可能做了哪些与以前的项目不同的事情来导致 stack build 的这种意外行为.

最佳答案

确保 package.yaml 存在于您的项目目录的根目录中。

package.yaml是一种改进cabal语法的新文件格式,由hpack转换而来.

Stack 对 hpack 的支持与 stack build 命令一样强烈,可以使用 hpack 命令自动将 package.yaml 转换为 cabal 文件。

因此,删除 package.yaml 或编辑 package.yaml 以添加 Euterpea 包。 编辑它不会那么困难,因为它的格式是 YAML。

关于haskell - 为什么 `stack build` 会更改我的 .cabal 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47819202/

相关文章:

haskell - 对于高性能应用服务器,我应该选择Yesod的Warp和snap-server中的哪一个?

installation - 安装 darcsden

haskell - 从哪里开始 "Couldn' t 将类型 MyId 与 MyId 匹配”

haskell - 获取 Parsec 的左输入

list - 将我自己类型的项目添加到 Haskell 的列表中?

list - 为什么我得到 "Exception: Prelude.head: empty list"?

haskell - 安装 Happy 时出现问题

haskell - Cabal 库与 cabal 安装。有什么不同?

haskell - 如何使用堆叠凳?

haskell - 更改堆栈上的 ghci 版本