Wrong relative paths in error messages when building a multi-package project
Describe the bug
We have a multi-package repository https://github.com/IntersectMBO/plutus
Packages are sub-directories at project root.
packages:
plutus-benchmark
plutus-conformance
plutus-core
...
Usually I am building inside the project's root directory.
cd clonedrepo/plutus/
cabal build all
cabal build plutus-core # for a specific package
The problem is that in case GHC compilation fails, the GHC error messages contain paths
not relative to where I am building at the moment (that is the project's root directory).
The path is relative to the specific package under compilation and not relative to $PWD
To Reproduce
As an example after editing a file,
plutus-core/src/PlutusCore/Data.hs:12:29: error:
Module ‘Codec.CBOR.Decoding’ does not export ‘Decoderm’
|
12 | import Codec.CBOR.Decoding (Decoderm,)
| ^^^^^^^^
The path plutus-core/src/PlutusCore/Data.hs:12:29 is wrong relative to my $PWD (project root) that I am currently building in.
Expected behavior
I would expect that Cabal and GHC would print the correct path relative to where I am building at the moment, which is
plutus-core/plutus-core/src/PlutusCore/Data.hs
It seems that the package parent directory is omitted from the error messages.
It "feels" like cabal-install is cding to the package, building it as a normal Cabal package, then cding back out directory, roughly like:
cd ./plutus-core/
cabal build
cd ../
The problem arises when needing to navigate to these errors source spans. They do not reflect the $PWD that is returned after cabal is aborted/completed. Editors such as emacs (and its compilation mode) have difficulty figuring out the correct path to navigate to.
System information
- Operating system
cabal-3.12.1,ghc-9.6.7versions
Additional context
I searched in GHC for flag that can print absolute filepaths under compilation. But it does not seem to be such an option: https://downloads.haskell.org/ghc/latest/docs/users_guide/flags.html#verbosity-options
ghc would need to do this, but there is currently no way to tell it to prepend something to all paths in error messages.
Hypothetically we could postprocess output, but that would introduce buffering delays (no reliable/portable way to tell ghc not to buffer stderr if it's not going to a terminal) and might either miss paths or prepend to things that happen to look like paths but aren't.
There is ongoing work to decouple the Cabal library from PWD which will ultimately be able to help these kinds of issues.
See https://github.com/haskell/cabal/pull/9871 for the main part of the work.