Skip to content

Commit dea60af

Browse files
committed
Drop component name from hpc dirs; extend hack to internal libraries
TODO: nonIndefiniteComponents
1 parent 6149ddf commit dea60af

File tree

5 files changed

+42
-37
lines changed

5 files changed

+42
-37
lines changed

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
651651
distPref = fromFlag $ configDistPref $ configFlags lbi
652652
hpcdir way
653653
| forRepl = mempty -- HPC is not supported in ghci
654-
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way pkg_name
654+
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way
655655
| otherwise = mempty
656656

657657
createDirectoryIfMissingVerbose verbosity True libTargetDir
@@ -1548,7 +1548,7 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
15481548
distPref = fromFlag $ configDistPref $ configFlags lbi
15491549
hpcdir way
15501550
| gbuildIsRepl bm = mempty -- HPC is not supported in ghci
1551-
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way (gbuildName bm)
1551+
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way
15521552
| otherwise = mempty
15531553

15541554
rpaths <- getRPaths lbi clbi

Cabal/src/Distribution/Simple/GHCJS.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ buildOrReplLib mReplFlags verbosity numJobs pkg_descr lbi lib clbi = do
523523
distPref = fromFlag $ configDistPref $ configFlags lbi
524524
hpcdir way
525525
| forRepl = mempty -- HPC is not supported in ghci
526-
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way pkg_name
526+
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way
527527
| otherwise = mempty
528528

529529
createDirectoryIfMissingVerbose verbosity True libTargetDir
@@ -1243,7 +1243,7 @@ gbuild verbosity numJobs pkg_descr lbi bm clbi = do
12431243
distPref = fromFlag $ configDistPref $ configFlags lbi
12441244
hpcdir way
12451245
| gbuildIsRepl bm = mempty -- HPC is not supported in ghci
1246-
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way (gbuildName bm)
1246+
| isCoverageEnabled = toFlag $ Hpc.mixDir distPref way
12471247
| otherwise = mempty
12481248

12491249
rpaths <- getRPaths lbi clbi

Cabal/src/Distribution/Simple/Hpc.hs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,16 @@ mixDir
7373
-- ^ \"dist/\" prefix
7474
-> Way
7575
-> FilePath
76-
-- ^ Component name
77-
-> FilePath
7876
-- ^ Directory containing test suite's .mix files
79-
mixDir distPref way name = hpcDir distPref way </> "mix" </> name
77+
mixDir distPref way = hpcDir distPref way </> "mix"
8078

8179
tixDir
8280
:: FilePath
8381
-- ^ \"dist/\" prefix
8482
-> Way
8583
-> FilePath
86-
-- ^ Component name
87-
-> FilePath
8884
-- ^ Directory containing test suite's .tix files
89-
tixDir distPref way name = hpcDir distPref way </> "tix" </> name
85+
tixDir distPref way = hpcDir distPref way </> "tix"
9086

9187
-- | Path to the .tix file containing a test suite's sum statistics.
9288
tixFilePath
@@ -97,17 +93,15 @@ tixFilePath
9793
-- ^ Component name
9894
-> FilePath
9995
-- ^ Path to test suite's .tix file
100-
tixFilePath distPref way name = tixDir distPref way name </> name <.> "tix"
96+
tixFilePath distPref way name = tixDir distPref way </> name <.> "tix"
10197

10298
htmlDir
10399
:: FilePath
104100
-- ^ \"dist/\" prefix
105101
-> Way
106102
-> FilePath
107-
-- ^ Component name
108-
-> FilePath
109103
-- ^ Path to test suite's HTML markup directory
110-
htmlDir distPref way name = hpcDir distPref way </> "html" </> name
104+
htmlDir distPref way = hpcDir distPref way </> "html"
111105

