[commit: haddock] T6018-injective-type-families, adamse-D1033, ghc-head, wip/10268, wip/10313, wip/D548-master, wip/D548-master-2, wip/T10483, wip/T8584, wip/T9840, wip/api-ann-hstylit, wip/api-ann-hstylit-1, wip/api-ann-hstylit-2, wip/api-ann-hstylit-3, wip/api-ann-hstylit-4, wip/api-ann-hstylit-5, wip/ast-annotations-separate, wip/ast-prepare-annotations, wip/ast-prepare-annotations-final, wip/ast-prepare-annotations-final2, wip/ast-prepare-annotations-final3, wip/ast-prepare-annotations-final4, wip/ast-prepare-annotations-final5, wip/ast-prepare-annotations-final6, wip/orf-new, wip/orf-reboot, wip/pattern-synonyms, wip/rae, wip/remove-cabal-dep, wip/trac-9744: Changes due to ghc api changes in package representation (b2a807d)

git at git.haskell.org git at git.haskell.org
Wed Jul 8 08:30:55 UTC 2015


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

On branches: T6018-injective-type-families,adamse-D1033,ghc-head,wip/10268,wip/10313,wip/D548-master,wip/D548-master-2,wip/T10483,wip/T8584,wip/T9840,wip/api-ann-hstylit,wip/api-ann-hstylit-1,wip/api-ann-hstylit-2,wip/api-ann-hstylit-3,wip/api-ann-hstylit-4,wip/api-ann-hstylit-5,wip/ast-annotations-separate,wip/ast-prepare-annotations,wip/ast-prepare-annotations-final,wip/ast-prepare-annotations-final2,wip/ast-prepare-annotations-final3,wip/ast-prepare-annotations-final4,wip/ast-prepare-annotations-final5,wip/ast-prepare-annotations-final6,wip/orf-new,wip/orf-reboot,wip/pattern-synonyms,wip/rae,wip/remove-cabal-dep,wip/trac-9744
Link       : http://git.haskell.org/haddock.git/commitdiff/b2a807da55d197c648fd2df1f156f9862711d92b

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

commit b2a807da55d197c648fd2df1f156f9862711d92b
Author: Duncan Coutts <duncan at well-typed.com>
Date:   Wed Aug 27 13:49:31 2014 +0100

    Changes due to ghc api changes in package representation
    
    Also fix a bug with finding the package name and version given a
    module. This had become wrong due to the package key changes (it was
    very hacky in the first place). We now look up the package key in the
    package db to get the package info properly.


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

b2a807da55d197c648fd2df1f156f9862711d92b
 src/Haddock.hs                 | 13 ++++++++-----
 src/Haddock/Backends/Hoogle.hs |  6 ++++--
 src/Haddock/GhcUtils.hs        | 25 +++++--------------------
 3 files changed, 17 insertions(+), 27 deletions(-)

diff --git a/src/Haddock.hs b/src/Haddock.hs
index 024b109..bed4762 100644
--- a/src/Haddock.hs
+++ b/src/Haddock.hs
@@ -42,7 +42,6 @@ import Data.IORef
 import qualified Data.Map as Map
 import System.IO
 import System.Exit
-import System.Directory
 
 #if defined(mingw32_HOST_OS)
 import Foreign
@@ -63,6 +62,8 @@ import DynFlags hiding (verbosity)
 import StaticFlags (discardStaticFlags)
 import Panic (handleGhcException)
 import Module
+import PackageConfig
+import FastString
 
 --------------------------------------------------------------------------------
 -- * Exception handling
@@ -242,7 +243,7 @@ render dflags flags qual ifaces installedIfaces srcMap = do
     pkgMod           = ifaceMod (head ifaces)
     pkgKey            = modulePackageKey pkgMod
     pkgStr           = Just (packageKeyString pkgKey)
-    (pkgName,pkgVer) = modulePackageInfo pkgMod
+    (pkgName,pkgVer) = modulePackageInfo dflags pkgMod
 
     (srcBase, srcModule, srcEntity, srcLEntity) = sourceUrls flags
     srcMap' = maybe srcMap (\path -> Map.insert pkgKey path srcMap) srcEntity
@@ -276,14 +277,16 @@ render dflags flags qual ifaces installedIfaces srcMap = do
     copyHtmlBits odir libDir themes
 
   when (Flag_Hoogle `elem` flags) $ do
