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

Ben Gamari's avatar
Ben Gamari committed
3
import Base
4
import GHC
Andrey Mokhov's avatar
Andrey Mokhov committed
5
import Oracles.PackageData
6
import Predicate
Andrey Mokhov's avatar
Andrey Mokhov committed
7
import Settings
8
import Settings.Builders.Ghc
Andrey Mokhov's avatar
Andrey Mokhov committed
9
import Settings.Paths
10

11
12
13
14
15
16
-- | Given a version string such as "2.16.2" produce an integer equivalent.
versionToInt :: String -> Int
versionToInt s = major * 1000 + minor * 10 + patch
  where
    [major, minor, patch] = map read . words $ replaceEq '.' ' ' s

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

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