Hadrian: handle Haddock's resource directory
[ghc.git] / hadrian / src / Settings / Builders / Haddock.hs
1 module Settings.Builders.Haddock (haddockBuilderArgs) where
2
3 import Hadrian.Haskell.Cabal
4 import Hadrian.Haskell.Cabal.Type
5 import Hadrian.Utilities
6
7 import Packages
8 import Rules.Documentation
9 import Settings.Builders.Common
10 import Settings.Builders.Ghc
11
12 -- | Given a version string such as "2.16.2" produce an integer equivalent.
13 versionToInt :: String -> Int
14 versionToInt = read . dropWhile (=='0') . filter (/='.')
15
16 haddockBuilderArgs :: Args
17 haddockBuilderArgs = mconcat
18 [ builder (Haddock BuildIndex) ? do
19 output <- getOutput
20 inputs <- getInputs
21 root <- getBuildRoot
22 mconcat
23 [ arg $ "-B" ++ root -/- "stage1" -/- "lib"
24 , arg $ "--lib=" ++ root -/- "stage1" -/- "lib"
25 , arg "--gen-index"
26 , arg "--gen-contents"
27 , arg "-o", arg $ takeDirectory output
28 , arg "-t", arg "Haskell Hierarchical Libraries"
29 , arg "-p", arg "libraries/prologue.txt"
30 , pure [ "--read-interface="
31 ++ (takeFileName . takeDirectory) haddock
32 ++ "," ++ haddock | haddock <- inputs ] ]
33
34 , builder (Haddock BuildPackage) ? do
35 output <- getOutput
36 pkg <- getPackage
37 root <- getBuildRoot
38 path <- getBuildPath
39 context <- getContext
40 version <- expr $ pkgVersion pkg
41 synopsis <- expr $ pkgSynopsis pkg
42 deps <- getContextData depNames
43 haddocks <- expr $ haddockDependencies context
44 hVersion <- expr $ pkgVersion haddock
45 ghcOpts <- haddockGhcArgs
46 mconcat
47 [ arg "--verbosity=0"
48 , arg $ "-B" ++ root -/- "stage1" -/- "lib"
49 , arg $ "--lib=" ++ root -/- "stage1" -/- "lib"
50 , arg $ "--odir=" ++ takeDirectory output
51 , arg "--no-tmp-comp-dir"
52 , arg $ "--dump-interface=" ++ output
53 , arg "--html"
54 , arg "--hyperlinked-source"
55 , arg "--hoogle"
56 , arg "--quickjump"
57 , arg $ "--title=" ++ pkgName pkg ++ "-" ++ version
58 ++ ": " ++ synopsis
59 , arg $ "--prologue=" ++ takeDirectory output -/- "haddock-prologue.txt"
60 , arg $ "--optghc=-D__HADDOCK_VERSION__="
61 ++ show (versionToInt hVersion)
62 , map ("--hide=" ++) <$> getContextData otherModules
63 , pure [ "--read-interface=../" ++ dep
64 ++ ",../" ++ dep ++ "/src/%{MODULE}.html#%{NAME},"
65 ++ haddock | (dep, haddock) <- zip deps haddocks ]
66 , pure [ "--optghc=" ++ opt | opt <- ghcOpts, not ("--package-db" `isInfixOf` opt) ]
67 , getInputs
68 , arg "+RTS"
69 , arg $ "-t" ++ path -/- "haddock.t"
70 , arg "--machine-readable"
71 , arg "-RTS" ] ]