Skip to content

Commit

Permalink
Fourmolu formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-romes committed Dec 4, 2023
1 parent 0545169 commit a574757
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 52 deletions.
1 change: 0 additions & 1 deletion Cabal/src/Distribution/Simple/Flag.hs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ mergeListFlag :: Flag [a] -> Flag [a] -> Flag [a]
mergeListFlag currentFlags v =
Flag $ concat (flagToList currentFlags ++ flagToList v)


-- | Types that represent boolean flags.
class BooleanFlag a where
asBool :: a -> Bool
Expand Down
11 changes: 5 additions & 6 deletions Cabal/src/Distribution/Simple/Hpc.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}

-----------------------------------------------------------------------------

Expand Down Expand Up @@ -35,20 +35,20 @@ import Distribution.PackageDescription
)
import qualified Distribution.PackageDescription as PD
import Distribution.Pretty
import Distribution.Simple.Flag (fromFlagOrDefault)
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo (..))
import Distribution.Simple.Program
( hpcProgram
, requireProgramVersion
)
import Distribution.Simple.Program.Hpc (markup, union)
import Distribution.Simple.Setup (TestFlags (..))
import Distribution.Simple.Utils (notice)
import Distribution.Types.UnqualComponentName
import Distribution.Verbosity (Verbosity ())
import Distribution.Version (anyVersion)
import System.Directory (createDirectoryIfMissing, doesFileExist)
import System.FilePath
import Distribution.Simple.Setup (TestFlags(..))
import Distribution.Simple.Flag (fromFlagOrDefault)

-- -------------------------------------------------------------------------
-- Haskell Program Coverage
Expand Down Expand Up @@ -152,14 +152,14 @@ markupPackage verbosity TestFlags{testCoverageDistPrefs, testCoverageLibsModules
tixFilePath testDistPref way testName'
-- And call 'markupPackage' once per `test` invocation with all the
-- testsuites to run, which results in multiple tix files being considered
_ -> do
_ -> do
let excluded = concatMap testModules suites ++ [main]
pkgName = prettyShow $ PD.package pkg_descr
summedTixFile = tixFilePath testDistPref way pkgName
createDirectoryIfMissing True $ takeDirectory summedTixFile
union hpc verbosity tixFiles summedTixFile excluded
return summedTixFile

markup hpc hpcVer verbosity tixFile mixDirs htmlDir' included
notice verbosity $
"Package coverage report written to "
Expand All @@ -170,4 +170,3 @@ markupPackage verbosity TestFlags{testCoverageDistPrefs, testCoverageLibsModules
testNames = fmap (unUnqualComponentName . testName) suites
mixDirs = map (`mixDir` way) (fromFlagOrDefault [] testCoverageDistPrefs)
included = fromFlagOrDefault [] testCoverageLibsModules

61 changes: 31 additions & 30 deletions Cabal/src/Distribution/Simple/Setup/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import Distribution.Simple.Utils
import Distribution.Verbosity
import qualified Text.PrettyPrint as Disp

import Distribution.Simple.Setup.Common
import Distribution.ModuleName (ModuleName)
import Distribution.Simple.Setup.Common

-- ------------------------------------------------------------

Expand Down Expand Up @@ -98,7 +98,6 @@ data TestFlags = TestFlags
-- excludes indefinite libraries and instantiations because HPC does not
-- support backpack - Nov. 2023). Cabal uses these paths as dist prefixes to
-- determine the path to the `mix` dirs of each component to cover.

, -- TODO: think about if/how options are passed to test exes
testOptions :: [PathTemplate]
}
Expand Down Expand Up @@ -223,35 +222,37 @@ testOptions' showOrParseArgs =
(\v flags -> flags{testFailWhenNoTestSuites = v})
trueArg
, option
[]
["coverage-module"]
"Module of a project-local library to include in the HPC report"
testCoverageLibsModules
(\v flags ->
flags{ testCoverageLibsModules =
mergeListFlag (testCoverageLibsModules flags) v
}
)
( reqArg'
"MODULE"
(Flag . (: []) . fromString)
(fmap prettyShow . fromFlagOrDefault [])
)
[]
["coverage-module"]
"Module of a project-local library to include in the HPC report"
testCoverageLibsModules
( \v flags ->
flags
{ testCoverageLibsModules =
mergeListFlag (testCoverageLibsModules flags) v
}
)
( reqArg'
"MODULE"
(Flag . (: []) . fromString)
(fmap prettyShow . fromFlagOrDefault [])
)
, option
[]
["coverage-dist-dir"]
"The directory where Cabal puts generated build files of an HPC enabled component"
testCoverageDistPrefs
(\v flags ->
flags{ testCoverageDistPrefs =
mergeListFlag (testCoverageDistPrefs flags) v
}
)
( reqArg'
"DIR"
(Flag . (: []))
(fromFlagOrDefault [])
)
[]
["coverage-dist-dir"]
"The directory where Cabal puts generated build files of an HPC enabled component"
testCoverageDistPrefs
( \v flags ->
flags
{ testCoverageDistPrefs =
mergeListFlag (testCoverageDistPrefs flags) v
}
)
( reqArg'
"DIR"
(Flag . (: []))
(fromFlagOrDefault [])
)
, option
[]
["test-options"]
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/CmdTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ import Distribution.Verbosity
import qualified System.Exit (exitSuccess)

