7e98e2739b13fed53eb1b519489c67742d551de1
[hadrian.git] / src / Rules / Documentation.hs
1 module Rules.Documentation (buildPackageDocumentation) where
2
3 import Base
4 import Context
5 import Expression
6 import GHC
7 import Oracles.PackageData
8 import Rules.Actions
9 import Settings
10 import Target
11
12 haddockHtmlLib :: FilePath
13 haddockHtmlLib = "inplace/lib/html/haddock-util.js"
14
15 -- Note: this build rule creates plenty of files, not just the .haddock one.
16 -- All of them go into the 'doc' subdirectory. Pedantically tracking all built
17 -- files in the Shake databases seems fragile and unnecesarry.
18 buildPackageDocumentation :: Context -> Rules ()
19 buildPackageDocumentation context @ (Context {..}) =
20 let cabalFile = pkgCabalFile package
21 haddockFile = pkgHaddockFile package
22 in when (stage == Stage1) $ do
23 haddockFile %> \file -> do
24 srcs <- interpretInContext context getPackageSources
25 deps <- map PackageName <$> interpretInContext context (getPkgDataList DepNames)
26 let haddocks = [ pkgHaddockFile depPkg
27 | Just depPkg <- map findKnownPackage deps
28 , depPkg /= rts ]
29 need $ srcs ++ haddocks ++ [haddockHtmlLib]
30
31 -- HsColour sources
32 -- TODO: what is the output of GhcCabalHsColour?
33 whenM (specified HsColour) $ do
34 pkgConf <- pkgConfFile stage package
35 need [ cabalFile, pkgConf ] -- TODO: check if need pkgConf
36 build $ Target context GhcCabalHsColour [cabalFile] []
37
38 -- Build Haddock documentation
39 -- TODO: pass the correct way from Rules via Context
40 let haddockWay = if dynamicGhcPrograms then dynamic else vanilla
41 build $ Target (context {way = haddockWay}) Haddock srcs [file]
42
43 when (package == haddock) $ haddockHtmlLib %> \_ -> do
44 let dir = takeDirectory haddockHtmlLib
45 liftIO $ removeFiles dir ["//*"]
46 copyDirectory "utils/haddock/haddock-api/resources/html" dir
47
48 -- # Make the haddocking depend on the library .a file, to ensure
49 -- # that we wait until the library is fully built before we haddock it
50 -- $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$($1_$2_$$(HADDOCK_WAY)_LIB)
51 -- endif