Commit 298af87d authored by Duncan Coutts's avatar Duncan Coutts Committed by GitHub
Browse files

Merge pull request #3504 from dcoutts/pr/issue-3495

Exit with non-0 code when build fails
parents dc3eca7d ba2065f4
......@@ -8,7 +8,8 @@ module Distribution.Client.CmdBuild (
import Distribution.Client.ProjectOrchestration
( PreBuildHooks(..), runProjectPreBuildPhase, selectTargets
, ProjectBuildContext(..), runProjectBuildPhase, printPlan )
, ProjectBuildContext(..), runProjectBuildPhase
, printPlan, reportBuildFailures )
import Distribution.Client.ProjectConfig
( BuildTimeSettings(..) )
import Distribution.Client.ProjectPlanning
......@@ -53,11 +54,10 @@ buildAction (configFlags, configExFlags, installFlags, haddockFlags)
printPlan verbosity buildCtx
unless (buildSettingDryRun buildSettings) $ do
_plan <- runProjectBuildPhase
verbosity
buildCtx
--TODO: [required eventually] report on build failures in residual plan
return ()
plan <- runProjectBuildPhase
verbosity
buildCtx
reportBuildFailures plan
where
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
......
......@@ -8,7 +8,8 @@ module Distribution.Client.CmdRepl (
import Distribution.Client.ProjectOrchestration
( PreBuildHooks(..), runProjectPreBuildPhase, selectTargets
, ProjectBuildContext(..), runProjectBuildPhase, printPlan )
, ProjectBuildContext(..), runProjectBuildPhase
, printPlan, reportBuildFailures )
import Distribution.Client.ProjectConfig
( BuildTimeSettings(..) )
import Distribution.Client.ProjectPlanning
......@@ -57,11 +58,10 @@ replAction (configFlags, configExFlags, installFlags, haddockFlags)
printPlan verbosity buildCtx
unless (buildSettingDryRun buildSettings) $ do
_plan <- runProjectBuildPhase
verbosity
buildCtx
--TODO: [required eventually] report on build failures in residual plan
return ()
plan <- runProjectBuildPhase
verbosity
buildCtx
reportBuildFailures plan
where
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
......
......@@ -50,6 +50,9 @@ module Distribution.Client.ProjectOrchestration (
-- * Build phase: now do it.
runProjectBuildPhase,
-- * Post build actions
reportBuildFailures,
) where
import Distribution.Client.ProjectConfig
......@@ -85,6 +88,7 @@ import qualified Data.Map as Map
import Data.Map (Map)
import Data.List
import Data.Either
import System.Exit (exitFailure)
-- | Command line configuration flags. These are used to extend\/override the
......@@ -475,3 +479,17 @@ linearizeInstallPlan =
--TODO: [code cleanup] This is a bit of a hack, pretending that each package is installed
-- could we use InstallPlan.topologicalOrder?
reportBuildFailures :: ElaboratedInstallPlan -> IO ()
reportBuildFailures plan =
case [ (pkg, reason)
| InstallPlan.Failed pkg reason <- InstallPlan.toList plan ] of
[] -> return ()
_failed -> exitFailure
--TODO: [required eventually] see the old printBuildFailures for an example
-- of the kind of things we could report, but we want to handle the special
-- case of the current package better, since if you do "cabal build" then
-- you don't need a lot of context to explain where the ghc error message
-- comes from, and indeed extra noise would just be annoying.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment