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

3
import Settings.Builders.Common
4
5
import Settings.Builders.Ghc

6
7
8
9
10
11
-- | 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

12
13
haddockBuilderArgs :: Args
haddockBuilderArgs = builder Haddock ? do
14
    output   <- getOutput
15
    pkg      <- getPackage
16
    path     <- getBuildPath
17
18
19
20
21
    version  <- getPkgData Version
    synopsis <- getPkgData Synopsis
    hidden   <- getPkgDataList HiddenModules
    deps     <- getPkgDataList Deps
    depNames <- getPkgDataList DepNames
22
    hVersion <- lift . pkgData . Version $ buildPath (vanillaContext Stage2 haddock)
23
24
    ghcOpts  <- fromDiffExpr commonGhcArgs
    mconcat
25
        [ arg $ "--odir=" ++ takeDirectory output
Andrey Mokhov's avatar
Andrey Mokhov committed
26
        , arg "--verbosity=0"
27
        , arg "--no-tmp-comp-dir"
28
        , arg $ "--dump-interface=" ++ output
29
30
        , arg "--html"
        , arg "--hoogle"
31
        , arg $ "--title=" ++ pkgNameString pkg ++ "-" ++ version ++ ": " ++ synopsis
32
        , arg $ "--prologue=" ++ path -/- "haddock-prologue.txt"
33
        , arg $ "--optghc=-D__HADDOCK_VERSION__=" ++ show (versionToInt hVersion)
34
35
36
        , append $ map ("--hide=" ++) hidden
        , append $ [ "--read-interface=../" ++ dep
                     ++ ",../" ++ dep ++ "/src/%{MODULE/./-}.html\\#%{NAME},"
Andrey Mokhov's avatar
Andrey Mokhov committed
37
                     ++ pkgHaddockFile (vanillaContext Stage1 depPkg)
38
                   | (dep, depName) <- zip deps depNames
39
40
                   , Just depPkg <- [findKnownPackage $ PackageName depName]
                   , depPkg /= rts ]
41
        , append [ "--optghc=" ++ opt | opt <- ghcOpts ]
Andrey Mokhov's avatar
Andrey Mokhov committed
42
43
44
45
        , specified HsColour ?
          arg "--source-module=src/%{MODULE/./-}.html"
        , specified HsColour ?
          arg "--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