[commit: ghc] wip/nfs-locking: Implement buildPackageDocumentation build rule. (b38d769)

git at git.haskell.org git at git.haskell.org
Thu Oct 26 23:35:26 UTC 2017


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

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/b38d769b73fa7576c2450c7d6057e5e0dd83b8f0/ghc

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

commit b38d769b73fa7576c2450c7d6057e5e0dd83b8f0
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date:   Wed Aug 19 02:42:50 2015 +0100

    Implement buildPackageDocumentation build rule.


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

b38d769b73fa7576c2450c7d6057e5e0dd83b8f0
 src/Rules/Documentation.hs | 53 ++++++++++++++++++++++++++++++++++++++++++++++
 src/Rules/Package.hs       |  4 +++-
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/src/Rules/Documentation.hs b/src/Rules/Documentation.hs
new file mode 100644
index 0000000..9cde8d1
--- /dev/null
+++ b/src/Rules/Documentation.hs
@@ -0,0 +1,53 @@
+module Rules.Documentation (buildPackageDocumentation) where
+
+import Way
+import Base
+import Stage
+import Builder
+import Package
+import Expression
+import Oracles.PackageData
+import qualified Target
+import Settings.TargetDirectory
+import Rules.Actions
+import Rules.Resources
+import Settings.Util
+import Settings.User
+import Settings.Packages
+import Control.Monad.Extra
+
+-- 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
+-- files in the Shake databases seems fragile and unnecesarry.
+buildPackageDocumentation :: Resources -> StagePackageTarget -> Rules ()
+buildPackageDocumentation _ target =
+    let stage   = Target.stage target
+        pkg     = Target.package target
+        name    = pkgName pkg
+        cabal   = pkgCabalPath pkg
+        haddock = pkgHaddockPath pkg
+    in when (stage == Stage1) $ do
+
+        haddock %> \file -> do
+            whenM (specified HsColour) $ do
+                need [cabal]
+                build $ fullTarget target GhcCabalHsColour [cabal] []
+            srcs <- interpret target getPackageSources
+            deps <- interpret target $ getPkgDataList DepNames
+            let haddocks = [ pkgHaddockPath depPkg
+                           | Just depPkg <- map findKnownPackage deps ]
+            need $ srcs ++ haddocks
+            let haddockWay = if dynamicGhcPrograms then dynamic else vanilla
+            build $ fullTargetWithWay target Haddock haddockWay srcs [file]
+
+-- $$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS =
+--    $$(foreach n,$$($1_$2_DEPS)
+--        ,$$($$n_HADDOCK_FILE) $$($$n_dist-install_$$(HADDOCK_WAY)_LIB))
+
+-- $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) :
+--     $$$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS) | $$$$(dir $$$$@)/.
+
+-- # 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
diff --git a/src/Rules/Package.hs b/src/Rules/Package.hs
index dbbe5cc..6e5448b 100644
--- a/src/Rules/Package.hs
+++ b/src/Rules/Package.hs
@@ -7,10 +7,12 @@ import Rules.Compile
 import Rules.Library
 import Rules.Resources
 import Rules.Dependencies
+import Rules.Documentation
 
 buildPackage :: Resources -> StagePackageTarget -> Rules ()
 buildPackage = mconcat
     [ buildPackageData
     , buildPackageDependencies
     , compilePackage
-    , buildPackageLibrary ]
+    , buildPackageLibrary
+    , buildPackageDocumentation ]



More information about the ghc-commits mailing list