-    let pkgName2 = if pkgName == "main" && title /= [] then title else pkgName
-    ppHoogle dflags pkgName2 pkgVer title prologue visibleIfaces odir
+    let pkgNameStr | unpackFS pkgNameFS == "main" && title /= []
+                               = title
+                   | otherwise = unpackFS pkgNameFS
+          where PackageName pkgNameFS = pkgName
+    ppHoogle dflags pkgNameStr pkgVer title prologue visibleIfaces odir
 
   when (Flag_LaTeX `elem` flags) $ do
     ppLaTeX title pkgStr visibleIfaces odir prologue opt_latex_style
                   libDir
 
-
 -------------------------------------------------------------------------------
 -- * Reading and dumping interface files
 -------------------------------------------------------------------------------
diff --git a/src/Haddock/Backends/Hoogle.hs b/src/Haddock/Backends/Hoogle.hs
index 628e1cd..1314529 100644
--- a/src/Haddock/Backends/Hoogle.hs
+++ b/src/Haddock/Backends/Hoogle.hs
@@ -25,6 +25,7 @@ import Outputable
 import Data.Char
 import Data.List
 import Data.Maybe
+import Data.Version
 import System.FilePath
 import System.IO
 
@@ -34,13 +35,14 @@ prefix = ["-- Hoogle documentation, generated by Haddock"
          ,""]
 
 
-ppHoogle :: DynFlags -> String -> String -> String -> Maybe (Doc RdrName) -> [Interface] -> FilePath -> IO ()
+ppHoogle :: DynFlags -> String -> Version -> String -> Maybe (Doc RdrName) -> [Interface] -> FilePath -> IO ()
 ppHoogle dflags package version synopsis prologue ifaces odir = do
     let filename = package ++ ".txt"
         contents = prefix ++
                    docWith dflags (drop 2 $ dropWhile (/= ':') synopsis) prologue ++
                    ["@package " ++ package] ++
-                   ["@version " ++ version | version /= ""] ++
+                   ["@version " ++ showVersion version
+                   | not (null (versionBranch version)) ] ++
                    concat [ppModule dflags i | i <- ifaces, OptHide `notElem` ifaceOptions i]
     h <- openFile (odir </> filename) WriteMode
     hSetEncoding h utf8
diff --git a/src/Haddock/GhcUtils.hs b/src/Haddock/GhcUtils.hs
index 33d9213..2c7b79a 100644
--- a/src/Haddock/GhcUtils.hs
+++ b/src/Haddock/GhcUtils.hs
@@ -22,8 +22,6 @@ import Control.Arrow
 import Data.Foldable hiding (concatMap)
 import Data.Function
 import Data.Traversable
-import Distribution.Compat.ReadP
-import Distribution.Text
 
 import Exception
 import Outputable
@@ -43,24 +41,11 @@ moduleString = moduleNameString . moduleName
 
 
 -- return the (name,version) of the package
-modulePackageInfo :: Module -> (String, [Char])
-modulePackageInfo modu = case unpackPackageKey pkg of
-                          Nothing -> (packageKeyString pkg, "")
-                          Just x -> (display $ pkgName x, showVersion (pkgVersion x))
-  where pkg = modulePackageKey modu
-
-
--- This was removed from GHC 6.11
--- XXX we shouldn't be using it, probably
-
--- | Try and interpret a GHC 'PackageKey' as a cabal 'PackageIdentifer'. Returns @Nothing@ if
--- we could not parse it as such an object.
-unpackPackageKey :: PackageKey -> Maybe PackageIdentifier
-unpackPackageKey p
-  = case [ pid | (pid,"") <- readP_to_S parse str ] of
-        []      -> Nothing
-        (pid:_) -> Just pid
-  where str = packageKeyString p
+modulePackageInfo :: DynFlags -> Module -> (PackageName, Version)
+modulePackageInfo dflags modu =
+    (packageName pkg, packageVersion pkg)
+  where
+    pkg = getPackageDetails dflags (modulePackageKey modu)
 
 
 lookupLoadedHomeModuleGRE  :: GhcMonad m => ModuleName -> m (Maybe GlobalRdrEnv)



More information about the ghc-commits mailing list