Refactor GHC/user packages, move builder-specific functions into Builder
[ghc.git] / src / Rules / Documentation.hs
1 module Rules.Documentation (buildPackageDocumentation, haddockDependencies) where
2
3 import Base
4 import Context
5 import Flavour
6 import GHC
7 import Oracles.ModuleFiles
8 import Oracles.PackageData
9 import Settings
10 import Target
11 import Utilities
12
13 haddockHtmlLib :: FilePath
14 haddockHtmlLib = "inplace/lib/html/haddock-util.js"
15
16 haddockDependencies :: Context -> Action [FilePath]
17 haddockDependencies context = do
18 path <- buildPath context
19 depNames <- pkgDataList $ DepNames path
20 sequence [ pkgHaddockFile $ vanillaContext Stage1 depPkg
21 | Just depPkg <- map findPackageByName depNames, depPkg /= rts ]
22
23 -- Note: this build rule creates plenty of files, not just the .haddock one.
24 -- All of them go into the 'doc' subdirectory. Pedantically tracking all built
25 -- files in the Shake database seems fragile and unnecessary.
26 buildPackageDocumentation :: Context -> Rules ()
27 buildPackageDocumentation context@Context {..} = when (stage == Stage1) $ do
28 "//" ++ contextDir context ++ "//*.haddock" %> \file -> do
29 srcs <- hsSources context
30 haddocks <- haddockDependencies context
31 need $ srcs ++ haddocks ++ [haddockHtmlLib]
32
33 -- Build Haddock documentation
34 -- TODO: pass the correct way from Rules via Context
35 dynamicPrograms <- dynamicGhcPrograms <$> flavour
36 let haddockWay = if dynamicPrograms then dynamic else vanilla
37 build $ target (context {way = haddockWay}) Haddock srcs [file]
38
39 when (package == haddock) $ haddockHtmlLib %> \_ -> do
40 let dir = takeDirectory haddockHtmlLib
41 liftIO $ removeFiles dir ["//*"]
42 copyDirectory "utils/haddock/haddock-api/resources/html" dir
43
44 -- # Make the haddocking depend on the library .a file, to ensure
45 -- # that we wait until the library is fully built before we haddock it
46 -- $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$($1_$2_$$(HADDOCK_WAY)_LIB)
47 -- endif