From a056e6d3363e537f4c7ac8512a817451c52da709 Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita Date: Mon, 4 Dec 2023 11:28:39 +0000 Subject: [PATCH] HPC: Error out on multi-package when coverage is enabled (#9493) --- cabal-install/src/Distribution/Client/CmdTest.hs | 6 ++++++ cabal-install/src/Distribution/Client/Errors.hs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/cabal-install/src/Distribution/Client/CmdTest.hs b/cabal-install/src/Distribution/Client/CmdTest.hs index 74fcc3a78b2..fff56d3b80d 100644 --- a/cabal-install/src/Distribution/Client/CmdTest.hs +++ b/cabal-install/src/Distribution/Client/CmdTest.hs @@ -69,6 +69,8 @@ import Distribution.Client.Errors import GHC.Environment ( getFullArgs ) +import Distribution.Client.ProjectConfig.Types (ProjectConfig(projectConfigLocalPackages)) +import Distribution.Client.ProjectConfig (PackageConfig(packageConfigCoverage)) testCommand :: CommandUI (NixStyleFlags ()) testCommand = @@ -125,6 +127,10 @@ testAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO () testAction flags@NixStyleFlags{..} targetStrings globalFlags = do baseCtx <- establishProjectBaseContext verbosity cliConfig OtherCommand + -- Multi package coverage is not supported (see cabal#9493) + when (length (localPackages baseCtx) > 1 && fromFlagOrDefault False (packageConfigCoverage (projectConfigLocalPackages $ projectConfig baseCtx))) $ + dieWithException verbosity MultiPackageCoverageUnsupported + targetSelectors <- either (reportTargetSelectorProblems verbosity) return =<< readTargetSelectors (localPackages baseCtx) (Just TestKind) targetStrings diff --git a/cabal-install/src/Distribution/Client/Errors.hs b/cabal-install/src/Distribution/Client/Errors.hs index ada3eca5268..3d39c4a0e84 100644 --- a/cabal-install/src/Distribution/Client/Errors.hs +++ b/cabal-install/src/Distribution/Client/Errors.hs @@ -184,6 +184,7 @@ data CabalInstallException | CorruptedIndexCache String | UnusableIndexState RemoteRepo Timestamp Timestamp | MissingPackageList RemoteRepo + | MultiPackageCoverageUnsupported deriving (Show, Typeable) exceptionCodeCabalInstall :: CabalInstallException -> Int @@ -334,6 +335,7 @@ exceptionCodeCabalInstall e = case e of CorruptedIndexCache{} -> 7158 UnusableIndexState{} -> 7159 MissingPackageList{} -> 7160 + MultiPackageCoverageUnsupported -> 7161 exceptionMessageCabalInstall :: CabalInstallException -> String exceptionMessageCabalInstall e = case e of @@ -849,6 +851,9 @@ exceptionMessageCabalInstall e = case e of "The package list for '" ++ unRepoName (remoteRepoName repoRemote) ++ "' does not exist. Run 'cabal update' to download it." + MultiPackageCoverageUnsupported -> + "--enable-coverage was specified, but program coverage is not supported in " + ++ "multiple package projects because of a HPC limitation (see cabal#9493)." instance Exception (VerboseException CabalInstallException) where displayException :: VerboseException CabalInstallException -> [Char]