diff --git a/cabal-install/Distribution/Client/CmdBench.hs b/cabal-install/Distribution/Client/CmdBench.hs index 396e605d662..76759fcf8e9 100644 --- a/cabal-install/Distribution/Client/CmdBench.hs +++ b/cabal-install/Distribution/Client/CmdBench.hs @@ -8,13 +8,22 @@ module Distribution.Client.CmdBench ( benchAction, -- * Internals exposed for testing - TargetProblem(..), + componentNotBenchmarkProblem, + isSubComponentProblem, + noBenchmarksProblem, selectPackageTargets, selectComponentTarget ) where import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages + ( renderTargetSelector, showTargetSelector, + renderTargetProblemCommon, renderTargetProblemNoneEnabled, + renderTargetProblemNoTargets, plural, targetSelectorPluralPkgs, + targetSelectorFilter ) +import Distribution.Client.TargetProblem + ( TargetProblem (..), commonTargetProblem, customTargetProblem + , noTargetsProblem, noneEnabledTargetProblem ) import Distribution.Client.Setup ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags ) @@ -102,7 +111,7 @@ benchAction ( configFlags, configExFlags, installFlags $ resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors @@ -133,7 +142,7 @@ benchAction ( configFlags, configExFlags, installFlags -- or fail if there are no benchmarks or no buildable benchmarks. -- selectPackageTargets :: TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] + -> [AvailableTarget k] -> Either BenchTargetProblem [k] selectPackageTargets targetSelector targets -- If there are any buildable benchmark targets then we select those @@ -142,15 +151,15 @@ selectPackageTargets targetSelector targets -- If there are benchmarks but none are buildable then we report those | not (null targetsBench) - = Left (TargetProblemNoneEnabled targetSelector targetsBench) + = Left (noneEnabledTargetProblem targetSelector targetsBench) -- If there are no benchmarks but some other targets then we report that | not (null targets) - = Left (TargetProblemNoBenchmarks targetSelector) + = Left (noBenchmarksProblem targetSelector) -- If there are no targets at all then we report that | otherwise - = Left (TargetProblemNoTargets targetSelector) + = Left (noTargetsProblem targetSelector) where targetsBenchBuildable = selectBuildableTargets . filterTargetsKind BenchKind @@ -168,34 +177,28 @@ selectPackageTargets targetSelector targets -- to the basic checks on being buildable etc. -- selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k + -> AvailableTarget k -> Either BenchTargetProblem k selectComponentTarget subtarget@WholeComponent t | CBenchName _ <- availableTargetComponentName t - = either (Left . TargetProblemCommon) return $ + = either (Left . commonTargetProblem) return $ selectComponentTargetBasic subtarget t | otherwise - = Left (TargetProblemComponentNotBenchmark (availableTargetPackageId t) - (availableTargetComponentName t)) + = Left (componentNotBenchmarkProblem + (availableTargetPackageId t) + (availableTargetComponentName t)) selectComponentTarget subtarget t - = Left (TargetProblemIsSubComponent (availableTargetPackageId t) - (availableTargetComponentName t) - subtarget) + = Left (isSubComponentProblem + (availableTargetPackageId t) + (availableTargetComponentName t) + subtarget) -- | The various error conditions that can occur when matching a -- 'TargetSelector' against 'AvailableTarget's for the @bench@ command. -- -data TargetProblem = - TargetProblemCommon TargetProblemCommon - - -- | The 'TargetSelector' matches benchmarks but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] - - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - +data BenchProblem = -- | The 'TargetSelector' matches targets but no benchmarks - | TargetProblemNoBenchmarks TargetSelector + TargetProblemNoBenchmarks TargetSelector -- | The 'TargetSelector' refers to a component that is not a benchmark | TargetProblemComponentNotBenchmark PackageId ComponentName @@ -204,25 +207,43 @@ data TargetProblem = | TargetProblemIsSubComponent PackageId ComponentName SubComponentTarget deriving (Eq, Show) -reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a + +type BenchTargetProblem = TargetProblem BenchProblem + +noBenchmarksProblem :: TargetSelector -> TargetProblem BenchProblem +noBenchmarksProblem = customTargetProblem . TargetProblemNoBenchmarks + +componentNotBenchmarkProblem :: PackageId -> ComponentName -> TargetProblem BenchProblem +componentNotBenchmarkProblem pkgid name = customTargetProblem $ + TargetProblemComponentNotBenchmark pkgid name + +isSubComponentProblem + :: PackageId + -> ComponentName + -> SubComponentTarget + -> TargetProblem BenchProblem +isSubComponentProblem pkgid name subcomponent = customTargetProblem $ + TargetProblemIsSubComponent pkgid name subcomponent + +reportTargetProblems :: Verbosity -> [BenchTargetProblem] -> IO a reportTargetProblems verbosity = die' verbosity . unlines . map renderTargetProblem -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = +renderTargetProblem :: BenchTargetProblem -> String +renderTargetProblem (CommonProblem problem) = renderTargetProblemCommon "run" problem -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = +renderTargetProblem (NoneEnabled targetSelector targets) = renderTargetProblemNoneEnabled "benchmark" targetSelector targets -renderTargetProblem (TargetProblemNoBenchmarks targetSelector) = +renderTargetProblem (CustomProblem (TargetProblemNoBenchmarks targetSelector)) = "Cannot run benchmarks for the target '" ++ showTargetSelector targetSelector ++ "' which refers to " ++ renderTargetSelector targetSelector ++ " because " ++ plural (targetSelectorPluralPkgs targetSelector) "it does" "they do" ++ " not contain any benchmarks." -renderTargetProblem (TargetProblemNoTargets targetSelector) = +renderTargetProblem (NoTargets targetSelector) = case targetSelectorFilter targetSelector of Just kind | kind /= BenchKind -> "The bench command is for running benchmarks, but the target '" @@ -231,7 +252,7 @@ renderTargetProblem (TargetProblemNoTargets targetSelector) = _ -> renderTargetProblemNoTargets "benchmark" targetSelector -renderTargetProblem (TargetProblemComponentNotBenchmark pkgid cname) = +renderTargetProblem (CustomProblem (TargetProblemComponentNotBenchmark pkgid cname)) = "The bench command is for running benchmarks, but the target '" ++ showTargetSelector targetSelector ++ "' refers to " ++ renderTargetSelector targetSelector ++ " from the package " @@ -239,7 +260,7 @@ renderTargetProblem (TargetProblemComponentNotBenchmark pkgid cname) = where targetSelector = TargetComponent pkgid cname WholeComponent -renderTargetProblem (TargetProblemIsSubComponent pkgid cname subtarget) = +renderTargetProblem (CustomProblem (TargetProblemIsSubComponent pkgid cname subtarget)) = "The bench command can only run benchmarks as a whole, " ++ "not files or modules within them, but the target '" ++ showTargetSelector targetSelector ++ "' refers to " diff --git a/cabal-install/Distribution/Client/CmdBuild.hs b/cabal-install/Distribution/Client/CmdBuild.hs index f042dc735c6..e267c07215d 100644 --- a/cabal-install/Distribution/Client/CmdBuild.hs +++ b/cabal-install/Distribution/Client/CmdBuild.hs @@ -6,7 +6,6 @@ module Distribution.Client.CmdBuild ( buildAction, -- * Internals exposed for testing - TargetProblem(..), selectPackageTargets, selectComponentTarget ) where @@ -15,6 +14,12 @@ import Prelude () import Distribution.Client.Compat.Prelude import Distribution.Client.ProjectOrchestration +import Distribution.Client.TargetProblem + ( TargetProblem' + , commonTargetProblem + , noTargetsProblem + , noneEnabledTargetProblem + ) import Distribution.Client.CmdErrorMessages import Distribution.Client.Setup @@ -132,11 +137,11 @@ buildAction -- Interpret the targets on the command line as build targets -- (as opposed to say repl or haddock targets). - targets <- either (reportTargetProblems verbosity) return + targets <- either (reportBuildTargetProblems verbosity) return $ resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors @@ -175,7 +180,7 @@ buildAction -- components -- selectPackageTargets :: TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] + -> [AvailableTarget k] -> Either TargetProblem' [k] selectPackageTargets targetSelector targets -- If there are any buildable targets then we select those @@ -184,11 +189,11 @@ selectPackageTargets targetSelector targets -- If there are targets but none are buildable then we report those | not (null targets) - = Left (TargetProblemNoneEnabled targetSelector targets') + = Left (noneEnabledTargetProblem targetSelector targets') -- If there are no targets at all then we report that | otherwise - = Left (TargetProblemNoTargets targetSelector) + = Left (noTargetsProblem targetSelector) where targets' = forgetTargetsDetail targets targetsBuildable = selectBuildableTargetsWith @@ -208,36 +213,14 @@ selectPackageTargets targetSelector targets -- For the @build@ command we just need the basic checks on being buildable etc. -- selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k + -> AvailableTarget k -> Either TargetProblem' k selectComponentTarget subtarget = - either (Left . TargetProblemCommon) Right + either (Left . commonTargetProblem) Right . selectComponentTargetBasic subtarget - --- | The various error conditions that can occur when matching a --- 'TargetSelector' against 'AvailableTarget's for the @build@ command. --- -data TargetProblem = - TargetProblemCommon TargetProblemCommon - - -- | The 'TargetSelector' matches targets but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] - - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - deriving (Eq, Show) - -reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a -reportTargetProblems verbosity = - die' verbosity . unlines . map renderTargetProblem - -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = - renderTargetProblemCommon "build" problem -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = - renderTargetProblemNoneEnabled "build" targetSelector targets -renderTargetProblem(TargetProblemNoTargets targetSelector) = - renderTargetProblemNoTargets "build" targetSelector +reportBuildTargetProblems :: Verbosity -> [TargetProblem'] -> IO a +reportBuildTargetProblems verbosity problems = + reportTargetProblems verbosity "build" problems reportCannotPruneDependencies :: Verbosity -> CannotPruneDependencies -> IO a reportCannotPruneDependencies verbosity = diff --git a/cabal-install/Distribution/Client/CmdErrorMessages.hs b/cabal-install/Distribution/Client/CmdErrorMessages.hs index 34d7bfda455..8ca1c115619 100644 --- a/cabal-install/Distribution/Client/CmdErrorMessages.hs +++ b/cabal-install/Distribution/Client/CmdErrorMessages.hs @@ -1,4 +1,7 @@ -{-# LANGUAGE RecordWildCards, NamedFieldPuns #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE RecordWildCards #-} + -- | Utilities to help format error messages for the various CLI commands. -- @@ -10,20 +13,31 @@ module Distribution.Client.CmdErrorMessages ( import Distribution.Client.Compat.Prelude import Prelude () -import Distribution.Client.ProjectOrchestration +import Distribution.Client.ProjectPlanning + ( AvailableTarget(..), AvailableTargetStatus(..), + CannotPruneDependencies(..), TargetRequested(..) ) +import Distribution.Client.TargetSelector + ( SubComponentTarget(..) ) +import Distribution.Client.TargetProblem + ( TargetProblemCommon(..), TargetProblem(..), TargetProblem' ) import Distribution.Client.TargetSelector - ( ComponentKindFilter, componentKind, showTargetSelector ) + ( ComponentKind(..), ComponentKindFilter, TargetSelector(..), + componentKind, showTargetSelector ) import Distribution.Package - ( packageId, PackageName, packageName ) + ( PackageId, packageId, PackageName, packageName ) +import Distribution.Simple.Utils + ( die' ) import Distribution.Types.ComponentName - ( showComponentName ) + ( ComponentName(..), showComponentName ) import Distribution.Types.LibraryName ( LibraryName(..) ) import Distribution.Solver.Types.OptionalStanza ( OptionalStanza(..) ) import Distribution.Pretty ( prettyShow ) +import Distribution.Verbosity + ( Verbosity ) import qualified Data.List.NonEmpty as NE import Data.Function (on) @@ -191,6 +205,28 @@ renderComponentKind Plural ckind = case ckind of BenchKind -> "benchmarks" +------------------------------------------------------- +-- Renderering error messages for TargetProblem +-- + +-- | Default implementation of 'reportTargetProblems' simply renders one problem per line. +reportTargetProblems :: Verbosity -> String -> [TargetProblem'] -> IO a +reportTargetProblems verbosity verb = + die' verbosity . unlines . map (renderTargetProblem verb) + +-- | Default implementation of 'renderTargetProblem'. +renderTargetProblem :: String -> TargetProblem' -> String +renderTargetProblem verb = \case + (CommonProblem problem) -> + renderTargetProblemCommon verb problem + (NoneEnabled targetSelector targets) -> + renderTargetProblemNoneEnabled verb targetSelector targets + (NoTargets targetSelector) -> + renderTargetProblemNoTargets verb targetSelector + (CustomProblem ()) -> + "" + + ------------------------------------------------------- -- Renderering error messages for TargetProblemCommon -- diff --git a/cabal-install/Distribution/Client/CmdHaddock.hs b/cabal-install/Distribution/Client/CmdHaddock.hs index 6d06c679b9f..707b2d22d12 100644 --- a/cabal-install/Distribution/Client/CmdHaddock.hs +++ b/cabal-install/Distribution/Client/CmdHaddock.hs @@ -8,13 +8,18 @@ module Distribution.Client.CmdHaddock ( haddockAction, -- * Internals exposed for testing - TargetProblem(..), selectPackageTargets, selectComponentTarget ) where import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages +import Distribution.Client.TargetProblem + ( TargetProblem' + , commonTargetProblem + , noTargetsProblem + , noneEnabledTargetProblem + ) import Distribution.Client.NixStyleOptions ( NixStyleFlags, nixStyleOptions, defaultNixStyleFlags ) @@ -92,11 +97,11 @@ haddockAction ( configFlags, configExFlags, installFlags -- When we interpret the targets on the command line, interpret them as -- haddock targets - targets <- either (reportTargetProblems verbosity) return + targets <- either (reportBuildDocumentationTargetProblems verbosity) return $ resolveTargets (selectPackageTargets haddockFlags) selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors @@ -128,7 +133,7 @@ haddockAction ( configFlags, configExFlags, installFlags -- We do similarly for test-suites, benchmarks and foreign libs. -- selectPackageTargets :: HaddockFlags -> TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] + -> [AvailableTarget k] -> Either TargetProblem' [k] selectPackageTargets haddockFlags targetSelector targets -- If there are any buildable targets then we select those @@ -137,11 +142,11 @@ selectPackageTargets haddockFlags targetSelector targets -- If there are targets but none are buildable then we report those | not (null targets) - = Left (TargetProblemNoneEnabled targetSelector targets') + = Left (noneEnabledTargetProblem targetSelector targets') -- If there are no targets at all then we report that | otherwise - = Left (TargetProblemNoTargets targetSelector) + = Left (noTargetsProblem targetSelector) where targets' = forgetTargetsDetail (map disableNotRequested targets) targetsBuildable = selectBuildableTargets (map disableNotRequested targets) @@ -178,35 +183,11 @@ selectPackageTargets haddockFlags targetSelector targets -- etc. -- selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k + -> AvailableTarget k -> Either TargetProblem' k selectComponentTarget subtarget = - either (Left . TargetProblemCommon) Right + either (Left . commonTargetProblem) Right . selectComponentTargetBasic subtarget - --- | The various error conditions that can occur when matching a --- 'TargetSelector' against 'AvailableTarget's for the @haddock@ command. --- -data TargetProblem = - TargetProblemCommon TargetProblemCommon - - -- | The 'TargetSelector' matches targets but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] - - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - deriving (Eq, Show) - -reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a -reportTargetProblems verbosity = - die' verbosity . unlines . map renderTargetProblem - -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = - renderTargetProblemCommon "build documentation for" problem - -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = - renderTargetProblemNoneEnabled "build documentation for" targetSelector targets - -renderTargetProblem(TargetProblemNoTargets targetSelector) = - renderTargetProblemNoTargets "build documentation for" targetSelector +reportBuildDocumentationTargetProblems :: Verbosity -> [TargetProblem'] -> IO a +reportBuildDocumentationTargetProblems verbosity problems = + reportTargetProblems verbosity "build documentation for" problems diff --git a/cabal-install/Distribution/Client/CmdInstall.hs b/cabal-install/Distribution/Client/CmdInstall.hs index cf773425816..58be8e2bbaa 100644 --- a/cabal-install/Distribution/Client/CmdInstall.hs +++ b/cabal-install/Distribution/Client/CmdInstall.hs @@ -12,7 +12,6 @@ module Distribution.Client.CmdInstall ( installAction, -- * Internals exposed for testing - TargetProblem(..), selectPackageTargets, selectComponentTarget, -- * Internals exposed for CmdRepl + CmdRun @@ -28,6 +27,12 @@ import Distribution.Compat.Directory import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages import Distribution.Client.CmdSdist +import Distribution.Client.TargetProblem + ( TargetProblem', + TargetProblem (CommonProblem), + commonTargetProblem, + noneEnabledTargetProblem, + noTargetsProblem ) import Distribution.Client.CmdInstall.ClientInstallFlags import Distribution.Client.CmdInstall.ClientInstallTargetSelector @@ -506,7 +511,7 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS let mTargets = resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan (Just pkgDb) targetSelectors @@ -518,12 +523,12 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS -- Not everything is local. let (errs', hackageNames) = partitionEithers . flip fmap errs $ \case - TargetProblemCommon (TargetAvailableInIndex name) -> Right name + CommonProblem (TargetAvailableInIndex name) -> Right name err -> Left err -- report incorrect case for known package. for_ errs' $ \case - TargetProblemCommon (TargetNotInProject hn) -> + CommonProblem (TargetNotInProject hn) -> case searchByName (packageIndex pkgDb) (unPackageName hn) of [] -> return () xs -> die' verbosity . concat $ @@ -533,7 +538,7 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS ] _ -> return () - when (not . null $ errs') $ reportTargetProblems verbosity errs' + when (not . null $ errs') $ reportBuildTargetProblems verbosity errs' let targetSelectors' = flip filter targetSelectors $ \case @@ -546,11 +551,11 @@ partitionToKnownTargetsAndHackagePackages verbosity pkgDb elaboratedPlan targetS -- This can't fail, because all of the errors are -- removed (or we've given up). targets <- - either (reportTargetProblems verbosity) return $ + either (reportBuildTargetProblems verbosity) return $ resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors' @@ -568,11 +573,11 @@ constructProjectBuildContext constructProjectBuildContext verbosity baseCtx targetSelectors = do runProjectPreBuildPhase verbosity baseCtx $ \elaboratedPlan -> do -- Interpret the targets on the command line as build targets - targets <- either (reportTargetProblems verbosity) return $ + targets <- either (reportBuildTargetProblems verbosity) return $ resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors @@ -931,7 +936,7 @@ getPackageDbStack compilerId storeDirFlag logsDirFlag = do -- selectPackageTargets :: TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] + -> [AvailableTarget k] -> Either TargetProblem' [k] selectPackageTargets targetSelector targets -- If there are any buildable targets then we select those @@ -940,11 +945,11 @@ selectPackageTargets targetSelector targets -- If there are targets but none are buildable then we report those | not (null targets) - = Left (TargetProblemNoneEnabled targetSelector targets') + = Left (noneEnabledTargetProblem targetSelector targets') -- If there are no targets at all then we report that | otherwise - = Left (TargetProblemNoTargets targetSelector) + = Left (noTargetsProblem targetSelector) where targets' = forgetTargetsDetail targets targetsBuildable = selectBuildableTargetsWith @@ -965,36 +970,13 @@ selectPackageTargets targetSelector targets -- selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k + -> AvailableTarget k -> Either TargetProblem' k selectComponentTarget subtarget = - either (Left . TargetProblemCommon) Right + either (Left . commonTargetProblem) Right . selectComponentTargetBasic subtarget - --- | The various error conditions that can occur when matching a --- 'TargetSelector' against 'AvailableTarget's for the @build@ command. --- -data TargetProblem = - TargetProblemCommon TargetProblemCommon - - -- | The 'TargetSelector' matches targets but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] - - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - deriving (Eq, Show) - -reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a -reportTargetProblems verbosity = - die' verbosity . unlines . map renderTargetProblem - -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = - renderTargetProblemCommon "build" problem -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = - renderTargetProblemNoneEnabled "build" targetSelector targets -renderTargetProblem(TargetProblemNoTargets targetSelector) = - renderTargetProblemNoTargets "build" targetSelector +reportBuildTargetProblems :: Verbosity -> [TargetProblem'] -> IO a +reportBuildTargetProblems verbosity problems = reportTargetProblems verbosity "build" problems reportCannotPruneDependencies :: Verbosity -> CannotPruneDependencies -> IO a reportCannotPruneDependencies verbosity = diff --git a/cabal-install/Distribution/Client/CmdRepl.hs b/cabal-install/Distribution/Client/CmdRepl.hs index d907b9bf66b..21c9cc8ed19 100644 --- a/cabal-install/Distribution/Client/CmdRepl.hs +++ b/cabal-install/Distribution/Client/CmdRepl.hs @@ -12,7 +12,7 @@ module Distribution.Client.CmdRepl ( replAction, -- * Internals exposed for testing - TargetProblem(..), + matchesMultipleProblem, selectPackageTargets, selectComponentTarget ) where @@ -26,6 +26,14 @@ import qualified Distribution.Types.Lens as L import Distribution.Client.NixStyleOptions ( NixStyleFlags, nixStyleOptions, defaultNixStyleFlags ) import Distribution.Client.CmdErrorMessages + ( renderTargetSelector, showTargetSelector, + renderTargetProblemCommon, renderTargetProblemNoneEnabled, + renderTargetProblemNoTargets, targetSelectorRefersToPkgs, + renderComponentKind, renderListCommaAnd, renderListSemiAnd, + componentKind, sortGroupOn, Plural(..) ) +import Distribution.Client.TargetProblem + ( TargetProblem(..), commonTargetProblem, customTargetProblem + , noneEnabledTargetProblem, noTargetsProblem ) import qualified Distribution.Client.InstallPlan as InstallPlan import Distribution.Client.ProjectBuilding ( rebuildTargetsDryRun, improveInstallPlanWithUpToDatePackages ) @@ -317,7 +325,7 @@ replAction ( configFlags, configExFlags, installFlags $ resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors @@ -327,7 +335,7 @@ replAction ( configFlags, configExFlags, installFlags -- same component, but not two that live in different components. when (Set.size (distinctTargetComponents targets) > 1) $ reportTargetProblems verbosity - [TargetProblemMultipleTargets targets] + [multipleTargetsProblem targets] return targets @@ -461,7 +469,7 @@ generateReplFlags includeTransitive elaboratedPlan OriginalComponentInfo{..} = f -- multiple libs or exes. -- selectPackageTargets :: TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] + -> [AvailableTarget k] -> Either ReplTargetProblem [k] selectPackageTargets targetSelector targets -- If there is exactly one buildable library then we select that @@ -470,7 +478,7 @@ selectPackageTargets targetSelector targets -- but fail if there are multiple buildable libraries. | not (null targetsLibsBuildable) - = Left (TargetProblemMatchesMultiple targetSelector targetsLibsBuildable') + = Left (matchesMultipleProblem targetSelector targetsLibsBuildable') -- If there is exactly one buildable executable then we select that | [target] <- targetsExesBuildable @@ -478,7 +486,7 @@ selectPackageTargets targetSelector targets -- but fail if there are multiple buildable executables. | not (null targetsExesBuildable) - = Left (TargetProblemMatchesMultiple targetSelector targetsExesBuildable') + = Left (matchesMultipleProblem targetSelector targetsExesBuildable') -- If there is exactly one other target then we select that | [target] <- targetsBuildable @@ -486,15 +494,15 @@ selectPackageTargets targetSelector targets -- but fail if there are multiple such targets | not (null targetsBuildable) - = Left (TargetProblemMatchesMultiple targetSelector targetsBuildable') + = Left (matchesMultipleProblem targetSelector targetsBuildable') -- If there are targets but none are buildable then we report those | not (null targets) - = Left (TargetProblemNoneEnabled targetSelector targets') + = Left (noneEnabledTargetProblem targetSelector targets') -- If there are no targets at all then we report that | otherwise - = Left (TargetProblemNoTargets targetSelector) + = Left (noTargetsProblem targetSelector) where targets' = forgetTargetsDetail targets (targetsLibsBuildable, @@ -523,40 +531,46 @@ selectPackageTargets targetSelector targets -- For the @repl@ command we just need the basic checks on being buildable etc. -- selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k + -> AvailableTarget k -> Either ReplTargetProblem k selectComponentTarget subtarget = - either (Left . TargetProblemCommon) Right + either (Left . commonTargetProblem) Right . selectComponentTargetBasic subtarget +data ReplProblem + = TargetProblemMatchesMultiple TargetSelector [AvailableTarget ()] + + -- | Multiple 'TargetSelector's match multiple targets + | TargetProblemMultipleTargets TargetsMap + deriving (Eq, Show) + -- | The various error conditions that can occur when matching a -- 'TargetSelector' against 'AvailableTarget's for the @repl@ command. -- -data TargetProblem = - TargetProblemCommon TargetProblemCommon +type ReplTargetProblem = TargetProblem ReplProblem - -- | The 'TargetSelector' matches targets but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] +matchesMultipleProblem + :: TargetSelector + -> [AvailableTarget ()] + -> ReplTargetProblem +matchesMultipleProblem targetSelector targetsExesBuildable = + customTargetProblem $ TargetProblemMatchesMultiple targetSelector targetsExesBuildable - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - - -- | A single 'TargetSelector' matches multiple targets - | TargetProblemMatchesMultiple TargetSelector [AvailableTarget ()] - - -- | Multiple 'TargetSelector's match multiple targets - | TargetProblemMultipleTargets TargetsMap - deriving (Eq, Show) +multipleTargetsProblem + :: TargetsMap + -> ReplTargetProblem +multipleTargetsProblem = customTargetProblem . TargetProblemMultipleTargets -reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a +reportTargetProblems :: Verbosity -> [TargetProblem ReplProblem] -> IO a reportTargetProblems verbosity = die' verbosity . unlines . map renderTargetProblem -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = +renderTargetProblem :: TargetProblem ReplProblem -> String +renderTargetProblem (CommonProblem problem) = renderTargetProblemCommon "open a repl for" problem -renderTargetProblem (TargetProblemMatchesMultiple targetSelector targets) = +renderTargetProblem + (CustomProblem (TargetProblemMatchesMultiple targetSelector targets)) = "Cannot open a repl for multiple components at once. The target '" ++ showTargetSelector targetSelector ++ "' refers to " ++ renderTargetSelector targetSelector ++ " which " @@ -576,7 +590,8 @@ renderTargetProblem (TargetProblemMatchesMultiple targetSelector targets) = availableTargetComponentKind = componentKind . availableTargetComponentName -renderTargetProblem (TargetProblemMultipleTargets selectorMap) = +renderTargetProblem + (CustomProblem (TargetProblemMultipleTargets selectorMap)) = "Cannot open a repl for multiple components at once. The targets " ++ renderListCommaAnd [ "'" ++ showTargetSelector ts ++ "'" @@ -584,10 +599,10 @@ renderTargetProblem (TargetProblemMultipleTargets selectorMap) = ++ " refer to different components." ++ ".\n\n" ++ explanationSingleComponentLimitation -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = +renderTargetProblem (NoneEnabled targetSelector targets) = renderTargetProblemNoneEnabled "open a repl for" targetSelector targets -renderTargetProblem (TargetProblemNoTargets targetSelector) = +renderTargetProblem (NoTargets targetSelector) = renderTargetProblemNoTargets "open a repl for" targetSelector diff --git a/cabal-install/Distribution/Client/CmdRun.hs b/cabal-install/Distribution/Client/CmdRun.hs index 2f4b14c92c9..dc624c679a3 100644 --- a/cabal-install/Distribution/Client/CmdRun.hs +++ b/cabal-install/Distribution/Client/CmdRun.hs @@ -12,7 +12,8 @@ module Distribution.Client.CmdRun ( handleShebang, validScript, -- * Internals exposed for testing - TargetProblem(..), + matchesMultipleProblem, + noExesProblem, selectPackageTargets, selectComponentTarget ) where @@ -22,6 +23,13 @@ import Distribution.Client.Compat.Prelude hiding (toList) import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages + ( renderTargetSelector, showTargetSelector, + renderTargetProblemCommon, renderTargetProblemNoneEnabled, + renderTargetProblemNoTargets, plural, targetSelectorPluralPkgs, + targetSelectorFilter, renderListCommaAnd ) +import Distribution.Client.TargetProblem + ( TargetProblem (..), commonTargetProblem, customTargetProblem + , noneEnabledTargetProblem, noTargetsProblem ) import Distribution.Client.CmdRun.ClientRunFlags @@ -212,7 +220,7 @@ runAction ( configFlags, configExFlags, installFlags $ resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors @@ -227,7 +235,7 @@ runAction ( configFlags, configExFlags, installFlags _ <- singleExeOrElse (reportTargetProblems verbosity - [TargetProblemMultipleTargets targets]) + [multipleTargetsProblem targets]) targets let elaboratedPlan' = pruneInstallPlanToTargets @@ -481,7 +489,7 @@ matchingPackagesByUnitId uid = -- buildable. Fail if there are no or multiple buildable exe components. -- selectPackageTargets :: TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] + -> [AvailableTarget k] -> Either RunTargetProblem [k] selectPackageTargets targetSelector targets -- If there is exactly one buildable executable then we select that @@ -490,19 +498,19 @@ selectPackageTargets targetSelector targets -- but fail if there are multiple buildable executables. | not (null targetsExesBuildable) - = Left (TargetProblemMatchesMultiple targetSelector targetsExesBuildable') + = Left (matchesMultipleProblem targetSelector targetsExesBuildable') -- If there are executables but none are buildable then we report those | not (null targetsExes) - = Left (TargetProblemNoneEnabled targetSelector targetsExes) + = Left (noneEnabledTargetProblem targetSelector targetsExes) -- If there are no executables but some other targets then we report that | not (null targets) - = Left (TargetProblemNoExes targetSelector) + = Left (noExesProblem targetSelector) -- If there are no targets at all then we report that | otherwise - = Left (TargetProblemNoTargets targetSelector) + = Left (noTargetsProblem targetSelector) where -- Targets that can be executed targetsExecutableLike = @@ -522,36 +530,29 @@ selectPackageTargets targetSelector targets -- to the basic checks on being buildable etc. -- selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k + -> AvailableTarget k -> Either RunTargetProblem k selectComponentTarget subtarget@WholeComponent t = case availableTargetComponentName t of CExeName _ -> component CTestName _ -> component CBenchName _ -> component - _ -> Left (TargetProblemComponentNotExe pkgid cname) + _ -> Left (componentNotExeProblem pkgid cname) where pkgid = availableTargetPackageId t cname = availableTargetComponentName t - component = either (Left . TargetProblemCommon) return $ + component = either (Left . commonTargetProblem) return $ selectComponentTargetBasic subtarget t selectComponentTarget subtarget t - = Left (TargetProblemIsSubComponent (availableTargetPackageId t) - (availableTargetComponentName t) - subtarget) + = Left (isSubComponentProblem (availableTargetPackageId t) + (availableTargetComponentName t) + subtarget) -- | The various error conditions that can occur when matching a -- 'TargetSelector' against 'AvailableTarget's for the @run@ command. -- -data TargetProblem = - TargetProblemCommon TargetProblemCommon - -- | The 'TargetSelector' matches targets but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] - - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - +data RunProblem = -- | The 'TargetSelector' matches targets but no executables - | TargetProblemNoExes TargetSelector + TargetProblemNoExes TargetSelector -- | A single 'TargetSelector' matches multiple targets | TargetProblemMatchesMultiple TargetSelector [AvailableTarget ()] @@ -566,25 +567,49 @@ data TargetProblem = | TargetProblemIsSubComponent PackageId ComponentName SubComponentTarget deriving (Eq, Show) -reportTargetProblems :: Verbosity -> [TargetProblem] -> IO a +type RunTargetProblem = TargetProblem RunProblem + +noExesProblem :: TargetSelector -> RunTargetProblem +noExesProblem = customTargetProblem . TargetProblemNoExes + +matchesMultipleProblem :: TargetSelector -> [AvailableTarget ()] -> RunTargetProblem +matchesMultipleProblem selector targets = customTargetProblem $ + TargetProblemMatchesMultiple selector targets + +multipleTargetsProblem :: TargetsMap -> TargetProblem RunProblem +multipleTargetsProblem = customTargetProblem . TargetProblemMultipleTargets + +componentNotExeProblem :: PackageId -> ComponentName -> TargetProblem RunProblem +componentNotExeProblem pkgid name = customTargetProblem $ + TargetProblemComponentNotExe pkgid name + +isSubComponentProblem + :: PackageId + -> ComponentName + -> SubComponentTarget + -> TargetProblem RunProblem +isSubComponentProblem pkgid name subcomponent = customTargetProblem $ + TargetProblemIsSubComponent pkgid name subcomponent + +reportTargetProblems :: Verbosity -> [RunTargetProblem] -> IO a reportTargetProblems verbosity = die' verbosity . unlines . map renderTargetProblem -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = +renderTargetProblem :: RunTargetProblem -> String +renderTargetProblem (CommonProblem problem) = renderTargetProblemCommon "run" problem -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = +renderTargetProblem (NoneEnabled targetSelector targets) = renderTargetProblemNoneEnabled "run" targetSelector targets -renderTargetProblem (TargetProblemNoExes targetSelector) = +renderTargetProblem (CustomProblem (TargetProblemNoExes targetSelector)) = "Cannot run the target '" ++ showTargetSelector targetSelector ++ "' which refers to " ++ renderTargetSelector targetSelector ++ " because " ++ plural (targetSelectorPluralPkgs targetSelector) "it does" "they do" ++ " not contain any executables." -renderTargetProblem (TargetProblemNoTargets targetSelector) = +renderTargetProblem (NoTargets targetSelector) = case targetSelectorFilter targetSelector of Just kind | kind /= ExeKind -> "The run command is for running executables, but the target '" @@ -593,7 +618,8 @@ renderTargetProblem (TargetProblemNoTargets targetSelector) = _ -> renderTargetProblemNoTargets "run" targetSelector -renderTargetProblem (TargetProblemMatchesMultiple targetSelector targets) = +renderTargetProblem + (CustomProblem (TargetProblemMatchesMultiple targetSelector targets)) = "The run command is for running a single executable at once. The target '" ++ showTargetSelector targetSelector ++ "' refers to " ++ renderTargetSelector targetSelector ++ " which includes " @@ -605,13 +631,15 @@ renderTargetProblem (TargetProblemMatchesMultiple targetSelector targets) = [ExeKind, TestKind, BenchKind] ) ++ "." -renderTargetProblem (TargetProblemMultipleTargets selectorMap) = +renderTargetProblem + (CustomProblem (TargetProblemMultipleTargets selectorMap)) = "The run command is for running a single executable at once. The targets " ++ renderListCommaAnd [ "'" ++ showTargetSelector ts ++ "'" | ts <- ordNub (concatMap snd (concat (Map.elems selectorMap))) ] ++ " refer to different executables." -renderTargetProblem (TargetProblemComponentNotExe pkgid cname) = +renderTargetProblem + (CustomProblem (TargetProblemComponentNotExe pkgid cname)) = "The run command is for running executables, but the target '" ++ showTargetSelector targetSelector ++ "' refers to " ++ renderTargetSelector targetSelector ++ " from the package " @@ -619,7 +647,8 @@ renderTargetProblem (TargetProblemComponentNotExe pkgid cname) = where targetSelector = TargetComponent pkgid cname WholeComponent -renderTargetProblem (TargetProblemIsSubComponent pkgid cname subtarget) = +renderTargetProblem + (CustomProblem (TargetProblemIsSubComponent pkgid cname subtarget)) = "The run command can only run an executable as a whole, " ++ "not files or modules within them, but the target '" ++ showTargetSelector targetSelector ++ "' refers to " diff --git a/cabal-install/Distribution/Client/CmdTest.hs b/cabal-install/Distribution/Client/CmdTest.hs index 8b0a379e0b2..df9183ccbf1 100644 --- a/cabal-install/Distribution/Client/CmdTest.hs +++ b/cabal-install/Distribution/Client/CmdTest.hs @@ -8,13 +8,21 @@ module Distribution.Client.CmdTest ( testAction, -- * Internals exposed for testing - TargetProblem(..), + isSubComponentProblem, + notTestProblem, + noTestsProblem, selectPackageTargets, selectComponentTarget ) where import Distribution.Client.ProjectOrchestration import Distribution.Client.CmdErrorMessages + ( renderTargetSelector, showTargetSelector, targetSelectorFilter, plural, + renderTargetProblemCommon, renderTargetProblemNoneEnabled, + renderTargetProblemNoTargets, targetSelectorPluralPkgs ) +import Distribution.Client.TargetProblem + ( TargetProblem (..), commonTargetProblem, customTargetProblem + , noneEnabledTargetProblem, noTargetsProblem ) import Distribution.Client.Setup ( GlobalFlags(..), ConfigFlags(..), ConfigExFlags, InstallFlags ) @@ -113,7 +121,7 @@ testAction ( configFlags, configExFlags, installFlags $ resolveTargets selectPackageTargets selectComponentTarget - TargetProblemCommon + commonTargetProblem elaboratedPlan Nothing targetSelectors @@ -145,7 +153,7 @@ testAction ( configFlags, configExFlags, installFlags -- or fail if there are no test-suites or no buildable test-suites. -- selectPackageTargets :: TargetSelector - -> [AvailableTarget k] -> Either TargetProblem [k] + -> [AvailableTarget k] -> Either TestTargetProblem [k] selectPackageTargets targetSelector targets -- If there are any buildable test-suite targets then we select those @@ -154,15 +162,15 @@ selectPackageTargets targetSelector targets -- If there are test-suites but none are buildable then we report those | not (null targetsTests) - = Left (TargetProblemNoneEnabled targetSelector targetsTests) + = Left (noneEnabledTargetProblem targetSelector targetsTests) -- If there are no test-suite but some other targets then we report that | not (null targets) - = Left (TargetProblemNoTests targetSelector) + = Left (noTestsProblem targetSelector) -- If there are no targets at all then we report that | otherwise - = Left (TargetProblemNoTargets targetSelector) + = Left (noTargetsProblem targetSelector) where targetsTestsBuildable = selectBuildableTargets . filterTargetsKind TestKind @@ -180,34 +188,28 @@ selectPackageTargets targetSelector targets -- to the basic checks on being buildable etc. -- selectComponentTarget :: SubComponentTarget - -> AvailableTarget k -> Either TargetProblem k + -> AvailableTarget k -> Either TestTargetProblem k selectComponentTarget subtarget@WholeComponent t | CTestName _ <- availableTargetComponentName t - = either (Left . TargetProblemCommon) return $ + = either (Left . commonTargetProblem) return $ selectComponentTargetBasic subtarget t | otherwise - = Left (TargetProblemComponentNotTest (availableTargetPackageId t) - (availableTargetComponentName t)) + = Left (notTestProblem + (availableTargetPackageId t) + (availableTargetComponentName t)) selectComponentTarget subtarget t - = Left (TargetProblemIsSubComponent (availableTargetPackageId t) - (availableTargetComponentName t) - subtarget) + = Left (isSubComponentProblem + (availableTargetPackageId t) + (availableTargetComponentName t) + subtarget) -- | The various error conditions that can occur when matching a -- 'TargetSelector' against 'AvailableTarget's for the @test@ command. -- -data TargetProblem = - TargetProblemCommon TargetProblemCommon - - -- | The 'TargetSelector' matches targets but none are buildable - | TargetProblemNoneEnabled TargetSelector [AvailableTarget ()] - - -- | There are no targets at all - | TargetProblemNoTargets TargetSelector - +data TestProblem = -- | The 'TargetSelector' matches targets but no test-suites - | TargetProblemNoTests TargetSelector + TargetProblemNoTests TargetSelector -- | The 'TargetSelector' refers to a component that is not a test-suite | TargetProblemComponentNotTest PackageId ComponentName @@ -216,12 +218,30 @@ data TargetProblem = | TargetProblemIsSubComponent PackageId ComponentName SubComponentTarget deriving (Eq, Show) -reportTargetProblems :: Verbosity -> Flag Bool -> [TargetProblem] -> IO a + +type TestTargetProblem = TargetProblem TestProblem + + +noTestsProblem :: TargetSelector -> TargetProblem TestProblem +noTestsProblem = customTargetProblem . TargetProblemNoTests + +notTestProblem :: PackageId -> ComponentName -> TargetProblem TestProblem +notTestProblem pkgid name = customTargetProblem $ TargetProblemComponentNotTest pkgid name + +isSubComponentProblem + :: PackageId + -> ComponentName + -> SubComponentTarget + -> TargetProblem TestProblem +isSubComponentProblem pkgid name subcomponent = customTargetProblem $ + TargetProblemIsSubComponent pkgid name subcomponent + +reportTargetProblems :: Verbosity -> Flag Bool -> [TestTargetProblem] -> IO a reportTargetProblems verbosity failWhenNoTestSuites problems = case (failWhenNoTestSuites, problems) of - (Flag True, [TargetProblemNoTests _]) -> + (Flag True, [CustomProblem (TargetProblemNoTests _)]) -> die' verbosity problemsMessage - (_, [TargetProblemNoTests selector]) -> do + (_, [CustomProblem (TargetProblemNoTests selector)]) -> do notice verbosity (renderAllowedNoTestsProblem selector) System.Exit.exitSuccess (_, _) -> die' verbosity problemsMessage @@ -236,21 +256,21 @@ renderAllowedNoTestsProblem :: TargetSelector -> String renderAllowedNoTestsProblem selector = "No tests to run for " ++ renderTargetSelector selector -renderTargetProblem :: TargetProblem -> String -renderTargetProblem (TargetProblemCommon problem) = +renderTargetProblem :: TestTargetProblem -> String +renderTargetProblem (CommonProblem problem) = renderTargetProblemCommon "run" problem -renderTargetProblem (TargetProblemNoneEnabled targetSelector targets) = +renderTargetProblem (NoneEnabled targetSelector targets) = renderTargetProblemNoneEnabled "test" targetSelector targets -renderTargetProblem (TargetProblemNoTests targetSelector) = +renderTargetProblem (CustomProblem (TargetProblemNoTests targetSelector)) = "Cannot run tests for the target '" ++ showTargetSelector targetSelector ++ "' which refers to " ++ renderTargetSelector targetSelector ++ " because " ++ plural (targetSelectorPluralPkgs targetSelector) "it does" "they do" ++ " not contain any test suites." -renderTargetProblem (TargetProblemNoTargets targetSelector) = +renderTargetProblem (NoTargets targetSelector) = case targetSelectorFilter targetSelector of Just kind | kind /= TestKind -> "The test command is for running test suites, but the target '" @@ -260,7 +280,7 @@ renderTargetProblem (TargetProblemNoTargets targetSelector) = _ -> renderTargetProblemNoTargets "test" targetSelector -renderTargetProblem (TargetProblemComponentNotTest pkgid cname) = +renderTargetProblem (CustomProblem (TargetProblemComponentNotTest pkgid cname)) = "The test command is for running test suites, but the target '" ++ showTargetSelector targetSelector ++ "' refers to " ++ renderTargetSelector targetSelector ++ " from the package " @@ -268,7 +288,7 @@ renderTargetProblem (TargetProblemComponentNotTest pkgid cname) = where targetSelector = TargetComponent pkgid cname WholeComponent -renderTargetProblem (TargetProblemIsSubComponent pkgid cname subtarget) = +renderTargetProblem (CustomProblem (TargetProblemIsSubComponent pkgid cname subtarget)) = "The test command can only run test suites as a whole, " ++ "not files or modules within them, but the target '" ++ showTargetSelector targetSelector ++ "' refers to " diff --git a/cabal-install/Distribution/Client/ProjectOrchestration.hs b/cabal-install/Distribution/Client/ProjectOrchestration.hs index ff4deba5473..0f9e5999ba2 100644 --- a/cabal-install/Distribution/Client/ProjectOrchestration.hs +++ b/cabal-install/Distribution/Client/ProjectOrchestration.hs @@ -117,6 +117,8 @@ import Distribution.Client.ProjectBuilding import Distribution.Client.ProjectPlanOutput import Distribution.Client.RebuildMonad ( runRebuild ) +import Distribution.Client.TargetProblem + ( TargetProblemCommon(..) ) import Distribution.Client.Types ( GenericReadyPackage(..), UnresolvedSourcePackage , PackageSpecifier(..) @@ -788,32 +790,6 @@ selectComponentTargetBasic subtarget TargetBuildable targetKey _ -> Right targetKey -data TargetProblemCommon - = TargetNotInProject PackageName - | TargetAvailableInIndex PackageName - - | TargetComponentNotProjectLocal - PackageId ComponentName SubComponentTarget - - | TargetComponentNotBuildable - PackageId ComponentName SubComponentTarget - - | TargetOptionalStanzaDisabledByUser - PackageId ComponentName SubComponentTarget - - | TargetOptionalStanzaDisabledBySolver - PackageId ComponentName SubComponentTarget - - | TargetProblemUnknownComponent - PackageName (Either UnqualComponentName ComponentName) - - -- The target matching stuff only returns packages local to the project, - -- so these lookups should never fail, but if 'resolveTargets' is called - -- directly then of course it can. - | TargetProblemNoSuchPackage PackageId - | TargetProblemNoSuchComponent PackageId ComponentName - deriving (Eq, Show) - -- | Wrapper around 'ProjectPlanning.pruneInstallPlanToTargets' that adjusts -- for the extra unneeded info in the 'TargetsMap'. -- diff --git a/cabal-install/Distribution/Client/TargetProblem.hs b/cabal-install/Distribution/Client/TargetProblem.hs new file mode 100644 index 00000000000..81973aa773a --- /dev/null +++ b/cabal-install/Distribution/Client/TargetProblem.hs @@ -0,0 +1,87 @@ +module Distribution.Client.TargetProblem + ( TargetProblem(..), + TargetProblem', + TargetProblemCommon(..), + commonTargetProblem, + noneEnabledTargetProblem, + noTargetsProblem, + customTargetProblem, + ) +where + +import Distribution.Client.Compat.Prelude +import Distribution.Client.ProjectPlanning + ( AvailableTarget, + ) +import Distribution.Client.TargetSelector + ( TargetSelector, SubComponentTarget, + ) +import Distribution.Package + (PackageId, PackageName, + ) +import Distribution.Types.UnqualComponentName + ( UnqualComponentName, + ) +import Distribution.Simple.LocalBuildInfo + ( ComponentName(..), + ) +import Prelude () + +-- | Target problems that occur during project orchestration. +data TargetProblemCommon + = TargetNotInProject PackageName + | TargetAvailableInIndex PackageName + + | TargetComponentNotProjectLocal + PackageId ComponentName SubComponentTarget + + | TargetComponentNotBuildable + PackageId ComponentName SubComponentTarget + + | TargetOptionalStanzaDisabledByUser + PackageId ComponentName SubComponentTarget + + | TargetOptionalStanzaDisabledBySolver + PackageId ComponentName SubComponentTarget + + | TargetProblemUnknownComponent + PackageName (Either UnqualComponentName ComponentName) + + -- The target matching stuff only returns packages local to the project, + -- so these lookups should never fail, but if 'resolveTargets' is called + -- directly then of course it can. + | TargetProblemNoSuchPackage PackageId + | TargetProblemNoSuchComponent PackageId ComponentName + deriving (Eq, Show) + + + +-- | Type alias for a 'TargetProblem' with no user-defined problems/errors. +-- +-- Can use the utilities below for reporting/rendering problems. +type TargetProblem' = TargetProblem () + +-- | The various error conditions that can occur when matching a +-- 'TargetSelector' against 'AvailableTarget's which can be extended +-- with command specific target problems as described by 'e'. +data TargetProblem e + = CommonProblem TargetProblemCommon + | -- | The 'TargetSelector' matches benchmarks but none are buildable + NoneEnabled TargetSelector [AvailableTarget ()] + | -- | There are no targets at all + NoTargets TargetSelector + | -- | A custom target problem + CustomProblem e + deriving (Eq, Show) + +commonTargetProblem :: TargetProblemCommon -> TargetProblem e +commonTargetProblem = CommonProblem + +noneEnabledTargetProblem :: TargetSelector -> [AvailableTarget ()] -> TargetProblem e +noneEnabledTargetProblem = NoneEnabled + +noTargetsProblem :: TargetSelector -> TargetProblem e +noTargetsProblem = NoTargets + +customTargetProblem :: e -> TargetProblem e +customTargetProblem = CustomProblem diff --git a/cabal-install/cabal-install.cabal b/cabal-install/cabal-install.cabal index 3bc1b551e83..8bc5df5f6ed 100644 --- a/cabal-install/cabal-install.cabal +++ b/cabal-install/cabal-install.cabal @@ -251,6 +251,7 @@ executable cabal Distribution.Client.SrcDist Distribution.Client.Store Distribution.Client.Tar + Distribution.Client.TargetProblem Distribution.Client.TargetSelector Distribution.Client.Targets Distribution.Client.Types diff --git a/cabal-install/cabal-install.cabal.pp b/cabal-install/cabal-install.cabal.pp index b208a8be99a..f5bdeb276d2 100644 --- a/cabal-install/cabal-install.cabal.pp +++ b/cabal-install/cabal-install.cabal.pp @@ -192,6 +192,7 @@ Distribution.Client.SrcDist Distribution.Client.Store Distribution.Client.Tar + Distribution.Client.TargetProblem Distribution.Client.TargetSelector Distribution.Client.Targets Distribution.Client.Types diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index ce3f614ff8c..c508880f2b9 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -23,6 +23,8 @@ import Distribution.Client.ProjectPlanning.Types import Distribution.Client.ProjectBuilding import Distribution.Client.ProjectOrchestration ( resolveTargets, TargetProblemCommon(..), distinctTargetComponents ) +import Distribution.Client.TargetProblem + ( TargetProblem', commonTargetProblem, noneEnabledTargetProblem, noTargetsProblem ) import Distribution.Client.Types ( PackageLocation(..), UnresolvedSourcePackage , PackageSpecifier(..) ) @@ -534,18 +536,18 @@ testTargetProblemsCommon config0 = do [ (packageName p, packageId p) | p <- InstallPlan.toList elaboratedPlan ] - cases :: [( TargetSelector -> CmdBuild.TargetProblem + cases :: [( TargetSelector -> TargetProblem' , TargetSelector )] cases = [ -- Cannot resolve packages outside of the project - ( \_ -> CmdBuild.TargetProblemCommon $ + ( \_ -> commonTargetProblem $ TargetProblemNoSuchPackage "foobar" , mkTargetPackage "foobar" ) -- We cannot currently build components like testsuites or -- benchmarks from packages that are not local to the project - , ( \_ -> CmdBuild.TargetProblemCommon $ + , ( \_ -> commonTargetProblem $ TargetComponentNotProjectLocal (pkgIdMap Map.! "filepath") (CTestName "filepath-tests") WholeComponent @@ -553,19 +555,19 @@ testTargetProblemsCommon config0 = do (CTestName "filepath-tests") ) -- Components can be explicitly @buildable: False@ - , ( \_ -> CmdBuild.TargetProblemCommon $ + , ( \_ -> commonTargetProblem $ TargetComponentNotBuildable "q-0.1" (CExeName "buildable-false") WholeComponent , mkTargetComponent "q-0.1" (CExeName "buildable-false") ) -- Testsuites and benchmarks can be disabled by the solver if it -- cannot satisfy deps - , ( \_ -> CmdBuild.TargetProblemCommon $ + , ( \_ -> commonTargetProblem $ TargetOptionalStanzaDisabledBySolver "q-0.1" (CTestName "solver-disabled") WholeComponent , mkTargetComponent "q-0.1" (CTestName "solver-disabled") ) -- Testsuites and benchmarks can be disabled explicitly by the -- user via config - , ( \_ -> CmdBuild.TargetProblemCommon $ + , ( \_ -> commonTargetProblem $ TargetOptionalStanzaDisabledByUser "q-0.1" (CBenchName "user-disabled") WholeComponent , mkTargetComponent "q-0.1" (CBenchName "user-disabled") ) @@ -573,14 +575,14 @@ testTargetProblemsCommon config0 = do -- An unknown package. The target selector resolution should only -- produce known packages, so this should not happen with the -- output from 'readTargetSelectors'. - , ( \_ -> CmdBuild.TargetProblemCommon $ + , ( \_ -> commonTargetProblem $ TargetProblemNoSuchPackage "foobar" , mkTargetPackage "foobar" ) -- An unknown component of a known package. The target selector -- resolution should only produce known packages, so this should -- not happen with the output from 'readTargetSelectors'. - , ( \_ -> CmdBuild.TargetProblemCommon $ + , ( \_ -> commonTargetProblem $ TargetProblemNoSuchComponent "q-0.1" (CExeName "no-such") , mkTargetComponent "q-0.1" (CExeName "no-such") ) ] @@ -588,7 +590,7 @@ testTargetProblemsCommon config0 = do elaboratedPlan CmdBuild.selectPackageTargets CmdBuild.selectComponentTarget - CmdBuild.TargetProblemCommon + commonTargetProblem cases where testdir = "targets/complex" @@ -612,8 +614,8 @@ testTargetProblemsBuild config reportSubCase = do "targets/empty-pkg" config CmdBuild.selectPackageTargets CmdBuild.selectComponentTarget - CmdBuild.TargetProblemCommon - [ ( CmdBuild.TargetProblemNoTargets, mkTargetPackage "p-0.1" ) + commonTargetProblem + [ ( noTargetsProblem, mkTargetPackage "p-0.1" ) ] reportSubCase "all-disabled" @@ -626,8 +628,8 @@ testTargetProblemsBuild config reportSubCase = do } CmdBuild.selectPackageTargets CmdBuild.selectComponentTarget - CmdBuild.TargetProblemCommon - [ ( flip CmdBuild.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CBenchName "user-disabled") TargetDisabledByUser True , AvailableTarget "p-0.1" (CTestName "solver-disabled") @@ -653,7 +655,7 @@ testTargetProblemsBuild config reportSubCase = do elaboratedPlan CmdBuild.selectPackageTargets CmdBuild.selectComponentTarget - CmdBuild.TargetProblemCommon + commonTargetProblem [ mkTargetPackage "p-0.1" ] [ ("p-0.1-inplace", (CLibName LMainLibName)) , ("p-0.1-inplace-a-benchmark", CBenchName "a-benchmark") @@ -675,7 +677,7 @@ testTargetProblemsBuild config reportSubCase = do elaboratedPlan CmdBuild.selectPackageTargets CmdBuild.selectComponentTarget - CmdBuild.TargetProblemCommon + commonTargetProblem [ mkTargetPackage "p-0.1" ] [ ("p-0.1-inplace", (CLibName LMainLibName)) , ("p-0.1-inplace-an-exe", CExeName "an-exe") @@ -690,7 +692,7 @@ testTargetProblemsBuild config reportSubCase = do elaboratedPlan CmdBuild.selectPackageTargets CmdBuild.selectComponentTarget - CmdBuild.TargetProblemCommon + commonTargetProblem [ TargetPackage TargetExplicitNamed ["p-0.1"] (Just TestKind) , TargetPackage TargetExplicitNamed ["p-0.1"] (Just BenchKind) ] @@ -707,8 +709,8 @@ testTargetProblemsRepl config reportSubCase = do "targets/multiple-libs" config CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon - [ ( flip CmdRepl.TargetProblemMatchesMultiple + commonTargetProblem + [ ( flip CmdRepl.matchesMultipleProblem [ AvailableTarget "p-0.1" (CLibName LMainLibName) (TargetBuildable () TargetRequestedByDefault) True , AvailableTarget "q-0.1" (CLibName LMainLibName) @@ -722,8 +724,8 @@ testTargetProblemsRepl config reportSubCase = do "targets/multiple-exes" config CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon - [ ( flip CmdRepl.TargetProblemMatchesMultiple + commonTargetProblem + [ ( flip CmdRepl.matchesMultipleProblem [ AvailableTarget "p-0.1" (CExeName "p2") (TargetBuildable () TargetRequestedByDefault) True , AvailableTarget "p-0.1" (CExeName "p1") @@ -737,8 +739,8 @@ testTargetProblemsRepl config reportSubCase = do "targets/multiple-tests" config CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon - [ ( flip CmdRepl.TargetProblemMatchesMultiple + commonTargetProblem + [ ( flip CmdRepl.matchesMultipleProblem [ AvailableTarget "p-0.1" (CTestName "p2") (TargetBuildable () TargetNotRequestedByDefault) True , AvailableTarget "p-0.1" (CTestName "p1") @@ -753,7 +755,7 @@ testTargetProblemsRepl config reportSubCase = do elaboratedPlan CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon + commonTargetProblem [ mkTargetComponent "p-0.1" (CExeName "p1") , mkTargetComponent "p-0.1" (CExeName "p2") ] @@ -766,8 +768,8 @@ testTargetProblemsRepl config reportSubCase = do "targets/libs-disabled" config CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon - [ ( flip CmdRepl.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CLibName LMainLibName) TargetNotBuildable True ] , mkTargetPackage "p-0.1" ) ] @@ -777,8 +779,8 @@ testTargetProblemsRepl config reportSubCase = do "targets/exes-disabled" config CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon - [ ( flip CmdRepl.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CExeName "p") TargetNotBuildable True ] , mkTargetPackage "p-0.1" ) @@ -789,8 +791,8 @@ testTargetProblemsRepl config reportSubCase = do "targets/test-only" config CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon - [ ( flip CmdRepl.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CTestName "pexe") (TargetBuildable () TargetNotRequestedByDefault) True ] @@ -802,8 +804,8 @@ testTargetProblemsRepl config reportSubCase = do "targets/empty-pkg" config CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon - [ ( CmdRepl.TargetProblemNoTargets, mkTargetPackage "p-0.1" ) + commonTargetProblem + [ ( noTargetsProblem, mkTargetPackage "p-0.1" ) ] reportSubCase "requested component kinds" @@ -813,7 +815,7 @@ testTargetProblemsRepl config reportSubCase = do elaboratedPlan CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon + commonTargetProblem [ TargetPackage TargetExplicitNamed ["p-0.1"] Nothing ] [ ("p-0.1-inplace", (CLibName LMainLibName)) ] -- When we select the package with an explicit filter then we get those @@ -822,14 +824,14 @@ testTargetProblemsRepl config reportSubCase = do elaboratedPlan CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon + commonTargetProblem [ TargetPackage TargetExplicitNamed ["p-0.1"] (Just TestKind) ] [ ("p-0.1-inplace-a-testsuite", CTestName "a-testsuite") ] assertProjectDistinctTargets elaboratedPlan CmdRepl.selectPackageTargets CmdRepl.selectComponentTarget - CmdRepl.TargetProblemCommon + commonTargetProblem [ TargetPackage TargetExplicitNamed ["p-0.1"] (Just BenchKind) ] [ ("p-0.1-inplace-a-benchmark", CBenchName "a-benchmark") ] @@ -842,8 +844,8 @@ testTargetProblemsRun config reportSubCase = do "targets/multiple-exes" config CmdRun.selectPackageTargets CmdRun.selectComponentTarget - CmdRun.TargetProblemCommon - [ ( flip CmdRun.TargetProblemMatchesMultiple + commonTargetProblem + [ ( flip CmdRun.matchesMultipleProblem [ AvailableTarget "p-0.1" (CExeName "p2") (TargetBuildable () TargetRequestedByDefault) True , AvailableTarget "p-0.1" (CExeName "p1") @@ -858,7 +860,7 @@ testTargetProblemsRun config reportSubCase = do elaboratedPlan CmdRun.selectPackageTargets CmdRun.selectComponentTarget - CmdRun.TargetProblemCommon + commonTargetProblem [ mkTargetComponent "p-0.1" (CExeName "p1") , mkTargetComponent "p-0.1" (CExeName "p2") ] @@ -871,8 +873,8 @@ testTargetProblemsRun config reportSubCase = do "targets/exes-disabled" config CmdRun.selectPackageTargets CmdRun.selectComponentTarget - CmdRun.TargetProblemCommon - [ ( flip CmdRun.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CExeName "p") TargetNotBuildable True ] , mkTargetPackage "p-0.1" ) @@ -883,8 +885,8 @@ testTargetProblemsRun config reportSubCase = do "targets/empty-pkg" config CmdRun.selectPackageTargets CmdRun.selectComponentTarget - CmdRun.TargetProblemCommon - [ ( CmdRun.TargetProblemNoTargets, mkTargetPackage "p-0.1" ) + commonTargetProblem + [ ( noTargetsProblem, mkTargetPackage "p-0.1" ) ] reportSubCase "lib-only" @@ -892,8 +894,8 @@ testTargetProblemsRun config reportSubCase = do "targets/lib-only" config CmdRun.selectPackageTargets CmdRun.selectComponentTarget - CmdRun.TargetProblemCommon - [ ( CmdRun.TargetProblemNoExes, mkTargetPackage "p-0.1" ) + commonTargetProblem + [ ( CmdRun.noExesProblem, mkTargetPackage "p-0.1" ) ] @@ -910,8 +912,8 @@ testTargetProblemsTest config reportSubCase = do } CmdTest.selectPackageTargets CmdTest.selectComponentTarget - CmdTest.TargetProblemCommon - [ ( flip CmdTest.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CTestName "user-disabled") TargetDisabledByUser True , AvailableTarget "p-0.1" (CTestName "solver-disabled") @@ -926,8 +928,8 @@ testTargetProblemsTest config reportSubCase = do config CmdTest.selectPackageTargets CmdTest.selectComponentTarget - CmdTest.TargetProblemCommon - [ ( flip CmdTest.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CTestName "user-disabled") TargetDisabledBySolver True , AvailableTarget "p-0.1" (CTestName "solver-disabled") @@ -935,7 +937,7 @@ testTargetProblemsTest config reportSubCase = do ] , mkTargetPackage "p-0.1" ) - , ( flip CmdTest.TargetProblemNoneEnabled + , ( flip noneEnabledTargetProblem [ AvailableTarget "q-0.1" (CTestName "buildable-false") TargetNotBuildable True ] @@ -947,8 +949,8 @@ testTargetProblemsTest config reportSubCase = do "targets/empty-pkg" config CmdTest.selectPackageTargets CmdTest.selectComponentTarget - CmdTest.TargetProblemCommon - [ ( CmdTest.TargetProblemNoTargets, mkTargetPackage "p-0.1" ) + commonTargetProblem + [ ( noTargetsProblem, mkTargetPackage "p-0.1" ) ] reportSubCase "no tests" @@ -957,9 +959,9 @@ testTargetProblemsTest config reportSubCase = do config CmdTest.selectPackageTargets CmdTest.selectComponentTarget - CmdTest.TargetProblemCommon - [ ( CmdTest.TargetProblemNoTests, mkTargetPackage "p-0.1" ) - , ( CmdTest.TargetProblemNoTests, mkTargetPackage "q-0.1" ) + commonTargetProblem + [ ( CmdTest.noTestsProblem, mkTargetPackage "p-0.1" ) + , ( CmdTest.noTestsProblem, mkTargetPackage "q-0.1" ) ] reportSubCase "not a test" @@ -968,24 +970,24 @@ testTargetProblemsTest config reportSubCase = do config CmdTest.selectPackageTargets CmdTest.selectComponentTarget - CmdTest.TargetProblemCommon $ - [ ( const (CmdTest.TargetProblemComponentNotTest + commonTargetProblem $ + [ ( const (CmdTest.notTestProblem "p-0.1" (CLibName LMainLibName)) , mkTargetComponent "p-0.1" (CLibName LMainLibName) ) - , ( const (CmdTest.TargetProblemComponentNotTest + , ( const (CmdTest.notTestProblem "p-0.1" (CExeName "an-exe")) , mkTargetComponent "p-0.1" (CExeName "an-exe") ) - , ( const (CmdTest.TargetProblemComponentNotTest + , ( const (CmdTest.notTestProblem "p-0.1" (CFLibName "libp")) , mkTargetComponent "p-0.1" (CFLibName "libp") ) - , ( const (CmdTest.TargetProblemComponentNotTest + , ( const (CmdTest.notTestProblem "p-0.1" (CBenchName "a-benchmark")) , mkTargetComponent "p-0.1" (CBenchName "a-benchmark") ) ] ++ - [ ( const (CmdTest.TargetProblemIsSubComponent + [ ( const (CmdTest.isSubComponentProblem "p-0.1" cname (ModuleTarget modname)) , mkTargetModule "p-0.1" cname modname ) | (cname, modname) <- [ (CTestName "a-testsuite", "TestModule") @@ -994,7 +996,7 @@ testTargetProblemsTest config reportSubCase = do , ((CLibName LMainLibName), "P") ] ] ++ - [ ( const (CmdTest.TargetProblemIsSubComponent + [ ( const (CmdTest.isSubComponentProblem "p-0.1" cname (FileTarget fname)) , mkTargetFile "p-0.1" cname fname) | (cname, fname) <- [ (CTestName "a-testsuite", "Test.hs") @@ -1017,8 +1019,8 @@ testTargetProblemsBench config reportSubCase = do } CmdBench.selectPackageTargets CmdBench.selectComponentTarget - CmdBench.TargetProblemCommon - [ ( flip CmdBench.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CBenchName "user-disabled") TargetDisabledByUser True , AvailableTarget "p-0.1" (CBenchName "solver-disabled") @@ -1033,8 +1035,8 @@ testTargetProblemsBench config reportSubCase = do config CmdBench.selectPackageTargets CmdBench.selectComponentTarget - CmdBench.TargetProblemCommon - [ ( flip CmdBench.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CBenchName "user-disabled") TargetDisabledBySolver True , AvailableTarget "p-0.1" (CBenchName "solver-disabled") @@ -1042,7 +1044,7 @@ testTargetProblemsBench config reportSubCase = do ] , mkTargetPackage "p-0.1" ) - , ( flip CmdBench.TargetProblemNoneEnabled + , ( flip noneEnabledTargetProblem [ AvailableTarget "q-0.1" (CBenchName "buildable-false") TargetNotBuildable True ] @@ -1054,8 +1056,8 @@ testTargetProblemsBench config reportSubCase = do "targets/empty-pkg" config CmdBench.selectPackageTargets CmdBench.selectComponentTarget - CmdBench.TargetProblemCommon - [ ( CmdBench.TargetProblemNoTargets, mkTargetPackage "p-0.1" ) + commonTargetProblem + [ ( noTargetsProblem, mkTargetPackage "p-0.1" ) ] reportSubCase "no benchmarks" @@ -1064,9 +1066,9 @@ testTargetProblemsBench config reportSubCase = do config CmdBench.selectPackageTargets CmdBench.selectComponentTarget - CmdBench.TargetProblemCommon - [ ( CmdBench.TargetProblemNoBenchmarks, mkTargetPackage "p-0.1" ) - , ( CmdBench.TargetProblemNoBenchmarks, mkTargetPackage "q-0.1" ) + commonTargetProblem + [ ( CmdBench.noBenchmarksProblem, mkTargetPackage "p-0.1" ) + , ( CmdBench.noBenchmarksProblem, mkTargetPackage "q-0.1" ) ] reportSubCase "not a benchmark" @@ -1075,24 +1077,24 @@ testTargetProblemsBench config reportSubCase = do config CmdBench.selectPackageTargets CmdBench.selectComponentTarget - CmdBench.TargetProblemCommon $ - [ ( const (CmdBench.TargetProblemComponentNotBenchmark + commonTargetProblem $ + [ ( const (CmdBench.componentNotBenchmarkProblem "p-0.1" (CLibName LMainLibName)) , mkTargetComponent "p-0.1" (CLibName LMainLibName) ) - , ( const (CmdBench.TargetProblemComponentNotBenchmark + , ( const (CmdBench.componentNotBenchmarkProblem "p-0.1" (CExeName "an-exe")) , mkTargetComponent "p-0.1" (CExeName "an-exe") ) - , ( const (CmdBench.TargetProblemComponentNotBenchmark + , ( const (CmdBench.componentNotBenchmarkProblem "p-0.1" (CFLibName "libp")) , mkTargetComponent "p-0.1" (CFLibName "libp") ) - , ( const (CmdBench.TargetProblemComponentNotBenchmark + , ( const (CmdBench.componentNotBenchmarkProblem "p-0.1" (CTestName "a-testsuite")) , mkTargetComponent "p-0.1" (CTestName "a-testsuite") ) ] ++ - [ ( const (CmdBench.TargetProblemIsSubComponent + [ ( const (CmdBench.isSubComponentProblem "p-0.1" cname (ModuleTarget modname)) , mkTargetModule "p-0.1" cname modname ) | (cname, modname) <- [ (CTestName "a-testsuite", "TestModule") @@ -1101,7 +1103,7 @@ testTargetProblemsBench config reportSubCase = do , ((CLibName LMainLibName), "P") ] ] ++ - [ ( const (CmdBench.TargetProblemIsSubComponent + [ ( const (CmdBench.isSubComponentProblem "p-0.1" cname (FileTarget fname)) , mkTargetFile "p-0.1" cname fname) | (cname, fname) <- [ (CTestName "a-testsuite", "Test.hs") @@ -1121,8 +1123,8 @@ testTargetProblemsHaddock config reportSubCase = do (let haddockFlags = mkHaddockFlags False True True False in CmdHaddock.selectPackageTargets haddockFlags) CmdHaddock.selectComponentTarget - CmdHaddock.TargetProblemCommon - [ ( flip CmdHaddock.TargetProblemNoneEnabled + commonTargetProblem + [ ( flip noneEnabledTargetProblem [ AvailableTarget "p-0.1" (CBenchName "user-disabled") TargetDisabledByUser True , AvailableTarget "p-0.1" (CTestName "solver-disabled") @@ -1141,8 +1143,8 @@ testTargetProblemsHaddock config reportSubCase = do (let haddockFlags = mkHaddockFlags False False False False in CmdHaddock.selectPackageTargets haddockFlags) CmdHaddock.selectComponentTarget - CmdHaddock.TargetProblemCommon - [ ( CmdHaddock.TargetProblemNoTargets, mkTargetPackage "p-0.1" ) + commonTargetProblem + [ ( noTargetsProblem, mkTargetPackage "p-0.1" ) ] reportSubCase "enabled component kinds" @@ -1154,7 +1156,7 @@ testTargetProblemsHaddock config reportSubCase = do elaboratedPlan (CmdHaddock.selectPackageTargets haddockFlags) CmdHaddock.selectComponentTarget - CmdHaddock.TargetProblemCommon + commonTargetProblem [ mkTargetPackage "p-0.1" ] [ ("p-0.1-inplace", (CLibName LMainLibName)) , ("p-0.1-inplace-a-benchmark", CBenchName "a-benchmark") @@ -1171,7 +1173,7 @@ testTargetProblemsHaddock config reportSubCase = do elaboratedPlan (CmdHaddock.selectPackageTargets haddockFlags) CmdHaddock.selectComponentTarget - CmdHaddock.TargetProblemCommon + commonTargetProblem [ mkTargetPackage "p-0.1" ] [ ("p-0.1-inplace", (CLibName LMainLibName)) ] @@ -1183,7 +1185,7 @@ testTargetProblemsHaddock config reportSubCase = do elaboratedPlan (CmdHaddock.selectPackageTargets haddockFlags) CmdHaddock.selectComponentTarget - CmdHaddock.TargetProblemCommon + commonTargetProblem [ TargetPackage TargetExplicitNamed ["p-0.1"] (Just FLibKind) , TargetPackage TargetExplicitNamed ["p-0.1"] (Just ExeKind) , TargetPackage TargetExplicitNamed ["p-0.1"] (Just TestKind) @@ -1330,7 +1332,7 @@ testExceptionInConfigureStep config = do (_pkga1, failure) <- expectPackageFailed plan res pkgidA1 case buildFailureReason failure of ConfigureFailed _ -> return () - _ -> assertFailure $ "expected ConfigureFailed, got " ++ show failure + _ -> assertFailure $ "expected ConfigureFailed, got " ++ show failure cleanProject testdir where testdir = "exception/configure"