Commit ba4ae3d0 authored by Iain Nicol's avatar Iain Nicol
Browse files

Fix: "cabal haddock" uses CPP overzealously

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.
parent 5729bc5c
......@@ -83,6 +83,7 @@ extra-source-files:
......@@ -27,7 +27,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(..) )
......@@ -365,7 +365,7 @@ getGhcCppOpts haddockVersion bi =
ghcOptCppOptions = defines
needsCpp = EnableExtension CPP `elem` allExtensions bi
needsCpp = EnableExtension CPP `elem` usedExtensions bi
defines = [haddockVersionMacro]
haddockVersionMacro = "-D__HADDOCK_VERSION__="
++ show (v1 * 1000 + v2 * 10 + v3)
......@@ -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
module NoCPP (Haystack) where
-- | For hiding needles.
data Haystack = Haystack
-- | Causes a build failure if the CPP language extension is enabled.
stringGap = "Foo\
......@@ -11,6 +11,6 @@ description:
Check that Cabal successfully invokes Haddock.
exposed-modules: CPP, Literate, Simple
exposed-modules: CPP, Literate, NoCPP, Simple
other-extensions: CPP
build-depends: base
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment