为什么`stack build`改变我的.cabal文件?

mhe*_*rzl 3 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
Run Code Online (Sandbox Code Playgroud)

我在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
Run Code Online (Sandbox Code Playgroud)

然而,当我再次运行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
Run Code Online (Sandbox Code Playgroud)

为什么要stack build改变我的cabal档案?我以前从未见过这种情况.


附注:不确定它是否相关,但.cabal文件的格式似乎与通常不同.与之前的项目一样,我通过运行自动初始化stack new <project-name>.我不知道我可能做的与以前的项目有什么不同,导致这种意想不到的行为stack build.

Yuj*_*oto 7

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

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

Stack支持hpack,stack build命令会自动将package.yaml转换为cabal文件hpack.

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

  • 哇哦,这真的有助于解释我生命的最后几分钟! (2认同)