Why is `stack build` altering my .cabal file?

ぐ巨炮叔叔 提交于 2019-12-31 02:20:25

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/47724988/why-is-stack-build-altering-my-cabal-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!