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/47724988/

相关文章:

linux - Yesod haskell-stack 安装-fPIC

haskell - Cabal configure 在 cabal 沙箱中找不到已安装的包

haskell - Cabal 在 NixOS 上构建时找不到外部库

haskell - 如何使用stack镜像容器?

haskell - 堆栈 : how to build with lts-13. 2?我想使用较新的库

json - 使用 lens-aeson 提取 JSON 字段时结合棱镜

javascript - 为什么 JavaScript 中的逻辑运算符是左结合的?

haskell - 开始使用 Yesod

string - SplitAt 3 然后继续 split

haskell - stack.yaml 文件是否应该检查到版本控制中?