Clean up code, add comments.
[hadrian.git] / src / Rules / Documentation.hs
1 module Rules.Documentation (buildPackageDocumentation) where
2
3 import Expression
4 import Oracles
5 import Rules.Actions
6 import Rules.Resources
7 import Settings
8
9 -- Note: this build rule creates plenty of files, not just the .haddock one.
10 -- All of them go into the 'doc' subdirectory. Pedantically tracking all built
11 -- files in the Shake databases seems fragile and unnecesarry.
12 buildPackageDocumentation :: Resources -> PartialTarget -> Rules ()
13 buildPackageDocumentation _ target @ (PartialTarget _ pkg) =
14 let cabalFile = pkgCabalFile pkg
15 haddockFile = pkgHaddockFile pkg
16 in do
17 haddockFile %> \file -> do
18 whenM (specified HsColour) $ do
19 need [cabalFile]
20 build $ fullTarget target GhcCabalHsColour [cabalFile] []
21 srcs <- interpretPartial target getPackageSources
22 deps <- interpretPartial target $ getPkgDataList DepNames
23 let haddocks = [ pkgHaddockFile depPkg
24 | Just depPkg <- map findKnownPackage deps ]
25 need $ srcs ++ haddocks
26 let haddockWay = if dynamicGhcPrograms then dynamic else vanilla
27 build $ fullTargetWithWay target Haddock haddockWay srcs [file]
28
29 -- # Make the haddocking depend on the library .a file, to ensure
30 -- # that we wait until the library is fully built before we haddock it
31 -- $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$($1_$2_$$(HADDOCK_WAY)_LIB)
32 -- endif