112106
-- | Attempt to guess the way the test suites in this package were compiled
113107
-- and linked with the library so the correct module interfaces are found.
@@ -139,7 +133,7 @@ markupTest verbosity lbi testDistPref libraryName suite library = do
139133
hpcProgram
140134
anyVersion
141135
(withPrograms lbi)
142-
let htmlDir_ = htmlDir testDistPref way testName'
136+
let htmlDir_ = htmlDir testDistPref way
143137
markup
144138
hpc
145139
hpcVer
@@ -156,8 +150,9 @@ markupTest verbosity lbi testDistPref libraryName suite library = do
156150
way = guessWay lbi
157151
testName' = unUnqualComponentName $ testName suite
158152
mixDirs =
159-
[ mixDir testDistPref way testName'
160-
, mixDir (pathToMainLibHpc testDistPref) way libraryName
153+
[ mixDir testDistPref way
154+
, mixDir (pathToLibHpc testDistPref (PD.libName library)) way
155+
-- nonIndefiniteLibraries
161156
]
162157

163158
-- | Generate the HTML markup for all of a package's test suites.
@@ -169,8 +164,8 @@ markupPackage
169164
-> PD.PackageDescription
170165
-> [TestSuite]
171166
-> IO ()
172-
markupPackage verbosity lbi distPref pkg_descr suites = do
173-
let tixFiles = map (tixFilePath distPref way) testNames
167+
markupPackage verbosity lbi testDistPref pkg_descr suites = do
168+
let tixFiles = map (tixFilePath testDistPref way) testNames
174169
tixFilesExist <- traverse doesFileExist tixFiles
175170
when (and tixFilesExist) $ do
176171
-- behaviour of 'markup' depends on version, so we need *a* version
@@ -181,8 +176,8 @@ markupPackage verbosity lbi distPref pkg_descr suites = do
181176
hpcProgram
182177
anyVersion
183178
(withPrograms lbi)
184-
let outFile = tixFilePath distPref way libraryName
185-
htmlDir' = htmlDir distPref way libraryName
179+
let outFile = tixFilePath testDistPref way libraryName
180+
htmlDir' = htmlDir testDistPref way
186181
excluded = concatMap testModules suites ++ [main]
187182
createDirectoryIfMissing True $ takeDirectory outFile
188183
union hpc verbosity tixFiles outFile excluded
@@ -194,19 +189,19 @@ markupPackage verbosity lbi distPref pkg_descr suites = do
194189
where
195190
way = guessWay lbi
196191
testNames = fmap (unUnqualComponentName . testName) suites
197-
mixDirs = mixDir (pathToMainLibHpc distPref) way libraryName : map (mixDir distPref way) testNames
198-
included = concatMap (exposedModules) $ PD.allLibraries pkg_descr
192+
mixDirs = mixDir testDistPref way : map ((`mixDir` way) . pathToLibHpc testDistPref . PD.libName) (PD.allLibraries pkg_descr)
193+
included = concatMap (exposedModules) $ nonIndefiniteLibraries pkg_descr
199194
libraryName = prettyShow $ PD.package pkg_descr
200195

201-
-- | A (non-exported) hack to determine the path to the main-lib hpc directory
202-
-- given the testsuite's dist prefix.
196+
-- | A (non-exported) hack to determine the path to the main and internal libs
197+
-- directory given the testsuite's dist prefix.
203198
--
204199
-- We use this function when constructing calls to `hpc markup` since otherwise
205-
-- having cabal-install communicate the path to the main lib dist-dir when
206-
-- building the test component, via the Setup.hs interface, is far more
207-
-- complicated.
208-
pathToMainLibHpc :: FilePath -> FilePath
209-
pathToMainLibHpc distPref = distPrefBuild
200+
-- having cabal-install communicate the path to the main and sub libraries
201+
-- dist-dir when building the test component, via the Setup.hs interface, is
202+
-- far more complicated.
203+
pathToLibHpc :: FilePath -> PD.LibraryName -> FilePath
204+
pathToLibHpc testDistPref libname = distPrefLib
210205
where
211206
-- This is a hack for HPC over test suites, needed to match the directory
212207
-- where HPC saves and reads .mix files when the main library of the same
@@ -218,16 +213,26 @@ pathToMainLibHpc distPref = distPrefBuild
218213
-- both @hpc@ and @ghc@. For non-default optimization levels, the path
219214
-- suffix is one element longer and the extra path element needs
220215
-- to be preserved.
221-
distPrefElements = splitDirectories distPref
222-
distPrefBuild = case drop (length distPrefElements - 3) distPrefElements of
216+
distPrefElements = splitDirectories testDistPref
217+
distPrefLib = case drop (length distPrefElements - 3) distPrefElements of
223218
["t", _, "noopt"] ->
224219
joinPath $
225220
take (length distPrefElements - 3) distPrefElements
221+
++ [distSuffixInternalLib]
226222
++ ["noopt"]
227223
["t", _, "opt"] ->
228224
joinPath $
229225
take (length distPrefElements - 3) distPrefElements
226+
++ [distSuffixInternalLib]
230227
++ ["opt"]
231228
[_, "t", _] ->
232-
joinPath $ take (length distPrefElements - 2) distPrefElements
233-
_ -> distPref
229+
joinPath $
230+
take (length distPrefElements - 2) distPrefElements
231+
++ [distSuffixInternalLib]
232+
_ -> error "pathToLibHpc: Expecting `testDirPref` to be the dist prefix of a test-suite component"
233+
distSuffixInternalLib = case libname of
234+
PD.LMainLibName -> ""
235+
PD.LSubLibName slname -> "l" </> unUnqualComponentName slname
236+
237+
nonIndefiniteLibraries :: PD.PackageDescription -> [Library]
238+
nonIndefiniteLibraries = PD.allLibraries

Cabal/src/Distribution/Simple/Test/ExeV10.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ runTest
5151
runTest pkg_descr lbi clbi flags suite = do
5252
let isCoverageEnabled = LBI.testCoverage lbi
5353
way = guessWay lbi
54-
tixDir_ = tixDir distPref way testName'
54+
tixDir_ = tixDir distPref way
5555

5656
pwd <- getCurrentDirectory
5757
existingEnv <- getEnvironment

Cabal/src/Distribution/Simple/Test/LibV09.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ runTest pkg_descr lbi clbi flags suite = do
8080

8181
-- Remove old .tix files if appropriate.
8282
unless (fromFlag $ testKeepTix flags) $ do
83-
let tDir = tixDir distPref way testName'
83+
let tDir = tixDir distPref way
8484
exists' <- doesDirectoryExist tDir
8585
when exists' $ removeDirectoryRecursive tDir
8686

8787
-- Create directory for HPC files.
88-
createDirectoryIfMissing True $ tixDir distPref way testName'
88+
createDirectoryIfMissing True $ tixDir distPref way
8989

9090
-- Write summary notices indicating start of test suite
9191
notice verbosity $ summarizeSuiteStart testName'

0 commit comments

Comments
 (0)