Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertion failure when combining build-tool-depends and --enable-documentation #9446

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 8 additions & 26 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ sanityCheckElaboratedConfiguredPackage
-> a
-> a
sanityCheckElaboratedConfiguredPackage
_sharedConfig
sharedConfig
elab@ElaboratedConfiguredPackage{..} =
( case elabPkgOrComp of
ElabPackage pkg -> sanityCheckElaboratedPackage elab pkg
Expand All @@ -273,10 +273,12 @@ sanityCheckElaboratedConfiguredPackage
-- 'installedPackageId' we assigned is consistent with
-- the 'hashedInstalledPackageId' we would compute from
-- the elaborated configured package
-- . assert (isInplaceBuildStyle elabBuildStyle ||
-- elabComponentId == hashedInstalledPackageId
-- (packageHashInputs sharedConfig elab))

. assert
( isInplaceBuildStyle elabBuildStyle
|| elabComponentId
== hashedInstalledPackageId
(packageHashInputs sharedConfig elab)
)
-- the stanzas explicitly disabled should not be available
. assert
( optStanzaSetNull $
Expand Down Expand Up @@ -3293,9 +3295,7 @@ pruneInstallPlanPass1 pkgs
prune :: ElaboratedConfiguredPackage -> PrunedPackage
prune elab = PrunedPackage elab' (pruneOptionalDependencies elab')
where
elab' =
setDocumentation $
addOptionalStanzas elab
elab' = addOptionalStanzas elab

graph = Graph.fromDistinctList pkgs'

Expand Down Expand Up @@ -3444,24 +3444,6 @@ pruneInstallPlanPass1 pkgs
<> optionalStanzasWithDepsAvailable availablePkgs elab pkg
addOptionalStanzas elab = elab

setDocumentation :: ElaboratedConfiguredPackage -> ElaboratedConfiguredPackage
setDocumentation elab@ElaboratedConfiguredPackage{elabPkgOrComp = ElabComponent comp} =
elab
{ elabBuildHaddocks =
elabBuildHaddocks elab && documentationEnabled (compSolverName comp) elab
}
where
documentationEnabled c =
case c of
CD.ComponentLib -> const True
CD.ComponentSubLib _ -> elabHaddockInternal
CD.ComponentFLib _ -> elabHaddockForeignLibs
CD.ComponentExe _ -> elabHaddockExecutables
CD.ComponentTest _ -> elabHaddockTestSuites
CD.ComponentBench _ -> elabHaddockBenchmarks
CD.ComponentSetup -> const False
setDocumentation elab = elab

Mikolaj marked this conversation as resolved.
Show resolved Hide resolved
-- Calculate package dependencies but cut out those needed only by
-- optional stanzas that we've determined we will not enable.
-- These pruned deps are not persisted in this pass since they're based on
Expand Down
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/HaddockBuildDepends/a.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: a
version: 0.1.0.0
build-type: Simple
cabal-version: >= 1.10

library
exposed-modules: MyLib
build-depends: base, lib
hs-source-dirs: src
default-language: Haskell2010
27 changes: 27 additions & 0 deletions cabal-testsuite/PackageTests/HaddockBuildDepends/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- exe-1 (exe:exe) (requires build)
- lib-1 (lib) (requires build)
- a-0.1.0.0 (lib) (first run)
Configuring executable 'exe' for exe-1...
Preprocessing executable 'exe' for exe-1...
Building executable 'exe' for exe-1...
Installing executable exe in <PATH>
Warning: The directory <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/incoming/new-<RAND><ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/<PACKAGE>-<HASH>/bin is not in the system search path.
Configuring library for lib-1...
Preprocessing library for lib-1...
Building library for lib-1...
Preprocessing library for lib-1...
Running Haddock on library for lib-1...
Documentation created: dist/doc/html/lib/
Installing library in <PATH>
Configuring library for a-0.1.0.0...
Preprocessing library for a-0.1.0.0...
Building library for a-0.1.0.0...
Preprocessing library for a-0.1.0.0...
Running Haddock on library for a-0.1.0.0...
Documentation created: <ROOT>/cabal.dist/work/dist/build/<ARCH>/ghc-<GHCVER>/a-0.1.0.0/doc/html/a/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
22 changes: 22 additions & 0 deletions cabal-testsuite/PackageTests/HaddockBuildDepends/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Test.Cabal.Prelude


main = cabalTest . withRepo "repo" $ do
cabal "build" ["--enable-documentation"]

env <- getTestEnv
let storeDir = testCabalDir env </> "store"

-- Check properties of executable component
libDir <- liftIO $ findDependencyInStore storeDir "exe"
-- Documentation is enabled..
assertFileDoesContain (libDir </> "cabal-hash.txt") "documentation: True"
-- But not built
shouldDirectoryNotExist ( libDir </> "share" </> "doc" )

-- Check properties of library
libDir <- liftIO $ findDependencyInStore storeDir "lib"
-- Documentation is enabled..
assertFileDoesContain (libDir </> "cabal-hash.txt") "documentation: True"
-- and has been built
shouldDirectoryExist ( libDir </> "share" </> "doc" )
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Main where

main = return ()
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: exe
version: 1
license: BSD3
author: Edward Z. Yang
maintainer: [email protected]
build-type: Simple
cabal-version: 2.0

executable exe
build-depends: base
main-is: Main.hs
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Lib where
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: lib
version: 1
license: BSD3
author: Edward Z. Yang
maintainer: [email protected]
build-type: Simple
cabal-version: 2.0

library
build-depends: base
build-tool-depends: exe:exe
exposed-modules: Lib
default-language: Haskell2010
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/HaddockBuildDepends/src/MyLib.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module MyLib (someFunc) where

someFunc :: IO ()
someFunc = return ()
4 changes: 3 additions & 1 deletion cabal-testsuite/src/Test/Cabal/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,5 +1157,7 @@ findDependencyInStore storeDir pkgName = do
then filter (not . flip elem "aeiou") pkgName
-- simulates the way 'hashedInstalledPackageId' uses to compress package name
else pkgName
let libDir = head $ filter (pkgName' `isPrefixOf`) packageDirs
let libDir = case filter (pkgName' `isPrefixOf`) packageDirs of
[] -> error $ "Could not find " <> pkgName' <> " when searching for " <> pkgName' <> " in\n" <> show packageDirs
(dir:_) -> dir
pure (storeDir </> storeDirForGhcVersion </> libDir)
Loading