@@ -76,31 +76,7 @@ mixDir
7676 -- ^ Component name
7777 -> FilePath
7878 -- ^ Directory containing test suite's .mix files
79- mixDir distPref way name = hpcDir distPrefBuild way </> " mix" </> name
80- where
81- -- This is a hack for HPC over test suites, needed to match the directory
82- -- where HPC saves and reads .mix files when the main library of the same
83- -- package is being processed, perhaps in a previous cabal run (#5213).
84- -- E.g., @distPref@ may be
85- -- @./dist-newstyle/build/x86_64-linux/ghc-9.0.1/cabal-gh5213-0.1/t/tests@
86- -- but the path where library mix files reside has two less components
87- -- at the end (@t/tests@) and this reduced path needs to be passed to
88- -- both @hpc@ and @ghc@. For non-default optimization levels, the path
89- -- suffix is one element longer and the extra path element needs
90- -- to be preserved.
91- distPrefElements = splitDirectories distPref
92- distPrefBuild = case drop (length distPrefElements - 3 ) distPrefElements of
93- [" t" , _, " noopt" ] ->
94- joinPath $
95- take (length distPrefElements - 3 ) distPrefElements
96- ++ [" noopt" ]
97- [" t" , _, " opt" ] ->
98- joinPath $
99- take (length distPrefElements - 3 ) distPrefElements
100- ++ [" opt" ]
101- [_, " t" , _] ->
102- joinPath $ take (length distPrefElements - 2 ) distPrefElements
103- _ -> distPref
79+ mixDir distPref way name = hpcDir distPref way </> " mix" </> name
10480
10581tixDir
10682 :: FilePath
@@ -146,14 +122,14 @@ markupTest
146122 :: Verbosity
147123 -> LocalBuildInfo
148124 -> FilePath
149- -- ^ \"dist/\" prefix
125+ -- ^ Testsuite \"dist/\" prefix
150126 -> String
151127 -- ^ Library name
152128 -> TestSuite
153129 -> Library
154130 -> IO ()
155- markupTest verbosity lbi distPref libraryName suite library = do
156- tixFileExists <- doesFileExist $ tixFilePath distPref way $ testName'
131+ markupTest verbosity lbi testDistPref libraryName suite library = do
132+ tixFileExists <- doesFileExist $ tixFilePath testDistPref way $ testName'
157133 when tixFileExists $ do
158134 -- behaviour of 'markup' depends on version, so we need *a* version
159135 -- but no particular one
@@ -163,12 +139,12 @@ markupTest verbosity lbi distPref libraryName suite library = do
163139 hpcProgram
164140 anyVersion
165141 (withPrograms lbi)
166- let htmlDir_ = htmlDir distPref way testName'
142+ let htmlDir_ = htmlDir testDistPref way testName'
167143 markup
168144 hpc
169145 hpcVer
170146 verbosity
171- (tixFilePath distPref way testName')
147+ (tixFilePath testDistPref way testName')
172148 mixDirs
173149 htmlDir_
174150 (exposedModules library)
@@ -179,14 +155,17 @@ markupTest verbosity lbi distPref libraryName suite library = do
179155 where
180156 way = guessWay lbi
181157 testName' = unUnqualComponentName $ testName suite
182- mixDirs = map (mixDir distPref way) [testName', libraryName]
158+ mixDirs =
159+ [ mixDir testDistPref way testName'
160+ , mixDir (pathToMainLibHpc testDistPref) way libraryName
161+ ]
183162
184163-- | Generate the HTML markup for all of a package's test suites.
185164markupPackage
186165 :: Verbosity
187166 -> LocalBuildInfo
188167 -> FilePath
189- -- ^ \"dist/\" prefix
168+ -- ^ Testsuite \"dist/\" prefix
190169 -> PD. PackageDescription
191170 -> [TestSuite ]
192171 -> IO ()
@@ -215,6 +194,40 @@ markupPackage verbosity lbi distPref pkg_descr suites = do
215194 where
216195 way = guessWay lbi
217196 testNames = fmap (unUnqualComponentName . testName) suites
218- mixDirs = map (mixDir distPref way) $ libraryName : testNames
197+ mixDirs = mixDir (pathToMainLibHpc distPref) way libraryName : map (mixDir distPref way) testNames
219198 included = concatMap (exposedModules) $ PD. allLibraries pkg_descr
220199 libraryName = prettyShow $ PD. package pkg_descr
200+
201+ -- | A (non-exported) hack to determine the path to the main-lib hpc directory
202+ -- given the testsuite's dist prefix.
203+ --
204+ -- 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
210+ where
211+ -- This is a hack for HPC over test suites, needed to match the directory
212+ -- where HPC saves and reads .mix files when the main library of the same
213+ -- package is being processed, perhaps in a previous cabal run (#5213).
214+ -- E.g., @distPref@ may be
215+ -- @./dist-newstyle/build/x86_64-linux/ghc-9.0.1/cabal-gh5213-0.1/t/tests@
216+ -- but the path where library mix files reside has two less components
217+ -- at the end (@t/tests@) and this reduced path needs to be passed to
218+ -- both @hpc@ and @ghc@. For non-default optimization levels, the path
219+ -- suffix is one element longer and the extra path element needs
220+ -- to be preserved.
221+ distPrefElements = splitDirectories distPref
222+ distPrefBuild = case drop (length distPrefElements - 3 ) distPrefElements of
223+ [" t" , _, " noopt" ] ->
224+ joinPath $
225+ take (length distPrefElements - 3 ) distPrefElements
226+ ++ [" noopt" ]
227+ [" t" , _, " opt" ] ->
228+ joinPath $
229+ take (length distPrefElements - 3 ) distPrefElements
230+ ++ [" opt" ]
231+ [_, " t" , _] ->
232+ joinPath $ take (length distPrefElements - 2 ) distPrefElements
233+ _ -> distPref
0 commit comments