Invoke Haddock directly from the build system, instead of via Cabal
authorSimon Marlow <marlowsd@gmail.com>
Tue, 12 Jan 2010 22:55:48 +0000 (22:55 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Tue, 12 Jan 2010 22:55:48 +0000 (22:55 +0000)
Partly this is cleaner as we only have to preprocess the source files
once, but also it is necessary to avoid Haddock recompiling source
files when Template Haskell is in use, saving some time in validate
and fixing a problem whereby when HADDOCK_DOCS=YES, make always
re-haddocks the DPH packages.  This also needs an additional fix to
GHC.

HsColour support still uses Cabal, and hence preprocesses the source
files again. We could move this into the build system too, but there
is a version dependency that would mean adding extra autoconf stuff.

compiler/ghc.mk
ghc.mk
rules/haddock.mk
utils/ghc-cabal/ghc-cabal.hs

index 901b069..b33117a 100644 (file)
@@ -395,7 +395,7 @@ compiler_stage3_CONFIGURE_OPTS := $(compiler_stage2_CONFIGURE_OPTS)
 compiler_stage1_CONFIGURE_OPTS += --ghc-option=-DSTAGE=1
 compiler_stage2_CONFIGURE_OPTS += --ghc-option=-DSTAGE=2
 compiler_stage3_CONFIGURE_OPTS += --ghc-option=-DSTAGE=3
-compiler_stage2_HADDOCK_OPTS += --haddock-option=--optghc=-DSTAGE=2
+compiler_stage2_HADDOCK_OPTS += --optghc=-DSTAGE=2
 
 compiler_stage1_CONFIGURE_OPTS += --ghc-options='$(GhcStage1HcOpts)'
 compiler_stage2_CONFIGURE_OPTS += --ghc-options='$(GhcStage2HcOpts)'
diff --git a/ghc.mk b/ghc.mk
index 9eaa7cd..2c189b9 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -442,9 +442,8 @@ PRIMOPS_TXT = $(GHC_COMPILER_DIR)/prelude/primops.txt
 libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT) | $$(dir $$@)/.
        "$(GENPRIMOP_INPLACE)" --make-haskell-wrappers <$(PRIMOPS_TXT) >$@
 
-libraries/ghc-prim/GHC/Prim.hs : $(GENPRIMOP_INPLACE) $(PRIMOPS_TXT)
-       "$(GENPRIMOP_INPLACE)" --make-haskell-source <$(PRIMOPS_TXT) >$@
-
+# Required so that Haddock documents the primops.
+libraries/ghc-prim_dist-install_EXTRA_HADDOCK_SRCS = libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs
 
 # -----------------------------------------------------------------------------
 # Include build instructions from all subdirs
@@ -729,7 +728,7 @@ install_perl : $(INPLACE_PERL)
 endif # Windows
 
 ifneq "$(BINDIST)" "YES"
-$(ghc-prim_HADDOCK_FILE): \
+$(ghc-prim-$(libraries/ghc-prim_dist-install_VERSION)_HADDOCK_FILE): \
     libraries/ghc-prim/dist-install/build/autogen/GHC/Prim.hs \
     libraries/ghc-prim/dist-install/build/autogen/GHC/PrimopWrappers.hs
 endif # BINDIST
index 98838c9..f0d0aff 100644 (file)
@@ -15,31 +15,42 @@ define haddock  # args: $1 = dir,  $2 = distdir
 
 ifneq "$$($1_$2_DO_HADDOCK)" "NO"
 
-ifeq "$$($$($1_PACKAGE)_HADDOCK_FILE)" ""
-$$($1_PACKAGE)_HADDOCK_FILE = $1/$2/doc/html/$$($1_PACKAGE)/$$($1_PACKAGE).haddock
-ALL_HADDOCK_FILES += $$($$($1_PACKAGE)_HADDOCK_FILE)
+ifeq "$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)" ""
+$$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE = $1/$2/doc/html/$$($1_PACKAGE)/$$($1_PACKAGE).haddock
+ALL_HADDOCK_FILES += $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)
 else
 $$(error Already got a haddock file for $$($1_PACKAGE))
 endif
 
-haddock: $$($$($1_PACKAGE)_HADDOCK_FILE)
+haddock: $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)
 
 ifeq "$$(HADDOCK_DOCS)" "YES"
 $(call all-target,$1_$2_haddock,html_$1)
 endif
 
 .PHONY: html_$1
-html_$1 : $$($$($1_PACKAGE)_HADDOCK_FILE)
+html_$1 : $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE)
 
-$$($1_PACKAGE)_HADDOCK_DEPS = $$(foreach n,$$($1_$2_DEP_NAMES),$$($$n_HADDOCK_FILE))
+$$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS = $$(foreach n,$$($1_$2_DEPS),$$($$n_HADDOCK_FILE))
 
 ifeq "$$(HSCOLOUR_SRCS)" "YES"
-$1_$2_HADDOCK_FLAGS += --hyperlink-source
+$1_$2_HADDOCK_FLAGS += --source-module=src/%{MODULE/./-}.html --source-entity=src/%{MODULE/./-}.html#%{NAME}
 endif
 
 ifneq "$$(BINDIST)" "YES"
