[commit: ghc] wip/T16197: Hadrian: handle Haddock's resource directory (2e05912)

git at git.haskell.org git at git.haskell.org
Thu Jan 17 13:59:28 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/T16197
Link       : http://ghc.haskell.org/trac/ghc/changeset/2e05912086bbb8eab213d44af300ecc396d912aa/ghc

>---------------------------------------------------------------

commit 2e05912086bbb8eab213d44af300ecc396d912aa
Author: Alec Theriault <alec.theriault at gmail.com>
Date:   Thu Jan 10 03:45:06 2019 -0800

    Hadrian: handle Haddock's resource directory
    
    Fixes #16105
    
      * Require Haddock's resource as runtime dependencies of the Haddock
        builder. This means we no longer have to `need` particular resources
        in every other documentation rule.
    
      * Do a _tracked_ copy of both the 'html' and 'latex' folder resource
        folders.
    
      * Move resources into `stage1/lib` (NB: the `haddock` binary goes in
        `stage1/bin`). Besides now actually matching the Haddock script
        wrapper generated by BinaryDist, this also prepares for Haddock
        in relocatable build folder detecting its own resources.


>---------------------------------------------------------------

2e05912086bbb8eab213d44af300ecc396d912aa
 hadrian/src/Builder.hs                   | 11 +++++++++++
 hadrian/src/Rules/Documentation.hs       | 32 ++++++++++++++++----------------
 hadrian/src/Settings/Builders/Haddock.hs |  4 ++--
 3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/hadrian/src/Builder.hs b/hadrian/src/Builder.hs
index a3a3f54..55dcb3c 100644
--- a/hadrian/src/Builder.hs
+++ b/hadrian/src/Builder.hs
@@ -23,6 +23,7 @@ import Hadrian.Builder.Sphinx
 import Hadrian.Builder.Tar
 import Hadrian.Oracles.Path
 import Hadrian.Oracles.TextFile
+import Hadrian.Oracles.DirectoryContents
 import Hadrian.Utilities
 
 import Base
@@ -187,6 +188,16 @@ instance H.Builder Builder where
 
         Hsc2Hs stage -> (\p -> [p]) <$> templateHscPath stage
         Make dir  -> return [dir -/- "Makefile"]
+
+        Haddock _ -> do
+            let resdir = "utils/haddock/haddock-api/resources"
+            latexResources <- directoryContents matchAll (resdir -/- "latex")
+            htmlResources  <- directoryContents matchAll (resdir -/- "html")
+
+            haddockLib <- stageLibPath Stage1   -- Haddock is built in stage1
+            return $ [ haddockLib -/- makeRelative resdir f
+                     | f <- latexResources ++ htmlResources ]
+
         _         -> return []
 
     -- query the builder for some information.
diff --git a/hadrian/src/Rules/Documentation.hs b/hadrian/src/Rules/Documentation.hs
index f1a7454..2aa663f 100644
--- a/hadrian/src/Rules/Documentation.hs
+++ b/hadrian/src/Rules/Documentation.hs
@@ -36,9 +36,6 @@ pdfRoot = docRoot -/- "pdfs"
 archiveRoot :: FilePath
 archiveRoot = docRoot -/- "archives"
 
-haddockHtmlLib :: FilePath
-haddockHtmlLib = htmlRoot -/- "haddock-bundle.min.js"
-
 manPageBuildPath :: FilePath
 manPageBuildPath = "docs/users_guide/build-man/ghc.1"
 
@@ -67,6 +64,8 @@ pathPath _ = ""
 -- | Build all documentation
 documentationRules :: Rules ()
 documentationRules = do
+    haddockResources
+
     buildDocumentationArchives
     buildHtmlDocumentation
     buildManPage
@@ -97,7 +96,6 @@ buildHtmlDocumentation = do
     root <- buildRootRules
 
     root -/- htmlRoot -/- "index.html" %> \file -> do
-        need [root -/- haddockHtmlLib]
         need $ map ((root -/-) . pathIndex) docPaths
         copyFileUntracked "docs/index.html" file
 
@@ -106,25 +104,30 @@ buildSphinxHtml :: FilePath -> Rules ()
 buildSphinxHtml path = do
     root <- buildRootRules
     root -/- htmlRoot -/- path -/- "index.html" %> \file -> do
-        need [root -/- haddockHtmlLib]
         let dest = takeDirectory file
         build $ target docContext (Sphinx Html) [pathPath path] [dest]
 
 ------------------------------------ Haddock -----------------------------------
 
