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

3
4
import Hadrian.Utilities

5
import Settings.Builders.Common
6
7
import Settings.Builders.Ghc

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

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

-- 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