Documentation.hs 1.85 KB
Newer Older
1
2
module Rules.Documentation (buildPackageDocumentation) where

Ben Gamari's avatar
Ben Gamari committed
3
import Base
4
import Context
5
import Expression hiding (way)
Andrey Mokhov's avatar
Andrey Mokhov committed
6
import Flavour
7
import GHC
8
import Oracles.ModuleFiles
Andrey Mokhov's avatar
Andrey Mokhov committed
9
import Oracles.PackageData
10
import Settings
11
import Settings.Path
12
import Target
13
import Utilities
14

Andrey Mokhov's avatar
Andrey Mokhov committed
15
16
17
haddockHtmlLib :: FilePath
haddockHtmlLib = "inplace/lib/html/haddock-util.js"

18
19
-- Note: this build rule creates plenty of files, not just the .haddock one.
-- All of them go into the 'doc' subdirectory. Pedantically tracking all built
20
-- files in the Shake database seems fragile and unnecessary.
21
buildPackageDocumentation :: Context -> Rules ()
22
buildPackageDocumentation context@Context {..} =
Andrey Mokhov's avatar
Andrey Mokhov committed
23
    let haddockFile = pkgHaddockFile context
24
    in when (stage == Stage1) $ do
Andrey Mokhov's avatar
Andrey Mokhov committed
25
        haddockFile %> \file -> do
26
            srcs <- hsSources context
27
            deps <- map PackageName <$> interpretInContext context (getPkgDataList DepNames)
Andrey Mokhov's avatar
Andrey Mokhov committed
28
            let haddocks = [ pkgHaddockFile $ vanillaContext Stage1 depPkg
29
30
                           | Just depPkg <- map findKnownPackage deps
                           , depPkg /= rts ]
Andrey Mokhov's avatar
Andrey Mokhov committed
31
            need $ srcs ++ haddocks ++ [haddockHtmlLib]
32
33

            -- Build Haddock documentation
34
            -- TODO: pass the correct way from Rules via Context
Andrey Mokhov's avatar
Andrey Mokhov committed
35
            let haddockWay = if dynamicGhcPrograms flavour then dynamic else vanilla
36
            build $ target (context {way = haddockWay}) Haddock srcs [file]
37

38
        when (package == haddock) $ haddockHtmlLib %> \_ -> do
Andrey Mokhov's avatar
Andrey Mokhov committed
39
40
41
42
            let dir = takeDirectory haddockHtmlLib
            liftIO $ removeFiles dir ["//*"]
            copyDirectory "utils/haddock/haddock-api/resources/html" dir

43
44
45
46
-- # Make the haddocking depend on the library .a file, to ensure
-- # that we wait until the library is fully built before we haddock it
-- $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$($1_$2_$$(HADDOCK_WAY)_LIB)
-- endif