+-- | Copy resources into the @lib@ directory
+haddockResources :: Rules ()
+haddockResources = do
+    root <- buildRootRules
+    let resdir = "utils/haddock/haddock-api/resources"
+        haddockLib = root -/- "stage1/lib"    -- Haddock is built in stage1
+
+    [ haddockLib -/- "html//*", haddockLib -/- "latex//*" ] |%> \target -> do
+        let source = resdir -/- makeRelative haddockLib target
+        copyFile source target
+
 -- | Build the haddocks for GHC's libraries.
 buildLibraryDocumentation :: Rules ()
 buildLibraryDocumentation = do
     root <- buildRootRules
 
-    -- Js and Css files for haddock output
-    root -/- haddockHtmlLib %> \_ ->
-        copyDirectory "utils/haddock/haddock-api/resources/html" (root -/- docRoot)
-
     -- Building the "Haskell Hierarchical Libraries" index
     root -/- htmlRoot -/- "libraries/index.html" %> \file -> do
-        need [ root -/- haddockHtmlLib
-             , "libraries/prologue.txt" ]
+        need [ "libraries/prologue.txt" ]
 
         -- We want Haddocks for everything except `rts` to be built, but we
         -- don't want the index to be polluted by stuff from `ghc`-the-library
@@ -152,7 +155,6 @@ buildPackageDocumentation = do
     -- Per-package haddocks
     root -/- htmlRoot -/- "libraries/*/haddock-prologue.txt" %> \file -> do
         ctx <- getPkgDocTarget root file >>= pkgDocContext
-        need [root -/- haddockHtmlLib]
         -- This is how @ghc-cabal@ used to produces "haddock-prologue.txt" files.
         syn  <- pkgSynopsis    (Context.package ctx)
         desc <- pkgDescription (Context.package ctx)
@@ -172,7 +174,7 @@ buildPackageDocumentation = do
         vanillaSrcs <- hsSources context
         let srcs = vanillaSrcs `union` generatedSrcs
 
-        need $ srcs ++ haddocks ++ [root -/- haddockHtmlLib]
+        need $ srcs ++ haddocks
 
         -- Build Haddock documentation
         -- TODO: Pass the correct way from Rules via Context.
@@ -220,7 +222,6 @@ buildSphinxPdf :: FilePath -> Rules ()
 buildSphinxPdf path = do
     root <- buildRootRules
     root -/- pdfRoot -/- path <.> "pdf" %> \file -> do
-        need [root -/- haddockHtmlLib]
         withTempDir $ \dir -> do
             build $ target docContext (Sphinx Latex) [pathPath path] [dir]
             build $ target docContext Xelatex [path <.> "tex"] [dir]
@@ -236,7 +237,6 @@ buildArchive :: FilePath -> Rules ()
 buildArchive path = do
     root <- buildRootRules
     root -/- pathArchive path %> \file -> do
-        need [root -/- haddockHtmlLib]
         root <- buildRoot
         let src = root -/- pathIndex path
         need [src]
@@ -247,7 +247,7 @@ buildManPage :: Rules ()
 buildManPage = do
     root <- buildRootRules
     root -/- manPageBuildPath %> \file -> do
-        need [root -/- haddockHtmlLib, "docs/users_guide/ghc.rst"]
+        need ["docs/users_guide/ghc.rst"]
         withTempDir $ \dir -> do
             build $ target docContext (Sphinx Man) ["docs/users_guide"] [dir]
             copyFileUntracked (dir -/- "ghc.1") file
diff --git a/hadrian/src/Settings/Builders/Haddock.hs b/hadrian/src/Settings/Builders/Haddock.hs
index 2830c20..92ac714 100644
--- a/hadrian/src/Settings/Builders/Haddock.hs
+++ b/hadrian/src/Settings/Builders/Haddock.hs
@@ -21,7 +21,7 @@ haddockBuilderArgs = mconcat
         root   <- getBuildRoot
         mconcat
             [ arg $ "-B" ++ root -/- "stage1" -/- "lib"
-            , arg $ "--lib=" ++ root -/- "docs"
+            , arg $ "--lib=" ++ root -/- "stage1" -/- "lib"
             , arg "--gen-index"
             , arg "--gen-contents"
             , arg "-o", arg $ takeDirectory output
@@ -46,7 +46,7 @@ haddockBuilderArgs = mconcat
         mconcat
             [ arg "--verbosity=0"
             , arg $ "-B" ++ root -/- "stage1" -/- "lib"
-            , arg $ "--lib=" ++ root -/- "docs"
+            , arg $ "--lib=" ++ root -/- "stage1" -/- "lib"
             , arg $ "--odir=" ++ takeDirectory output
             , arg "--no-tmp-comp-dir"
             , arg $ "--dump-interface=" ++ output



More information about the ghc-commits mailing list