2137caea77edb6114a7038aa1ce6a01939ff6331
[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 stage pkg) =
14 let cabalFile = pkgCabalFile pkg
15 haddockFile = pkgHaddockFile pkg
16 in when (stage == Stage1) $ do
17
18 haddockFile %> \file -> do
19 whenM (specified HsColour) $ do
20 need [cabalFile]
21 build $ fullTarget target GhcCabalHsColour [cabalFile] []
22 srcs <- interpretPartial target getPackageSources
23 deps <- interpretPartial target $ getPkgDataList DepNames
24 let haddocks = [ pkgHaddockFile depPkg
25 | Just depPkg <- map findKnownPackage deps ]
26 need $ srcs ++ haddocks
27 let haddockWay = if dynamicGhcPrograms then dynamic else vanilla
28 build $ fullTargetWithWay target Haddock haddockWay srcs [file]
29
30 -- $$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS =
31 -- $$(foreach n,$$($1_$2_DEPS)
32 -- ,$$($$n_HADDOCK_FILE) $$($$n_dist-install_$$(HADDOCK_WAY)_LIB))
33
34 -- $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) :
35 -- $$$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS) | $$$$(dir $$$$@)/.
36
37 -- # Make the haddocking depend on the library .a file, to ensure
38 -- # that we wait until the library is fully built before we haddock it
39 -- $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$($1_$2_$$(HADDOCK_WAY)_LIB)
40 -- endif