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 15, 2013
1 parent f2d876a commit 0f7f80f
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 -- Maintainer : cabal-devel@haskell.org
-- Portability : portable -- Portability : portable
-- --
-- This module deals with the @haddock@ and @hscolour@ commands. Sadly this is -- This module deals with the @haddock@ and @hscolour@ commands. Sadly this is a
-- a rather complicated module. It deals with two versions of haddock (0.x and -- 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 -- 2.x). It has to do pre-processing which involves \'unlit\'ing and using
-- \'unlit\'ing and using @-DHADDOCK@ for any source code that uses @cpp@. It -- @-D__HADDOCK__@ for any source code that uses @cpp@. It uses information
-- uses information about installed packages (from @ghc-pkg@) to find the -- about installed packages (from @ghc-pkg@) to find the locations of
-- locations of documentation for dependent packages, so it can create links. -- documentation for dependent packages, so it can create links.
-- --
-- The @hscolour@ support allows generating html versions of the original -- The @hscolour@ support allows generating html versions of the original
-- source, with coloured syntax highlighting. -- source, with coloured syntax highlighting.
Expand Down Expand Up @@ -211,14 +211,14 @@ haddock pkg_descr lbi suffixes flags = do
let bi = libBuildInfo lib let bi = libBuildInfo lib
libArgs <- fromLibrary verbosity tmp lbi lib clbi htmlTemplate libArgs <- fromLibrary verbosity tmp lbi lib clbi htmlTemplate
libArgs' <- prepareSources verbosity tmp libArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (commonArgs `mappend` libArgs) lbi bi (commonArgs `mappend` libArgs)
runHaddock verbosity keepTempFiles confHaddock libArgs' runHaddock verbosity keepTempFiles confHaddock libArgs'
CExe exe -> when (flag haddockExecutables) $ do CExe exe -> when (flag haddockExecutables) $ do
withTempDirectory verbosity keepTempFiles (buildDir lbi) "tmp" $ \tmp -> do withTempDirectory verbosity keepTempFiles (buildDir lbi) "tmp" $ \tmp -> do
let bi = buildInfo exe let bi = buildInfo exe
exeArgs <- fromExecutable verbosity tmp lbi exe clbi htmlTemplate exeArgs <- fromExecutable verbosity tmp lbi exe clbi htmlTemplate
exeArgs' <- prepareSources verbosity tmp exeArgs' <- prepareSources verbosity tmp
lbi isVersion2 bi (commonArgs `mappend` exeArgs) lbi bi (commonArgs `mappend` exeArgs)
runHaddock verbosity keepTempFiles confHaddock exeArgs' runHaddock verbosity keepTempFiles confHaddock exeArgs'
_ -> return () _ -> return ()


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


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


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

0 comments on commit 0f7f80f

Please sign in to comment.