Skip to content

Commit

Permalink
Fix: "cabal haddock" uses CPP overzealously
Browse files Browse the repository at this point in the history
Until recently we supported ancient versions of Haddock, pre v2.0.  To
support the CPP extension with such versions, cabal had to invoke the
CPP before invoking Haddock on the output.  For simplicity cabal would
invoke the CPP on all Haskell files, if any Haskell file required CPP.
However, invoking CPP on a file which does not require it can cause
build failures.

Haddock v2.0+ supports the CPP via GHC, and even automatically
preprocesses any file with the {-# LANGUAGE CPP #-} pragma. Hence we
simply need only tell Haddock to enable the CPP when the CPP is a
package level default extension.

Fixes issue #1808.
  • Loading branch information
iainnicol authored and mzero committed Jul 23, 2014
1 parent f0dff98 commit c5e0b33
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extra-source-files:
tests/PackageTests/Haddock/CPP.hs
tests/PackageTests/Haddock/Literate.lhs
tests/PackageTests/Haddock/my.cabal
tests/PackageTests/Haddock/NoCPP.hs
tests/PackageTests/Haddock/Simple.hs
tests/PackageTests/OrderFlags/Foo.hs
tests/PackageTests/OrderFlags/my.cabal
Expand Down
4 changes: 2 additions & 2 deletions Cabal/Distribution/Simple/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Distribution.Package
, PackageName(..), packageName )
import qualified Distribution.ModuleName as ModuleName
import Distribution.PackageDescription as PD
( PackageDescription(..), BuildInfo(..), allExtensions
( PackageDescription(..), BuildInfo(..), usedExtensions
, Library(..), hasLibs, Executable(..)
, TestSuite(..), TestSuiteInterface(..)
, Benchmark(..), BenchmarkInterface(..) )
Expand Down Expand Up @@ -388,7 +388,7 @@ getGhcCppOpts haddockVersion bi =
ghcOptCppOptions = defines
}
where
needsCpp = EnableExtension CPP `elem` allExtensions bi
needsCpp = EnableExtension CPP `elem` usedExtensions bi
defines = [haddockVersionMacro]
haddockVersionMacro = "-D__HADDOCK_VERSION__="
++ show (v1 * 1000 + v2 * 10 + v3)
Expand Down
2 changes: 1 addition & 1 deletion Cabal/tests/PackageTests/Haddock/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ suite ghcPath = TestCase $ do
assertHaddockSucceeded hResult

let docFiles = map (haddocksDir </>)
["CPP.html", "Literate.html", "Simple.html"]
["CPP.html", "Literate.html", "NoCPP.html", "Simple.html"]
mapM_ (assertFindInFile "For hiding needles.") docFiles

assertFindInFile :: String -> FilePath -> Assertion
Expand Down
8 changes: 8 additions & 0 deletions Cabal/tests/PackageTests/Haddock/NoCPP.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module NoCPP (Haystack) where

-- | For hiding needles.
data Haystack = Haystack

-- | Causes a build failure if the CPP language extension is enabled.
stringGap = "Foo\
\Bar"
2 changes: 1 addition & 1 deletion Cabal/tests/PackageTests/Haddock/my.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ description:
Check that Cabal successfully invokes Haddock.

Library
exposed-modules: CPP, Literate, Simple
exposed-modules: CPP, Literate, NoCPP, Simple
other-extensions: CPP
build-depends: base

0 comments on commit c5e0b33

Please sign in to comment.