Use Cabal directly in place of ghc-cabal + make build root configurable (#531)
[hadrian.git] / src / Settings / Builders / Haddock.hs
1 module Settings.Builders.Haddock (haddockBuilderArgs) where
2
3 import Hadrian.Haskell.Cabal
4 import Hadrian.Haskell.Cabal.PackageData as PD
5 import Hadrian.Utilities
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 = read . dropWhile (=='0') . filter (/='.')
13
14 haddockBuilderArgs :: Args
15 haddockBuilderArgs = withHsPackage $ \ctx -> mconcat
16 [ builder (Haddock BuildIndex) ? do
17 output <- getOutput
18 inputs <- getInputs
19 root <- getBuildRoot
20 mconcat
21 [ arg $ "-B" ++ root -/- "stage1" -/- "lib"
22 , arg $ "--lib=" ++ root -/- "docs"
23 , arg "--gen-index"
24 , arg "--gen-contents"
25 , arg "-o", arg $ takeDirectory output
26 , arg "-t", arg "Haskell Hierarchical Libraries"
27 , arg "-p", arg "libraries/prologue.txt"
28 , pure [ "--read-interface="
29 ++ (takeFileName . takeDirectory) haddock
30 ++ "," ++ haddock | haddock <- inputs ] ]
31
32 , builder (Haddock BuildPackage) ? do
33 output <- getOutput
34 pkg <- getPackage
35 root <- getBuildRoot
36 path <- getBuildPath
37 Just version <- expr $ pkgVersion ctx
38 Just synopsis <- expr $ pkgSynopsis ctx
39 deps <- getPackageData PD.depNames
40 haddocks <- expr . haddockDependencies =<< getContext
41 Just hVersion <- expr $ pkgVersion ctx
42 ghcOpts <- haddockGhcArgs
43 mconcat
44 [ arg "--verbosity=0"
45 , arg $ "-B" ++ root -/- "stage1" -/- "lib"
46 , arg $ "--lib=" ++ root -/- "docs"
47 , arg $ "--odir=" ++ takeDirectory output
48 , arg "--no-tmp-comp-dir"
49 , arg $ "--dump-interface=" ++ output
50 , arg "--html"
51 , arg "--hyperlinked-source"
52 , arg "--hoogle"
53 , arg "--quickjump"
54 , arg $ "--title=" ++ pkgName pkg ++ "-" ++ version
55 ++ ": " ++ synopsis
56 , arg $ "--prologue=" ++ takeDirectory output -/- "haddock-prologue.txt"
57 , arg $ "--optghc=-D__HADDOCK_VERSION__="
58 ++ show (versionToInt hVersion)
59 , map ("--hide=" ++) <$> getPackageData PD.otherModules
60 , pure [ "--read-interface=../" ++ dep
61 ++ ",../" ++ dep ++ "/src/%{MODULE}.html#%{NAME},"
62 ++ haddock | (dep, haddock) <- zip deps haddocks ]
63 , pure [ "--optghc=" ++ opt | opt <- ghcOpts, not ("--package-db" `isInfixOf` opt) ]
64 , getInputs
65 , arg "+RTS"
66 , arg $ "-t" ++ path -/- "haddock.t"
67 , arg "--machine-readable"
68 , arg "-RTS" ] ]