Skip to content

Commit

Permalink
Add entering/leaving directory messages to build output
Browse files Browse the repository at this point in the history
Ok, so here's the deal: with v2-build we can have multiple different
package directories in one build. At the moment we always start GHC in the
package directory with the paths to the sources being relative to
that. GHC's error messages are going to copy those paths verbatim.

Now when we have multiple packages in seperate directories, say:

    proj/
      pkg-a/A.hs
      pkg-b/B.hs

then error messages are juts going to mention "A.hs" or "B.hs" without the
pkg-* prefix.

So while this is kinda confusing for users that's not really the main
problem. Editors (Emacs in my case) usually have a mode that parses
compiler output to provide jump-to-error functionality. This usually relies
on the paths in error messages being relative to the current directory of
the editor or some such but we break this assumption with v2-build.

It turns out we're not the first build-tool to have this problem, recursive
make pretty much has the same problem and the "solution" there is to just
print messages before and after starting a recursive instance of the build
system in another directory. Editors already have support to parse these
annotations so I'm just adding support to do that to cabal.

Cabal's equivalent of the recursive make instance is Setup.hs/SetupWrapper
which for v2 is always invoked through either 'buildInplaceUnpackedPackage'
or 'buildAndInstallUnpackedPackage' so we add code there to print these
messages.

Together with the preceeding commit adding log linearizaton we can actually
guarantee that the output will make sense to editors trying to parse it
since it's as if we'd run with -j1, unlike the mess 'make' makes of things
when concurrent builds are active!
  • Loading branch information
DanielG committed Mar 25, 2020
1 parent 6e47d09 commit 19653c9
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cabal-install/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ import Control.Exception (Exception (..), Handler (..), SomeAsyncException, Some
import Data.Function (on)
import System.Directory (canonicalizePath, createDirectoryIfMissing, doesDirectoryExist, doesFileExist, removeFile, renameDirectory)
import System.FilePath (dropDrive, makeRelative, normalise, takeDirectory, (<.>), (</>))
import System.IO (stdout)
import System.IO (hPutStrLn, stdout)

import Distribution.Compat.Directory (listDirectory)

Expand Down Expand Up @@ -946,6 +946,16 @@ buildAndInstallUnpackedPackage verbosity

bracket_ initLogFile closeLogFile $ do

let
entering = withLogging $ \mLogFileHandle -> do
let hdl = fromMaybe stdout mLogFileHandle
hPutStrLn hdl $ "Entering directory '" ++ srcdir ++ "'"
leaving = withLogging $ \mLogFileHandle -> do
let hdl = fromMaybe stdout mLogFileHandle
hPutStrLn hdl $ "Leaving directory '" ++ srcdir ++ "'"

bracket_ entering leaving $ do

--TODO: [code cleanup] deal consistently with talking to older
-- Setup.hs versions, much like we do for ghc, with a proper
-- options type and rendering step which will also let us
Expand Down Expand Up @@ -1231,6 +1241,16 @@ buildInplaceUnpackedPackage verbosity

bracket_ initLogFile closeLogFile $ do

let
entering = withLogging $ \mLogFileHandle -> do
let hdl = fromMaybe stdout mLogFileHandle
hPutStrLn hdl $ "Entering directory '" ++ srcdir ++ "'"
leaving = withLogging $ \mLogFileHandle -> do
let hdl = fromMaybe stdout mLogFileHandle
hPutStrLn hdl $ "Leaving directory '" ++ srcdir ++ "'"

bracket_ entering leaving $ do

-- Configure phase
--
whenReConfigure $ do
Expand Down

0 comments on commit 19653c9

Please sign in to comment.