Commit c63e3787 authored by Alexis Williams's avatar Alexis Williams Committed by GitHub

Add proper error reporting for v2-install (#6102)

parent 01a5188a
......@@ -78,7 +78,7 @@ benchAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlag
benchAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
targetStrings globalFlags = do
baseCtx <- establishProjectBaseContext verbosity cliConfig
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand
targetSelectors <- either (reportTargetSelectorProblems verbosity) return
=<< readTargetSelectors (localPackages baseCtx) (Just BenchKind) targetStrings
......
......@@ -116,7 +116,7 @@ buildAction
| onlyConfigure = TargetActionConfigure
| otherwise = TargetActionBuild
baseCtx <- establishProjectBaseContext verbosity cliConfig
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand
targetSelectors <-
either (reportTargetSelectorProblems verbosity) return
......
......@@ -84,7 +84,7 @@ configureAction (configFlags, configExFlags, installFlags, haddockFlags, testFla
_extraArgs globalFlags = do
--TODO: deal with _extraArgs, since flags with wrong syntax end up there
baseCtx <- establishProjectBaseContext verbosity cliConfig
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand
-- Write out the @cabal.project.local@ so it gets picked up by the
-- planning phase. If old config exists, then print the contents
......
......@@ -31,6 +31,7 @@ import qualified Distribution.Client.Setup as Client
import Distribution.Client.ProjectOrchestration
( ProjectBuildContext(..)
, runProjectPreBuildPhase
, CurrentCommand(..)
, establishProjectBaseContext
, distDirLayout
, commandLineFlagsToProjectConfig
......@@ -125,7 +126,7 @@ execAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags
execAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
extraArgs globalFlags = do
baseCtx <- establishProjectBaseContext verbosity cliConfig
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand
-- To set up the environment, we'd like to select the libraries in our
-- dependency tree that we've already built. So first we set up an install
......
......@@ -113,7 +113,7 @@ freezeAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
cabalDirLayout,
projectConfig,
localPackages
} <- establishProjectBaseContext verbosity cliConfig
} <- establishProjectBaseContext verbosity cliConfig OtherCommand
(_, elaboratedPlan, _) <-
rebuildInstallPlan verbosity
......
......@@ -74,7 +74,7 @@ haddockAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFl
haddockAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
targetStrings globalFlags = do
baseCtx <- establishProjectBaseContext verbosity cliConfig
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand
targetSelectors <- either (reportTargetSelectorProblems verbosity) return
=<< readTargetSelectors (localPackages baseCtx) Nothing targetStrings
......
......@@ -253,7 +253,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags
let verbosity' = lessVerbose verbosity
-- First, we need to learn about what's available to be installed.
localBaseCtx <- establishProjectBaseContext verbosity' cliConfig
localBaseCtx <- establishProjectBaseContext verbosity' cliConfig InstallCommand
let localDistDirLayout = distDirLayout localBaseCtx
pkgDb <- projectConfigWithBuilderRepoContext verbosity' (buildSettings localBaseCtx) (getSourcePackages verbosity)
......@@ -816,13 +816,16 @@ establishDummyProjectBaseContext verbosity cliConfig tmpDir localPackages = do
buildSettings = resolveBuildTimeSettings
verbosity cabalDirLayout
projectConfig
currentCommand = InstallCommand
return ProjectBaseContext {
distDirLayout,
cabalDirLayout,
projectConfig,
localPackages,
buildSettings
buildSettings,
currentCommand
}
where
mdistDirectory = flagToMaybe
......
......@@ -337,7 +337,7 @@ data OriginalComponentInfo = OriginalComponentInfo
withProject :: ProjectConfig -> Verbosity -> [String] -> IO (ProjectBaseContext, [TargetSelector], IO ())
withProject cliConfig verbosity targetStrings = do
baseCtx <- establishProjectBaseContext verbosity cliConfig
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand
targetSelectors <- either (reportTargetSelectorProblems verbosity) return
=<< readTargetSelectors (localPackages baseCtx) (Just LibKind) targetStrings
......
......@@ -162,7 +162,7 @@ runAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
let
with =
establishProjectBaseContext verbosity cliConfig
establishProjectBaseContext verbosity cliConfig OtherCommand
without config =
establishDummyProjectBaseContext verbosity (config <> cliConfig) tempDir []
......
......@@ -12,7 +12,7 @@ module Distribution.Client.CmdSdist
import Distribution.Client.CmdErrorMessages
( Plural(..), renderComponentKind )
import Distribution.Client.ProjectOrchestration
( ProjectBaseContext(..), establishProjectBaseContext )
( ProjectBaseContext(..), CurrentCommand(..), establishProjectBaseContext )
import Distribution.Client.TargetSelector
( TargetSelector(..), ComponentKind
, readTargetSelectors, reportTargetSelectorProblems )
......@@ -155,7 +155,7 @@ sdistAction SdistFlags{..} targetStrings globalFlags = do
let distLayout = defaultDistDirLayout projectRoot mDistDirectory
dir <- getCurrentDirectory
projectConfig <- runRebuild dir $ readProjectConfig verbosity globalConfig distLayout
baseCtx <- establishProjectBaseContext verbosity projectConfig
baseCtx <- establishProjectBaseContext verbosity projectConfig OtherCommand
let localPkgs = localPackages baseCtx
targetSelectors <- either (reportTargetSelectorProblems verbosity) return
......
......@@ -89,7 +89,7 @@ testAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags
testAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
targetStrings globalFlags = do
baseCtx <- establishProjectBaseContext verbosity cliConfig
baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand
targetSelectors <- either (reportTargetSelectorProblems verbosity) return
=<< readTargetSelectors (localPackages baseCtx) (Just TestKind) targetStrings
......
......@@ -119,7 +119,7 @@ updateAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFla
updateAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
extraArgs globalFlags = do
projectConfig <- withProjectOrGlobalConfig verbosity globalConfigFlag
(projectConfig <$> establishProjectBaseContext verbosity cliConfig)
(projectConfig <$> establishProjectBaseContext verbosity cliConfig OtherCommand)
(\globalConfig -> return $ globalConfig <> cliConfig)
projectConfigWithSolverRepoContext verbosity
......
......@@ -41,6 +41,7 @@
--
module Distribution.Client.ProjectOrchestration (
-- * Discovery phase: what is in the project?
CurrentCommand(..),
establishProjectBaseContext,
ProjectBaseContext(..),
BuildTimeSettings(..),
......@@ -168,6 +169,11 @@ import System.Posix.Signals (sigKILL, sigSEGV)
#endif
-- | Tracks what command is being executed, because we need to hide this somewhere
-- for cases that need special handling (usually for error reporting).
data CurrentCommand = InstallCommand | OtherCommand
deriving (Show, Eq)
-- | This holds the context of a project prior to solving: the content of the
-- @cabal.project@ and all the local package @.cabal@ files.
--
......@@ -176,13 +182,15 @@ data ProjectBaseContext = ProjectBaseContext {
cabalDirLayout :: CabalDirLayout,
projectConfig :: ProjectConfig,
localPackages :: [PackageSpecifier UnresolvedSourcePackage],
buildSettings :: BuildTimeSettings
buildSettings :: BuildTimeSettings,
currentCommand :: CurrentCommand
}
establishProjectBaseContext :: Verbosity
-> ProjectConfig
-> CurrentCommand
-> IO ProjectBaseContext
establishProjectBaseContext verbosity cliConfig = do
establishProjectBaseContext verbosity cliConfig currentCommand = do
cabalDir <- getCabalDir
projectRoot <- either throwIO return =<<
......@@ -218,7 +226,8 @@ establishProjectBaseContext verbosity cliConfig = do
cabalDirLayout,
projectConfig,
localPackages,
buildSettings
buildSettings,
currentCommand
}
where
mdistDirectory = Setup.flagToMaybe projectConfigDistDir
......@@ -422,7 +431,7 @@ runProjectPostBuildPhase verbosity
-- Finally if there were any build failures then report them and throw
-- an exception to terminate the program
dieOnBuildFailures verbosity elaboratedPlanToExecute buildOutcomes
dieOnBuildFailures verbosity currentCommand elaboratedPlanToExecute buildOutcomes
-- Note that it is a deliberate design choice that the 'buildTargets' is
-- not passed to phase 1, and the various bits of input config is not
......@@ -971,9 +980,9 @@ printPlan verbosity
-- | If there are build failures then report them and throw an exception.
--
dieOnBuildFailures :: Verbosity
dieOnBuildFailures :: Verbosity -> CurrentCommand
-> ElaboratedInstallPlan -> BuildOutcomes -> IO ()
dieOnBuildFailures verbosity plan buildOutcomes
dieOnBuildFailures verbosity currentCommand plan buildOutcomes
| null failures = return ()
| isSimpleCase = exitFailure
......@@ -1060,6 +1069,7 @@ dieOnBuildFailures verbosity plan buildOutcomes
, [pkg] <- rootpkgs
, installedUnitId pkg == pkgid
, isFailureSelfExplanatory (buildFailureReason failure)
, currentCommand /= InstallCommand
= True
| otherwise
= False
......
......@@ -2,6 +2,7 @@
3.0.0.0 (current development version)
* `install-method` and `overwrite-policy` in `.cabal/config` now actually work. (#5942)
* `v2-install` now reports the error when a package fails to build. (#5641)
* `v2-install` now has a default when called in a project (#5978, #6014, #6092)
* '--write-ghc-environment-files' now defaults to 'never' (#4242)
* Fix `sdist`'s output when sent to stdout. (#5874)
......
Markdown is supported
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