Commit 47bdafb1 authored by ttuegel's avatar ttuegel
Browse files

LocalBuildInfo: track program coverage status

The status of Haskell program coverage is recorded in
LocalBuildInfo. Program coverage is disabled during configure if the
compiler does not support it.
parent 91d07f17
......@@ -57,6 +57,7 @@ module Distribution.Simple.Compiler (
unifiedIPIDRequired,
packageKeySupported,
unitIdSupported,
coverageSupported,
-- * Support for profiling detail levels
ProfDetailLevel(..),
......@@ -316,6 +317,14 @@ packageKeySupported = ghcSupported "Uses package keys"
unitIdSupported :: Compiler -> Bool
unitIdSupported = ghcSupported "Uses unit IDs"
-- | Does this compiler support Haskell program coverage?
coverageSupported :: Compiler -> Bool
coverageSupported comp =
case compilerFlavor comp of
GHC -> True
GHCJS -> True
_ -> False
-- | Utility function for GHC only features
ghcSupported :: String -> Compiler -> Bool
ghcSupported key comp =
......
......@@ -664,10 +664,7 @@ configure (pkg_descr0', pbi) cfg = do
++ "profiling is disabled. Linking will fail if any executables "
++ "depend on the library."
let configCoverage_ =
mappend (configCoverage cfg) (configLibCoverage cfg)
cfg' = cfg { configCoverage = configCoverage_ }
configCoverage <- configureCoverage verbosity cfg comp
reloc <-
if not (fromFlag $ configRelocatable cfg)
......@@ -678,8 +675,9 @@ configure (pkg_descr0', pbi) cfg = do
foldl' (\m clbi -> Map.insertWith (++) (componentLocalName clbi) [clbi] m)
Map.empty buildComponents
let lbi = LocalBuildInfo {
configFlags = cfg',
let lbi = configCoverage
LocalBuildInfo {
configFlags = cfg,
flagAssignment = flags,
componentEnabledSpec = enabled,
extraConfigArgs = [], -- Currently configure does not
......@@ -709,6 +707,8 @@ configure (pkg_descr0', pbi) cfg = do
splitObjs = split_objs,
stripExes = fromFlag $ configStripExes cfg,
stripLibs = fromFlag $ configStripLibs cfg,
exeCoverage = False,
libCoverage = False,
withPackageDB = packageDbs,
progPrefix = fromFlag $ configProgPrefix cfg,
progSuffix = fromFlag $ configProgSuffix cfg,
......@@ -1016,6 +1016,29 @@ configureDependencies verbosity
return (internalPkgDeps, externalPkgDeps)
-- | Select and apply coverage settings for the build based on the
-- 'ConfigFlags' and 'Compiler'.
configureCoverage :: Verbosity -> ConfigFlags -> Compiler
-> IO (LocalBuildInfo -> LocalBuildInfo)
configureCoverage verbosity cfg comp = do
let tryExeCoverage = fromFlagOrDefault False (configCoverage cfg)
tryLibCoverage = fromFlagOrDefault tryExeCoverage
(mappend (configCoverage cfg) (configLibCoverage cfg))
if coverageSupported comp
then do
let apply lbi = lbi { libCoverage = tryLibCoverage
, exeCoverage = tryExeCoverage
}
return apply
else do
let apply lbi = lbi { libCoverage = False
, exeCoverage = False
}
when (tryExeCoverage || tryLibCoverage) $ warn verbosity
("The compiler " ++ showCompilerId comp ++ " does not support "
++ "program coverage. Program coverage has been disabled.")
return apply
-- -----------------------------------------------------------------------------
-- Configuring package dependencies
......
......@@ -513,7 +513,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
-- Determine if program coverage should be enabled and if so, what
-- '-hpcdir' should be.
let isCoverageEnabled = fromFlag $ configCoverage $ configFlags lbi
let isCoverageEnabled = libCoverage lbi
-- TODO: Historically HPC files have been put into a directory which
-- has the package name. I'm going to avoid changing this for
-- now, but it would probably be better for this to be the
......@@ -808,7 +808,7 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
-- Determine if program coverage should be enabled and if so, what
-- '-hpcdir' should be.
let isCoverageEnabled = fromFlag $ configCoverage $ configFlags lbi
let isCoverageEnabled = exeCoverage lbi
distPref = fromFlag $ configDistPref $ configFlags lbi
hpcdir way
| forRepl = mempty -- HPC is not supported in ghci
......
......@@ -293,7 +293,7 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
-- Determine if program coverage should be enabled and if so, what
-- '-hpcdir' should be.
let isCoverageEnabled = fromFlag $ configCoverage $ configFlags lbi
let isCoverageEnabled = libCoverage lbi
pkg_name = display $ PD.package pkg_descr
distPref = fromFlag $ configDistPref $ configFlags lbi
hpcdir way
......@@ -534,7 +534,7 @@ buildOrReplExe forRepl verbosity numJobs _pkg_descr lbi
-- Determine if program coverage should be enabled and if so, what
-- '-hpcdir' should be.
let isCoverageEnabled = fromFlag $ configCoverage $ configFlags lbi
let isCoverageEnabled = exeCoverage lbi
distPref = fromFlag $ configDistPref $ configFlags lbi
hpcdir way
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way exeName'
......
......@@ -20,6 +20,7 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Hpc
import Distribution.Simple.InstallDirs
import qualified Distribution.Simple.LocalBuildInfo as LBI
import qualified Distribution.Types.LocalBuildInfo as LBI
import Distribution.Simple.Setup
import Distribution.Simple.UserHooks
import qualified Distribution.Simple.Test.ExeV10 as ExeV10
......@@ -110,8 +111,7 @@ test args pkg_descr lbi flags = do
allOk <- summarizePackage verbosity packageLog
writeFile packageLogFile $ show packageLog
let isCoverageEnabled = fromFlag $ configCoverage $ LBI.configFlags lbi
when isCoverageEnabled $
when (LBI.testCoverage lbi) $
markupPackage verbosity lbi distPref (display $ PD.package pkg_descr) $
map (fst . fst) testsToRun
......
......@@ -11,6 +11,7 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Hpc
import Distribution.Simple.InstallDirs
import qualified Distribution.Simple.LocalBuildInfo as LBI
import qualified Distribution.Types.LocalBuildInfo as LBI
import Distribution.Simple.Setup
import Distribution.Simple.Test.Log
import Distribution.Simple.Utils
......@@ -35,7 +36,7 @@ runTest :: PD.PackageDescription
-> PD.TestSuite
-> IO TestSuiteLog
runTest pkg_descr lbi clbi flags suite = do
let isCoverageEnabled = fromFlag $ configCoverage $ LBI.configFlags lbi
let isCoverageEnabled = LBI.testCoverage lbi
way = guessWay lbi
tixDir_ = tixDir distPref way $ PD.testName suite
......
......@@ -17,6 +17,7 @@ import Distribution.Simple.Compiler
import Distribution.Simple.Hpc
import Distribution.Simple.InstallDirs
import qualified Distribution.Simple.LocalBuildInfo as LBI
import qualified Distribution.Types.LocalBuildInfo as LBI
import Distribution.Simple.Setup
import Distribution.Simple.Test.Log
import Distribution.Simple.Utils
......@@ -44,7 +45,7 @@ runTest :: PD.PackageDescription
-> PD.TestSuite
-> IO TestSuiteLog
runTest pkg_descr lbi clbi flags suite = do
let isCoverageEnabled = fromFlag $ configCoverage $ LBI.configFlags lbi
let isCoverageEnabled = LBI.testCoverage lbi
way = guessWay lbi
pwd <- getCurrentDirectory
......
......@@ -33,6 +33,7 @@ module Distribution.Types.LocalBuildInfo (
withAllTargetsInBuildOrder',
neededTargetsInBuildOrder',
withNeededTargetsInBuildOrder',
testCoverage,
-- * Functions you SHOULD NOT USE (yet), but are defined here to
-- prevent someone from accidentally defining them
......@@ -141,6 +142,8 @@ data LocalBuildInfo = LocalBuildInfo {
splitObjs :: Bool, -- ^Use -split-objs with GHC, if available
stripExes :: Bool, -- ^Whether to strip executables during install
stripLibs :: Bool, -- ^Whether to strip libraries during install
exeCoverage :: Bool, -- ^Whether to enable executable program coverage
libCoverage :: Bool, -- ^Whether to enable library program coverage
progPrefix :: PathTemplate, -- ^Prefix to be prepended to installed executables
progSuffix :: PathTemplate, -- ^Suffix to be appended to installed executables
relocatable :: Bool -- ^Whether to build a relocatable package
......@@ -253,6 +256,11 @@ withNeededTargetsInBuildOrder' :: PackageDescription -> LocalBuildInfo -> [UnitI
withNeededTargetsInBuildOrder' pkg_descr lbi uids f
= sequence_ [ f target | target <- neededTargetsInBuildOrder' pkg_descr lbi uids ]
-- | Is coverage enabled for test suites? In practice, this requires library
-- and executable profiling to be enabled.
testCoverage :: LocalBuildInfo -> Bool
testCoverage lbi = exeCoverage lbi && libCoverage lbi
-------------------------------------------------------------------------------
-- Stub functions to prevent someone from accidentally defining them
......
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