为什么`stack build`改变我的.cabal文件? [英] Why is `stack build` altering my .cabal file?

查看:111
本文介绍了为什么`stack build`改变我的.cabal文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个项目,使用 Euterpea
$ b

运行 stack build 我得到以下错误,提示我需要添加 Euterpea 添加到我的 .cabal 文件的 build-depends 部分。 / b>

  $ sb 
合成-0.1.0.0:编译(lib + exe)
预处理库合成-0.1 .0.0 ...
编译库(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:错误:
无法载入'Euterpea'接口
它是隐藏的软件包'Euterpea-2.0.4'。
也许你需要在你的.cabal文件的build-depends中添加'Euterpea'。
使用-v查看搜索的文件列表。

- 使用时:
/home/matthew/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_1.24.2构建软件包合成-0.1.0.0。 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
用代码退出进程:ExitFailure 1

我添加 Euterpea 那里以及我的 .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语法的新文件格式,由
Stack支持hpack和 stack build 命令一样强大使用 hpack 命令自动将package.yaml转换为cabal文件。 因此,删除 package.yaml 或编辑 package.yaml 来添加Euterpea软件包。
编辑它不会像格式是YAML那样困难。


I am attempting to build a project which uses Euterpea.

Running stack build I get the following error, suggesting that I need to add Euterpea to the build-depends section of my .cabal file.

$ 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

I add Euterpea there, and the library section of my .cabal file then is the following.

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

However, when I then run stack build again, it gives the same error -- and changes my .cabal file back to what it was originally, with the library section then looking like

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

Why is stack build altering my cabal file? I have never seen that occurring before.


Side note: Not sure if it is related, but the .cabal file's format appears to be different than it normally does. Here as with previous projects I auto-initialized by running stack new <project-name>. I don't know what I might have done different from previous projects to cause this unexpected behavior of stack build.

解决方案

Make sure package.yaml exists in the root of your project directory.

package.yaml is a new file format to improve the syntax of cabal, converted by hpack.

Stack supports hpack as strongly as the stack build command automatically converts package.yaml into a cabal file with hpack command.

So, delete package.yaml or edit package.yaml to add Euterpea package. Editing it would not be so difficult as its format is YAML.

这篇关于为什么`stack build`改变我的.cabal文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