import Distribution.Client.Errors
import Distribution.Client.ProjectConfig (PackageConfig (packageConfigCoverage))
import Distribution.Client.ProjectConfig.Types (ProjectConfig (projectConfigLocalPackages))
import GHC.Environment
( getFullArgs
)
import Distribution.Client.ProjectConfig.Types (ProjectConfig(projectConfigLocalPackages))
import Distribution.Client.ProjectConfig (PackageConfig(packageConfigCoverage))

testCommand :: CommandUI (NixStyleFlags ())
testCommand =
Expand Down
30 changes: 17 additions & 13 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NoMonoLocalBinds #-} -- MUST come after TypeFamilies because TypeFamilies imply MonoLocalBinds
-- MUST come after TypeFamilies because TypeFamilies imply MonoLocalBinds
{-# LANGUAGE NoMonoLocalBinds #-}

-- | Planning how to build everything in a project.
module Distribution.Client.ProjectPlanning
Expand Down Expand Up @@ -148,10 +149,11 @@ import Distribution.Simple.Program.Db
import Distribution.Simple.Program.Find
import Distribution.Simple.Setup
( Flag (..)
, TestFlags (testCoverageDistPrefs)
, flagToList
, flagToMaybe
, fromFlagOrDefault
, toFlag, TestFlags (testCoverageDistPrefs)
, toFlag
)
import qualified Distribution.Simple.Setup as Cabal
import Distribution.System
Expand Down Expand Up @@ -4306,7 +4308,7 @@ setupHsTestFlags plan (ElaboratedConfiguredPackage{..}) sharedConfig verbosity d
covLibsDistPref = map (distBuildDirectory distDirLayout . elabDistDirParams sharedConfig) librariesToCover
-- The list of modules from libraries to consider in hpc, that Cabal passes to the hpc markup call
-- This list includes all modules, not only the exposed ones.
covIncludeModules = concatMap (\ElaboratedConfiguredPackage{elabModuleShape=modShape} -> Map.keys $ modShapeProvides modShape) librariesToCover
covIncludeModules = concatMap (\ElaboratedConfiguredPackage{elabModuleShape = modShape} -> Map.keys $ modShapeProvides modShape) librariesToCover

-- The list of non-pre-existing libraries without module holes, i.e. the
-- main library and sub-libraries components of all the local packages in
Expand All @@ -4316,18 +4318,21 @@ setupHsTestFlags plan (ElaboratedConfiguredPackage{..}) sharedConfig verbosity d
-- this seemingly includes the packages that are not local to the project?!
-- Weird, because we filter on localToProject!
-- Try it on cabal-install: cabal test --enable-coverage cabal-install
librariesToCover
= mapMaybe (\case
InstallPlan.Installed elab@ElaboratedConfiguredPackage{elabModuleShape=modShape}
librariesToCover =
mapMaybe
( \case
InstallPlan.Installed elab@ElaboratedConfiguredPackage{elabModuleShape = modShape}
| elabLocalToProject
, not (isIndefiniteOrInstantiation modShape)
-> Just elab
InstallPlan.Configured elab@ElaboratedConfiguredPackage{elabModuleShape=modShape}
, not (isIndefiniteOrInstantiation modShape) ->
Just elab
InstallPlan.Configured elab@ElaboratedConfiguredPackage{elabModuleShape = modShape}
| elabLocalToProject
, not (isIndefiniteOrInstantiation modShape)
-> Just elab
, not (isIndefiniteOrInstantiation modShape) ->
Just elab
_ -> Nothing
) $ Graph.toList $ InstallPlan.toGraph plan
)
$ Graph.toList
$ InstallPlan.toGraph plan

isIndefiniteOrInstantiation :: ModuleShape -> Bool
isIndefiniteOrInstantiation = not . Set.null . modShapeRequires
Expand Down Expand Up @@ -4465,7 +4470,6 @@ setupHsHaddockArgs :: ElaboratedConfiguredPackage -> [String]
setupHsHaddockArgs elab =
map (showComponentTarget (packageId elab)) (elabHaddockTargets elab)


------------------------------------------------------------------------------

-- * Sharing installed packages
Expand Down

0 comments on commit a574757

Please sign in to comment.