Permalink
Browse files

Make 'cabal haddock' always define __HADDOCK__ when preprocessing.

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 #926)

Fixes #1237.
  • Loading branch information...
1 parent 978f26c commit fae37add2b8ffd8c77f40885f7fab7db47cbd59a @23Skidoo committed Mar 15, 2013
Showing with 10 additions and 12 deletions.
  1. +10 −12 Cabal/Distribution/Simple/Haddock.hs
@@ -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.
@@ -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 ()
@@ -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
@@ -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

0 comments on commit fae37ad

Please sign in to comment.