Skip to content

Commit 969343a

Browse files
authored
Merge pull request #10250 from alt-romes/wip/romes/10046
hpc: Don't cover non-dependency libraries
2 parents 23e65cf + c3b8cee commit 969343a

File tree

10 files changed

+67
-8
lines changed

10 files changed

+67
-8
lines changed

Cabal/src/Distribution/Simple/Configure.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,9 @@ configureComponents
12801280
extraCoverageUnitIds = case enabled of
12811281
-- Whole package configure, add package libs
12821282
ComponentRequestedSpec{} -> mapMaybe mbCompUnitId buildComponents
1283-
-- Component configure, no need to do anything
1283+
-- Component configure, no need to do anything since
1284+
-- extra-coverage-for will be passed for all other components that
1285+
-- should be covered.
12841286
OneComponentRequestedSpec{} -> []
12851287
mbCompUnitId LibComponentLocalBuildInfo{componentUnitId} = Just componentUnitId
12861288
mbCompUnitId _ = Nothing

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -4058,7 +4058,7 @@ setupHsConfigureFlags
40584058
Just _ -> error "non-library dependency"
40594059
Nothing -> LMainLibName
40604060

4061-
configCoverageFor = determineCoverageFor elabPkgSourceId plan
4061+
configCoverageFor = determineCoverageFor elab plan
40624062

40634063
setupHsConfigureArgs
40644064
:: ElaboratedConfiguredPackage
@@ -4469,13 +4469,14 @@ inplaceBinRoot layout config package =
44694469

44704470
-- The list of non-pre-existing libraries without module holes, i.e. the
44714471
-- main library and sub-libraries components of all the local packages in
4472-
-- the project that do not require instantiations or are instantiations.
4472+
-- the project that are dependencies of the components being built and that do
4473+
-- not require instantiations or are instantiations.
44734474
determineCoverageFor
4474-
:: PackageId
4475-
-- ^ The 'PackageId' of the package or component being configured
4475+
:: ElaboratedConfiguredPackage
4476+
-- ^ The package or component being configured
44764477
-> ElaboratedInstallPlan
44774478
-> Flag [UnitId]
4478-
determineCoverageFor configuredPkgSourceId plan =
4479+
determineCoverageFor configuredPkg plan =
44794480
Flag
44804481
$ mapMaybe
44814482
( \case
@@ -4488,15 +4489,18 @@ determineCoverageFor configuredPkgSourceId plan =
44884489
$ Graph.toList
44894490
$ InstallPlan.toGraph plan
44904491
where
4491-
shouldCoverPkg elab@ElaboratedConfiguredPackage{elabModuleShape, elabPkgSourceId, elabLocalToProject} =
4492+
libDeps = elabLibDependencies configuredPkg
4493+
shouldCoverPkg elab@ElaboratedConfiguredPackage{elabModuleShape, elabPkgSourceId = pkgSID, elabLocalToProject} =
44924494
elabLocalToProject
44934495
&& not (isIndefiniteOrInstantiation elabModuleShape)
44944496
-- TODO(#9493): We can only cover libraries in the same package
44954497
-- as the testsuite
4496-
&& configuredPkgSourceId == elabPkgSourceId
4498+
&& elabPkgSourceId configuredPkg == pkgSID
44974499
-- Libraries only! We don't cover testsuite modules, so we never need
44984500
-- the paths to their mix dirs. Furthermore, we do not install testsuites...
44994501
&& maybe False (\case CLibName{} -> True; CNotLibName{} -> False) (elabComponentName elab)
4502+
-- We only want coverage for libraries which are dependencies of the given one
4503+
&& pkgSID `elem` map (confSrcId . fst) libDeps
45004504

45014505
isIndefiniteOrInstantiation :: ModuleShape -> Bool
45024506
isIndefiniteOrInstantiation = not . Set.null . modShapeRequires
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cabal-version: 3.0
2+
name: aa
3+
version: 0.1.0.0
4+
license: NONE
5+
build-type: Simple
6+
extra-doc-files: CHANGELOG.md
7+
8+
library
9+
exposed-modules: MyLib
10+
build-depends: base, template-haskell
11+
hs-source-dirs: src
12+
default-language: Haskell2010
13+
14+
test-suite bb-test
15+
default-language: Haskell2010
16+
type: exitcode-stdio-1.0
17+
hs-source-dirs: testbb
18+
main-is: Main.hs
19+
build-depends:
20+
base, aa
21+
22+
test-suite aa-test
23+
default-language: Haskell2010
24+
type: exitcode-stdio-1.0
25+
hs-source-dirs: test
26+
main-is: Main.hs
27+
build-depends:
28+
base
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main = pure ()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Test.Cabal.Prelude
2+
3+
-- T10046
4+
main = cabalTest $ recordMode DoNotRecord $ do
5+
out <- cabal' "test" ["all"]
6+
assertOutputDoesNotContain "Failed to find the installed unit 'aa-0.1.0.0-inplace'" out
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module MyLib where
3+
4+
import Control.Concurrent
5+
import Language.Haskell.TH
6+
7+
-- Must take longer to compile than the testsuite
8+
$(do runIO $
9+
threadDelay (5*1000*1000) -- 5s
10+
[d| data X |]
11+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main = pure ()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main = pure ()

changelog.d/issue-10046

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
synopsis: Bug fix - Don't pass --coverage-for for non-dependency libs of testsuite
2+
packages: cabal-install
3+
issues: #10046
4+
prs: #10250

0 commit comments

Comments
 (0)