Skip to content

Commit

Permalink
Make 'cabal haddock' always define __HADDOCK__ when preprocessing.
Browse files Browse the repository at this point in the history
This is useful e.g. for "writing documentation that links to module A without
explicitly qualifying everything, where A is not directly imported." (see the
discussion in haskell#926)

Fixes haskell#1237.
  • Loading branch information
23Skidoo committed Mar 19, 2013
1 parent 978f26c commit fae37ad
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Cabal/Distribution/Simple/Haddock.hs
Expand Up @@ -6,12 +6,12 @@
-- Maintainer : cabal-devel@haskell.org
-- Portability : portable
--
-- This module deals with the @haddock@ and @hscolour@ commands. Sadly this is
-- a rather complicated module. It deals with two versions of haddock (0.x and
-- 2.x). It has to do pre-processing for haddock 0.x which involves
-- \'unlit\'ing and using @-DHADDOCK@ for any source code that uses @cpp@. It
-- uses information about installed packages (from @ghc-pkg@) to find the
-- locations of documentation for dependent packages, so it can create links.
-- This module deals with the @haddock@ and @hscolour@ commands. Sadly this is a
-- rather complicated module. It deals with two versions of haddock (0.x and
-- 2.x). It has to do pre-processing which involves \'unlit\'ing and using
-- @-D__HADDOCK__@ for any source code that uses @cpp@. It uses information
-- about installed packages (from @ghc-pkg@) to find the locations of
-- documentation for dependent packages, so it can create links.
--
-- The @hscolour@ support allows generating html versions of the original
-- source, with coloured syntax highlighting.
Expand Down Expand Up @@ -211,14 +211,14 @@ haddock pkg_descr lbi suffixes flags = do
let bi = libBuildInfo lib
libArgs <- fromLibrary verbosity tmp lbi lib clbi htmlTemplate
libArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (commonArgs `mappend` libArgs)
lbi bi (commonArgs `mappend` libArgs)
runHaddock verbosity keepTempFiles confHaddock libArgs'
CExe exe -> when (flag haddockExecutables) $ do
withTempDirectory verbosity keepTempFiles (buildDir lbi) "tmp" $ \tmp -> do
let bi = buildInfo exe
exeArgs <- fromExecutable verbosity tmp lbi exe clbi htmlTemplate
exeArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (commonArgs `mappend` exeArgs)
lbi bi (commonArgs `mappend` exeArgs)
runHaddock verbosity keepTempFiles confHaddock exeArgs'
_ -> return ()

Expand All @@ -236,11 +236,10 @@ haddock pkg_descr lbi suffixes flags = do
prepareSources :: Verbosity
-> FilePath
-> LocalBuildInfo
-> Bool -- haddock >= 2.0
-> BuildInfo
-> HaddockArgs
-> IO HaddockArgs
prepareSources verbosity tmp lbi isVersion2 bi args@HaddockArgs{argTargets=files} =
prepareSources verbosity tmp lbi bi args@HaddockArgs{argTargets=files} =
mapM (mockPP tmp) files >>= \targets -> return args {argTargets=targets}
where
mockPP pref file = do
Expand All @@ -267,8 +266,7 @@ prepareSources verbosity tmp lbi isVersion2 bi args@HaddockArgs{argTargets=files

return hsFile
needsCpp = EnableExtension CPP `elem` allExtensions bi
defines | isVersion2 = []
| otherwise = ["-D__HADDOCK__"]
defines = ["-D__HADDOCK__"]

--------------------------------------------------------------------------------------------------
-- constributions to HaddockArgs
Expand Down

0 comments on commit fae37ad

Please sign in to comment.