tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

installing as a build-tool-depends fails (cabal bug?) #534

Closed symbiont-sam-halliday closed 4 years ago

symbiont-sam-halliday commented 4 years ago

If I add ormolu as a

  build-tool-depends:
    , ormolu:ormolu ==0.0.3.1

in my project, and use a cabal.project.freeze file that corresponds to https://www.stackage.org/lts-15.5 (e.g. by using http://hackage.haskell.org/package/stack2cabal on a stack.yaml frozen to that LTS or by downloading their partial freeze files) then I get a compilation error when building ormolu

$ cabal build :pkg:ormolu:exe:ormolu
...
src/GHC/DynFlags.hs:11:1-15: error:
    Could not load module ‘Platform’
    It is a member of the hidden package ‘ghc-lib-parser-8.8.3.20200224’.
    Perhaps you need to add ‘ghc-lib-parser’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘ghc-lib-parser-8.8.3.20200224’.
    Perhaps you need to add ‘ghc-lib-parser’ to the build-depends in your .cabal file.
    It is a member of the hidden package ‘ghc-8.8.3’.
    Perhaps you need to add ‘ghc’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
   |
11 | import Platform

The weird thing is that it compiles fine if I do cabal install ormolu from here (which uses the exact same frozen dependencies).

It also works fine for me if I do a cabal install ormolu-0.0.3.1 from my home directory (which doesn't use the freeze file).

This is almost certainly a cabal bug of some kind, but since this disproportionatly impacts ormolu, I am hoping that somebody here might have encountered it and have a fix?

Obviously the workaround is to install ormolu globally for the user, but it is so much better to have the formatter pegged to the project so that anybody can check it out and run cabal exec ormolu -- ... to get the exact same formatting, which simplifes linter scripts, editor integration, multiple projects, and going back to work on old branches, and all sorts of things.

mrkkrp commented 4 years ago

I don't know what is going on here, and it doesn't look like an Ormolu-specific issue, so closing.

symbiont-sam-halliday commented 4 years ago

I started trying to create a minimal repro to report upstream with cabal-install and was unable to get the failure to repeat. Now I'll investigate what project-specific thing might be relevant here... sorry for the noise.

symbiont-sam-halliday commented 4 years ago

Argh, I narrowed it down to the use of allow-newer in the cabal.project which is autogenerated by stack2cabal in order to workaround the fact that stack often allows this.

I've backlinked the cabal bug to here so that anybody else encountering this knows what the cause is, and a potential workaround. Remove the allow-newer if you can.

symbiont-sam-halliday commented 4 years ago

And fixed in upstream stack2cabal which turned out to be producing freeze files that were not correctly freezing the build-tool-depends.