-$$($$($1_PACKAGE)_HADDOCK_FILE) : $$(INPLACE_BIN)/haddock$$(exeext) $$(GHC_CABAL_INPLACE) $$($1_$2_HS_SRCS) $$($$($1_PACKAGE)_HADDOCK_DEPS) | $$$$(dir $$$$@)/.
-       "$$(GHC_CABAL_INPLACE)" haddock $2 $1 --with-haddock=$$(TOP)/$$(INPLACE_BIN)/haddock --with-ghc=$$(TOP)/$$(INPLACE_BIN)/ghc-stage2 $$($1_$2_HADDOCK_FLAGS) $$($1_$2_HADDOCK_OPTS)
+$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) : $$(INPLACE_BIN)/haddock$$(exeext) $$(GHC_CABAL_INPLACE) $$($1_$2_HS_SRCS) $$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_DEPS) | $$$$(dir $$$$@)/.
+       "$$(GHC_CABAL_INPLACE)" hscolour $2 $1
+       "$$(TOP)/$$(INPLACE_BIN)/haddock" \
+         --odir="$1/$2/doc/html/$$($1_PACKAGE)" \
+         --dump-interface=$$($$($1_PACKAGE)-$$($1_$2_VERSION)_HADDOCK_FILE) \
+         --html \
+         --title="$$($1_PACKAGE)-$$($1_$2_VERSION)$$(if $$(strip $$($1_$2_SYNOPSIS)),: $$(strip $$($1_$2_SYNOPSIS)),)" \
+         --prologue="$1/$2/haddock-prologue.txt" \
+         $$(foreach pkg,$$($1_$2_DEPS),$$(if $$($$(pkg)_HADDOCK_FILE),--read-interface=../$$(pkg)$$(comma)$$($$(pkg)_HADDOCK_FILE))) \
+         $$(foreach opt,$$($1_$2_v_ALL_HC_OPTS),--optghc=$$(opt)) \
+         $$($1_$2_HADDOCK_FLAGS) $$($1_$2_HADDOCK_OPTS) \
+         $$($1_$2_HS_SRCS) \
+         $$($1_$2_EXTRA_HADDOCK_SRCS)
 
 # Make the haddocking depend on the library .a file, to ensure
 # that we wait until the library is fully build before we haddock it
index c3a4789..2e967e9 100644 (file)
@@ -30,8 +30,8 @@ import System.FilePath
 main :: IO ()
 main = do args <- getArgs
           case args of
-              "haddock" : distDir : dir : args' ->
-                  runHaddock distDir dir args'
+              "hscolour" : distDir : dir : args' ->
+                  runHsColour distDir dir args'
               "check" : dir : [] ->
                   doCheck dir
               "install" : ghc : ghcpkg : strip : topdir : directory : distDir
@@ -52,7 +52,7 @@ syntax_error :: [String]
 syntax_error =
     ["syntax: ghc-cabal configure <configure-args> -- <distdir> <directory>...",
      "        ghc-cabal install <ghc-pkg> <directory> <distdir> <destdir> <prefix> <args>...",
-     "        ghc-cabal haddock <distdir> <directory> <args>..."]
+     "        ghc-cabal hscolour <distdir> <directory> <args>..."]
 
 die :: [String] -> IO a
 die errs = do mapM_ (hPutStrLn stderr) errs
@@ -111,32 +111,10 @@ doCheck directory
     where isFailure (PackageDistSuspicious {}) = False
           isFailure _ = True
 
-runHaddock :: FilePath -> FilePath -> [String] -> IO ()
-runHaddock distdir directory args
+runHsColour :: FilePath -> FilePath -> [String] -> IO ()
+runHsColour distdir directory args
  = withCurrentDirectory directory
- $ defaultMainWithHooksArgs hooks ("haddock" : "--builddir" : distdir : args)
-    where
-      hooks = userHooks {
-                  haddockHook = modHook (haddockHook userHooks)
-              }
-      modHook f pd lbi us flags
-       | packageName pd == PackageName "ghc-prim"
-          = let pd' = case library pd of
-                      Just lib ->
-                          let ghcPrim = fromJust (simpleParse "GHC.Prim")
-                              ems = filter (ghcPrim /=)
-                                           (exposedModules lib)
-                              lib' = lib { exposedModules = ems }
-                          in pd { library = Just lib' }
-                      Nothing ->
-                          error "Expected a library, but none found"
-                pc = withPrograms lbi
-                pc' = userSpecifyArgs "haddock"
-                          ["dist-install/build/autogen/GHC/Prim.hs"] pc
-                lbi' = lbi { withPrograms = pc' }
-            in f pd' lbi' us flags
-       | otherwise
-          = f pd lbi us flags
+ $ defaultMainArgs ("hscolour" : "--builddir" : distdir : args)
 
 doInstall :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath
           -> FilePath -> FilePath -> FilePath -> FilePath -> FilePath
@@ -358,6 +336,7 @@ generate config_args distdir directory
       let variablePrefix = directory ++ '_':distdir
       let xs = [variablePrefix ++ "_VERSION = " ++ display (pkgVersion (package pd)),
                 variablePrefix ++ "_MODULES = " ++ unwords (map display modules),
+                variablePrefix ++ "_SYNOPSIS =" ++ synopsis pd,
                 variablePrefix ++ "_HS_SRC_DIRS = " ++ unwords (hsSourceDirs bi),
                 variablePrefix ++ "_DEPS = " ++ unwords (map display dep_ids),
                 variablePrefix ++ "_DEP_NAMES = " ++ unwords (map (display . packageName) dep_ids),
@@ -384,6 +363,9 @@ generate config_args distdir directory
                 variablePrefix ++ "_DEP_EXTRA_LIBS = " ++ unwords (forDeps Installed.extraLibraries),
                 variablePrefix ++ "_DEP_LD_OPTS = "    ++ unwords (forDeps Installed.ldOptions)]
       writeFile (distdir ++ "/package-data.mk") $ unlines xs
+      writeFile (distdir ++ "/haddock-prologue.txt") $ 
+          if null (description pd) then synopsis pd
+                                   else description pd
   where
      escape = foldr (\c xs -> if c == '#' then '\\':'#':xs else c:xs) []
      wrap = map (\s -> "\'" ++ s ++ "\'")