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

3
4
import Hadrian.Utilities

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

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

15
16
haddockBuilderArgs :: Args
haddockBuilderArgs = builder Haddock ? do
17
    output   <- getOutput
18
    pkg      <- getPackage
19
    path     <- getBuildPath
20
21
22
    version  <- getPkgData Version
    synopsis <- getPkgData Synopsis
    deps     <- getPkgDataList Deps
23
24
25
    haddocks <- expr . haddockDependencies =<< getContext
    progPath <- expr $ buildPath (vanillaContext Stage2 haddock)
    hVersion <- expr $ pkgData (Version progPath)
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"
34
        , arg $ "--title=" ++ pkgNameString 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