Haddock.hs 2.41 KB
Newer Older
1
module Settings.Builders.Haddock (haddockBuilderArgs) where
2

3
import Hadrian.Utilities
4
import Hadrian.Haskell.Cabal
5

6
import Rules.Documentation
7
import Settings.Builders.Common
8 9
import Settings.Builders.Ghc

10 11
-- | Given a version string such as "2.16.2" produce an integer equivalent.
versionToInt :: String -> Int
Andrey Mokhov's avatar
Andrey Mokhov committed
12 13 14
versionToInt s = case map read . words $ replaceEq '.' ' ' s of
    [major, minor, patch] -> major * 1000 + minor * 10 + patch
    _                     -> error "versionToInt: cannot parse version."
15

16 17
haddockBuilderArgs :: Args
haddockBuilderArgs = builder Haddock ? do
18
    output   <- getOutput
19
    pkg      <- getPackage
20
    path     <- getBuildPath
21
    version  <- expr $ pkgVersion pkg
22
    synopsis <- fromMaybe "" <$> expr (pkgSynopsis pkg)
23
    deps     <- getPkgDataList Deps
24
    haddocks <- expr . haddockDependencies =<< getContext
25
    hVersion <- expr $ pkgVersion haddock
26
    ghcOpts  <- haddockGhcArgs
27
    mconcat
28
        [ arg $ "--odir=" ++ takeDirectory output
Andrey Mokhov's avatar
Andrey Mokhov committed
29
        , arg "--verbosity=0"
30
        , arg "--no-tmp-comp-dir"
31
        , arg $ "--dump-interface=" ++ output
32 33
        , arg "--html"
        , arg "--hoogle"
Andrey Mokhov's avatar
Andrey Mokhov committed
34
        , arg $ "--title=" ++ pkgName pkg ++ "-" ++ version ++ ": " ++ synopsis
35
        , arg $ "--prologue=" ++ path -/- "haddock-prologue.txt"
36
        , arg $ "--optghc=-D__HADDOCK_VERSION__=" ++ show (versionToInt hVersion)
Andrey Mokhov's avatar
Andrey Mokhov committed
37 38 39
        , map ("--hide=" ++) <$> getPkgDataList HiddenModules
        , pure [ "--read-interface=../" ++ dep
                 ++ ",../" ++ dep ++ "/src/%{MODULE/./-}.html\\#%{NAME},"
40
                 ++ haddock | (dep, haddock) <- zip deps haddocks ]
Andrey Mokhov's avatar
Andrey Mokhov committed
41
        , pure [ "--optghc=" ++ opt | opt <- ghcOpts ]
42
        , isSpecified HsColour ?
Andrey Mokhov's avatar
Andrey Mokhov committed
43 44 45
          pure [ "--source-module=src/%{MODULE/./-}.html"
               , "--source-entity=src/%{MODULE/./-}.html\\#%{NAME}" ]
        , getInputs
46
        , arg "+RTS"
47
        , arg $ "-t" ++ path -/- "haddock.t"
48 49
        , arg "--machine-readable"
        , arg "-RTS" ]
50 51 52 53 54 55 56 57 58 59 60 61 62 63

-- From ghc.mk:
-- # -----------------------------------------------
-- # Haddock-related bits

-- # Build the Haddock contents and index
-- ifeq "$(HADDOCK_DOCS)" "YES"
-- libraries/dist-haddock/index.html: $(haddock_INPLACE) $(ALL_HADDOCK_FILES)
--     cd libraries && sh gen_contents_index --intree
-- ifeq "$(phase)" "final"
-- $(eval $(call all-target,library_doc_index,libraries/dist-haddock/index.html))
-- endif
-- INSTALL_LIBRARY_DOCS += libraries/dist-haddock/*
-- endif