1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE RankNTypes #-}
4 -----------------------------------------------------------------------------
7 -- Module : Distribution.Simple.Program.Hpc
8 -- Copyright : Thomas Tuegel 2011
10 -- Maintainer : cabal-devel@haskell.org
11 -- Portability : portable
13 -- This module provides an library interface to the @hpc@ program.
14 module Distribution
.Simple
.Program
.Hpc
19 import Distribution
.Compat
.Prelude
22 import System
.Directory
(makeRelativeToCurrentDirectory
)
24 import Distribution
.ModuleName
25 import Distribution
.Pretty
26 import Distribution
.Simple
.Program
.Run
27 import Distribution
.Simple
.Program
.Types
28 import Distribution
.Simple
.Utils
29 import Distribution
.Verbosity
30 import Distribution
.Version
32 -- | Invoke hpc with the given parameters.
34 -- Prior to HPC version 0.7 (packaged with GHC 7.8), hpc did not handle
35 -- multiple .mix paths correctly, so we print a warning, and only pass it the
36 -- first path in the list. This means that e.g. test suites that import their
37 -- library as a dependency can still work, but those that include the library
38 -- modules directly (in other-modules) don't.
44 -- ^ Path to .tix file
46 -- ^ Paths to .mix file directories
48 -- ^ Path where html output should be located
50 -- ^ List of modules to include in the report
52 markup hpc hpcVer verbosity tixFile hpcDirs destDir included
= do
54 if withinRange hpcVer
(orLaterVersion version07
)
58 "Your version of HPC ("
60 ++ ") does not properly handle multiple search paths. "
61 ++ "Coverage report generation may fail unexpectedly. These "
62 ++ "issues are addressed in version 0.7 or later (GHC 7.8 or "
64 ++ if null droppedDirs
67 " The following search paths have been abandoned: "
71 -- Prior to GHC 8.0, hpc assumes all .mix paths are relative.
72 hpcDirs
'' <- traverse makeRelativeToCurrentDirectory hpcDirs
'
76 (markupInvocation hpc tixFile hpcDirs
'' destDir included
)
78 version07
= mkVersion
[0, 7]
79 (passedDirs
, droppedDirs
) = splitAt 1 hpcDirs
84 -- ^ Path to .tix file
86 -- ^ Paths to .mix file directories
88 -- ^ Path where html output should be
91 -- ^ List of modules to include
93 markupInvocation hpc tixFile hpcDirs destDir included
=
97 , "--destdir=" ++ destDir
99 ++ map ("--hpcdir=" ++) hpcDirs
100 ++ [ "--include=" ++ prettyShow moduleName
101 | moduleName
<- included
103 in programInvocation hpc args
109 -- ^ Paths to .tix files
111 -- ^ Path to resultant .tix file
113 -- ^ List of modules to exclude from union
115 union hpc verbosity tixFiles outFile excluded
=
118 (unionInvocation hpc tixFiles outFile excluded
)
123 -- ^ Paths to .tix files
125 -- ^ Path to resultant .tix file
127 -- ^ List of modules to exclude from union
129 unionInvocation hpc tixFiles outFile excluded
=
130 programInvocation hpc
$
134 , ["--output=" ++ outFile
]
135 , [ "--exclude=" ++ prettyShow moduleName
136 | moduleName
<- excluded