haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.62k stars 697 forks source link

Feature request: absolute paths in ghc errors #6670

Open symbiont-sam-halliday opened 4 years ago

symbiont-sam-halliday commented 4 years ago

ghc will report errors and warnings in files relative to the hs-source-dirs that is declared in the .cabal file. This typically results in minimal output relative to the location of the .cabal file.

However, there are many workflows where this can result in problems, especially if the user invokes cabal build from a different directory which is common in multi-project builds.

It would be good if there was a cabal.project{.local} option made available that caused cabal to construct the absolute path of hs-source-dirs prior to invoking ghc.

phadej commented 4 years ago

This is a perfect issue to solve after https://github.com/haskell/cabal/issues/6667. Before that I'm not brave enough to change anything related to paths.

DanielG commented 4 years ago

You might be interrested in my PR #6196 which addresses this issue using Entering/Leaving messages mentioning the directory Cabal is being invoked in, similar to how recursive Make deals with this problem.

symbiont-sam-halliday commented 4 years ago

@DanielG thanks! That looks interesting. I think it'd be a lot cleaner generally if more things used absolute paths. Parsing contextual information seems like it might be impossible for many tools, e.g. a terminal that is just doing filename detection and linking.

symbiont-sam-halliday commented 4 years ago

@phadej if I wanted to make just this one directory absolute, do you know which line of code I should change? It's the only one I care about since it impacts ghc error messages.

jacereda commented 4 years ago

I'm also interested in this feature. I also noticed https://gitlab.haskell.org/ghc/ghc/-/issues/15680

jacereda commented 4 years ago

Emacs 27.1 also has compilation-transform-file-match-alist that can serve as a workaround sometimes.

symbiont-sam-halliday commented 4 years ago

It seems bizarre to me that stack implemented this as a post-processor of the ghc output, instead of just making the directory absolute before invoking ghc. As a proof of concept that this is all that is needed, I manually converted all my source locations to absolute paths and ghc did what I wanted. Of course, I can't commit that kind of change to my project's repo.

newhoggy commented 4 years ago

Is it possible that MAX_PATH restrictions on Windows had a role to play in keeping relative directories in stack?

ulysses4ever commented 1 year ago

Most of diagnostics containing paths comes from GHC, so it should be fixed there. I guess I don’t understand how you see it being done in cabal, @symbiont-sam-halliday, could you explain in more detail?