Skip to content

Commit aef4e35

Browse files
committed
Allow per-component builds with coverage enabled
This commits re-enables per-component builds when coverage checking is enabled. This restriction was previously added in #5004 to fix #4798. However, the fix for #5213, in #7493, fixes the paths of the testsuite `.mix` files to the same location as that of the main library component, which in turn fixes #4798 as well -- meaning the restriction to treat testsuites per-package (legacy-fallback) is no longer needed. Lifting this restriction additionally fixes #6440 as we no longer constrain coverage to per-package builds only, thus allowing multi-libs. To generate hpc files in the appropriate component directories in the distribution tree, we move the hack from #7493 from dictating the `.mix` directories where hpc information is stored to dictating the `.mix` directories that are included in the call to `hpc markup`. Fixes #6440, and the already previously fixed #4798, #5213.
1 parent 1157461 commit aef4e35

File tree

8 files changed

+84
-40
lines changed

8 files changed

+84
-40
lines changed

Cabal/src/Distribution/Simple/Hpc.hs

+46-33
Original file line numberDiff line numberDiff line change
@@ -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

10581
tixDir
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.
185164
markupPackage
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

cabal-install/src/Distribution/Client/ProjectPlanning.hs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ elaborateInstallPlan
16731673
where
16741674
-- You are eligible to per-component build if this list is empty
16751675
why_not_per_component g =
1676-
cuz_buildtype ++ cuz_spec ++ cuz_length ++ cuz_flag ++ cuz_coverage
1676+
cuz_buildtype ++ cuz_spec ++ cuz_length ++ cuz_flag
16771677
where
16781678
cuz reason = [text reason]
16791679
-- We have to disable per-component for now with
@@ -1710,12 +1710,6 @@ elaborateInstallPlan
17101710
| fromFlagOrDefault True (projectConfigPerComponent sharedPackageConfig) =
17111711
[]
17121712
| otherwise = cuz "you passed --disable-per-component"
1713-
-- Enabling program coverage introduces odd runtime dependencies
1714-
-- between components.
1715-
cuz_coverage
1716-
| fromFlagOrDefault False (packageConfigCoverage localPackagesConfig) =
1717-
cuz "program coverage is enabled"
1718-
| otherwise = []
17191713

17201714
-- \| Sometimes a package may make use of features which are only
17211715
-- supported in per-package mode. If this is the case, we should
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cabal-version: >=1.10
2+
name: T4798
3+
version: 0.1
4+
5+
library
6+
exposed-modules: U2F, U2F.Types
7+
ghc-options: -Wall
8+
build-depends: base
9+
hs-source-dirs: src
10+
default-language: Haskell2010
11+
12+
test-suite hspec-suite
13+
type: exitcode-stdio-1.0
14+
main-is: test.hs
15+
ghc-options: -Wall
16+
hs-source-dirs: tests
17+
default-language: Haskell2010
18+
build-depends: base, T4798
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Test.Cabal.Prelude
2+
main = cabalTest $ cabal "test" ["--enable-coverage"]
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module U2F where
2+
3+
import U2F.Types
4+
5+
ourCurve :: String
6+
ourCurve = "SEC_p256r1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module UF2.Types where
2+
3+
data U2FError = RegistrationParseError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import U2F
2+
import U2F.Types
3+
4+
main = print ourCurve
5+
main :: IO ()
6+

0 commit comments

Comments
 (0)