ed29012c0a9fc234a72297c2fc6c21e5f457b22a
[hadrian.git] / src / Settings / Builders / Haddock.hs
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 import Settings.Builders.Ghc
9
10 -- | Given a version string such as "2.16.2" produce an integer equivalent.
11 versionToInt :: String -> Int
12 versionToInt s = case map read . words $ replaceEq '.' ' ' s of
13 [major, minor, patch] -> major * 1000 + minor * 10 + patch
14 _ -> error "versionToInt: cannot parse version."
15
16 haddockBuilderArgs :: Args
17 haddockBuilderArgs = withHsPackage $ \cabalFile -> mconcat
18 [ builder (Haddock BuildIndex) ? do
19 output <- getOutput
20 inputs <- getInputs
21 mconcat
22 [ arg "--gen-index"
23 , arg "--gen-contents"
24 , arg "-o", arg $ takeDirectory output
25 , arg "-t", arg "Haskell Hierarchical Libraries"
26 , arg "-p", arg "libraries/prologue.txt"
27 , pure [ "--read-interface="
28 ++ (takeFileName . takeDirectory) haddock
29 ++ "," ++ haddock | haddock <- inputs ] ]
30
31 , builder (Haddock BuildPackage) ? do
32 output <- getOutput
33 pkg <- getPackage
34 path <- getBuildPath
35 version <- expr $ pkgVersion cabalFile
36 synopsis <- expr $ pkgSynopsis cabalFile
37 deps <- getPkgDataList DepNames
38 haddocks <- expr . haddockDependencies =<< getContext
39 hVersion <- expr $ pkgVersion (unsafePkgCabalFile haddock) -- TODO: improve
40 ghcOpts <- haddockGhcArgs
41 mconcat
42 [ arg "--verbosity=0"
43 , arg $ "--odir=" ++ takeDirectory output
44 , arg "--no-tmp-comp-dir"
45 , arg $ "--dump-interface=" ++ output
46 , arg "--html"
47 , arg "--hyperlinked-source"
48 , arg "--hoogle"
49 , arg "--quickjump"
50 , arg $ "--title=" ++ pkgName pkg ++ "-" ++ version
51 ++ ": " ++ synopsis
52 , arg $ "--prologue=" ++ path -/- "haddock-prologue.txt"
53 , arg $ "--optghc=-D__HADDOCK_VERSION__="
54 ++ show (versionToInt hVersion)
55 , map ("--hide=" ++) <$> getPkgDataList HiddenModules
56 , pure [ "--read-interface=../" ++ dep
57 ++ ",../" ++ dep ++ "/src/%{MODULE}.html#%{NAME},"
58 ++ haddock | (dep, haddock) <- zip deps haddocks ]
59 , pure [ "--optghc=" ++ opt | opt <- ghcOpts ]
60 , getInputs
61 , arg "+RTS"
62 , arg $ "-t" ++ path -/- "haddock.t"
63 , arg "--machine-readable"
64 , arg "-RTS" ] ]