Skip to content

Commit 12a5254

Browse files
committed
Fix assertion failure when combining build-tool-depends and --enable-documentation
The `setDocumentation` function was modifying the elaborated package after the hash was computed. This led to the assertion failing as the computed hash was different to what was computed in the initial install plan. Therefore in order to fix this we either needed to: 1. Set elabBuildHaddocks = False at the point where the hash is initially computed. 2. Verify that elabBuildHaddocks = True will not lead to unexpected results. The latter has been implemented. The elabBuildHaddocks option is only consulted in `hasValidHaddockTargets`, at which point documentation building the executable component is disabled because elabHaddockExecutables is False. In the added test we ensure this by checking that we didn't build documentation for the executable which is built because of build-tool-depends. Fixes haskell#6006 haskell#8313
1 parent 2dad49a commit 12a5254

File tree

9 files changed

+71
-25
lines changed

9 files changed

+71
-25
lines changed

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

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ sanityCheckElaboratedConfiguredPackage
258258
-> a
259259
-> a
260260
sanityCheckElaboratedConfiguredPackage
261-
_sharedConfig
261+
sharedConfig
262262
elab@ElaboratedConfiguredPackage{..} =
263263
( case elabPkgOrComp of
264264
ElabPackage pkg -> sanityCheckElaboratedPackage elab pkg
@@ -273,9 +273,9 @@ sanityCheckElaboratedConfiguredPackage
273273
-- 'installedPackageId' we assigned is consistent with
274274
-- the 'hashedInstalledPackageId' we would compute from
275275
-- the elaborated configured package
276-
-- . assert (isInplaceBuildStyle elabBuildStyle ||
277-
-- elabComponentId == hashedInstalledPackageId
278-
-- (packageHashInputs sharedConfig elab))
276+
. traceShow elabUnitId (assert (isInplaceBuildStyle elabBuildStyle ||
277+
elabComponentId == hashedInstalledPackageId
278+
(packageHashInputs sharedConfig elab)))
279279

280280
-- the stanzas explicitly disabled should not be available
281281
. assert
@@ -3293,9 +3293,7 @@ pruneInstallPlanPass1 pkgs
32933293
prune :: ElaboratedConfiguredPackage -> PrunedPackage
32943294
prune elab = PrunedPackage elab' (pruneOptionalDependencies elab')
32953295
where
3296-
elab' =
3297-
setDocumentation $
3298-
addOptionalStanzas elab
3296+
elab' = addOptionalStanzas elab
32993297

33003298
graph = Graph.fromDistinctList pkgs'
33013299

@@ -3444,24 +3442,6 @@ pruneInstallPlanPass1 pkgs
34443442
<> optionalStanzasWithDepsAvailable availablePkgs elab pkg
34453443
addOptionalStanzas elab = elab
34463444

3447-
setDocumentation :: ElaboratedConfiguredPackage -> ElaboratedConfiguredPackage
3448-
setDocumentation elab@ElaboratedConfiguredPackage{elabPkgOrComp = ElabComponent comp} =
3449-
elab
3450-
{ elabBuildHaddocks =
3451-
elabBuildHaddocks elab && documentationEnabled (compSolverName comp) elab
3452-
}
3453-
where
3454-
documentationEnabled c =
3455-
case c of
3456-
CD.ComponentLib -> const True
3457-
CD.ComponentSubLib _ -> elabHaddockInternal
3458-
CD.ComponentFLib _ -> elabHaddockForeignLibs
3459-
CD.ComponentExe _ -> elabHaddockExecutables
3460-
CD.ComponentTest _ -> elabHaddockTestSuites
3461-
CD.ComponentBench _ -> elabHaddockBenchmarks
3462-
CD.ComponentSetup -> const False
3463-
setDocumentation elab = elab
3464-
34653445
-- Calculate package dependencies but cut out those needed only by
34663446
-- optional stanzas that we've determined we will not enable.
34673447
-- These pruned deps are not persisted in this pass since they're based on
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: a
2+
version: 0.1.0.0
3+
build-type: Simple
4+
cabal-version: >= 1.10
5+
6+
library
7+
exposed-modules: MyLib
8+
build-depends: base, lib
9+
hs-source-dirs: src
10+
default-language: Haskell2010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Test.Cabal.Prelude
2+
3+
4+
main = cabalTest . withRepo "repo" $ do
5+
cabal "build" ["--enable-documentation"]
6+
7+
env <- getTestEnv
8+
let storeDir = testCabalDir env </> "store"
9+
10+
-- Check properties of executable component
11+
libDir <- liftIO $ findDependencyInStore storeDir "exe"
12+
-- Documentation is enabled..
13+
assertFileDoesContain (libDir </> "cabal-hash.txt") "documentation: True"
14+
-- But not built
15+
shouldDirectoryNotExist ( libDir </> "share" </> "doc" )
16+
17+
-- Check properties of library
18+
libDir <- liftIO $ findDependencyInStore storeDir "lib"
19+
-- Documentation is enabled..
20+
assertFileDoesContain (libDir </> "cabal-hash.txt") "documentation: True"
21+
-- and has been built
22+
shouldDirectoryExist ( libDir </> "share" </> "doc" )
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Main where
2+
3+
main = return ()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: exe
2+
version: 1
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: 2.0
8+
9+
executable exe
10+
build-depends: base
11+
main-is: Main.hs
12+
default-language: Haskell2010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Lib where
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: lib
2+
version: 1
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Simple
7+
cabal-version: 2.0
8+
9+
library
10+
build-depends: base
11+
build-tool-depends: exe:exe
12+
exposed-modules: Lib
13+
default-language: Haskell2010
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLib (someFunc) where
2+
3+
someFunc :: IO ()
4+
someFunc = return ()

0 commit comments

Comments
 (0)