packages feed

hdocs 0.4.4.2 → 0.5.0.0

raw patch · 5 files changed

+93/−30 lines, 5 filesdep −MonadCatchIO-transformersdep −transformersdep ~ghcdep ~haddock-apidep ~haddock-library

Dependencies removed: MonadCatchIO-transformers, transformers

Dependency ranges changed: ghc, haddock-api, haddock-library

Files

hdocs.cabal view
@@ -1,5 +1,5 @@ name:                hdocs
-version:             0.4.4.2
+version:             0.5.0.0
 synopsis:            Haskell docs tool
 description:
   Tool and library to get docs for installed packages and source files.
@@ -24,6 +24,10 @@ build-type:          Simple
 cabal-version:       >=1.8
 
+source-repository head
+  type: git
+  location: git://github.com/mvoidex/hdocs.git
+
 library
   hs-source-dirs: src
   ghc-options: -fno-warn-tabs
@@ -31,19 +35,26 @@     HDocs.Base
     HDocs.Haddock
     HDocs.Module
+  other-modules:
+    HDocs.Ghc.Compat
+  if impl(ghc >= 8.0)
+    build-depends:
+      ghc >= 8.0.0,
+      haddock-api >= 2.17.0 && < 2.18.0,
+      haddock-library == 1.4.*
+  if impl(ghc < 8.0)
+    build-depends:
+      ghc >= 7.8.1 && < 8.0.0,
+      haddock-api >= 2.16.0 && < 2.17.0,
+      haddock-library == 1.2.*
   build-depends:
     base >= 4.7 && < 5,
     aeson >= 0.7.0,
     bytestring >= 0.10.0,
     Cabal >= 1.22.2,
     filepath >= 1.3.0,
-    ghc >= 7.8.1,
     ghc-paths >= 0.1.0,
-    haddock-library == 1.2.*,
-    haddock-api >= 2.16.0 && < 2.17.0,
     containers >= 0.5.0,
-    transformers >= 0.3.0,
-    MonadCatchIO-transformers >= 0.3.0,
     network >= 2.4.0,
     process >= 1.2.0,
     text >= 1.1.0,
@@ -61,7 +72,7 @@     bytestring >= 0.10.0,
     containers >= 0.5.0,
     filepath >= 1.3.0,
-    haddock-api >= 2.16.0 && < 2.17.0,
+    haddock-api,
     mtl >= 2.1.0,
     network >= 2.4.0,
     text >= 1.1.0
src/HDocs/Base.hs view
@@ -18,30 +18,30 @@ import Name (occNameString)
 import Packages
 
+import HDocs.Ghc.Compat
+
 -- | Documentation in module
 type ModuleDocMap = Map String (Doc String)
 
 -- | Run action with initialized packages
 withInitializedPackages :: [String] -> (DynFlags -> IO a) -> IO a
-withInitializedPackages ghcOpts cont = do
-	runGhc (Just libdir) $ do
-		fs <- getSessionDynFlags
-		defaultCleanupHandler fs $ do
-			(fs', _, _) <- parseDynamicFlags fs (map noLoc ghcOpts)
-			setSessionDynFlags fs'
-			(result, _) <- GHC.liftIO $ initPackages fs'
-			GHC.liftIO $ cont result
+withInitializedPackages ghcOpts cont = runGhc (Just libdir) $ do
+	fs <- getSessionDynFlags
+	cleanupHandler fs $ do
+		(fs', _, _) <- parseDynamicFlags fs (map noLoc ghcOpts)
+		_ <- setSessionDynFlags fs'
+		(result, _) <- GHC.liftIO $ initPackages fs'
+		GHC.liftIO $ cont result
 
 -- | Config GHC session
 configSession :: [String] -> IO DynFlags
-configSession ghcOpts = do
-	runGhc (Just libdir) $ do
-		fs <- getSessionDynFlags
-		defaultCleanupHandler fs $ do
-			(fs', _, _) <- parseDynamicFlags fs (map noLoc ghcOpts)
-			setSessionDynFlags fs'
-			(result, _) <- GHC.liftIO $ initPackages fs'
-			return result
+configSession ghcOpts = runGhc (Just libdir) $ do
+	fs <- getSessionDynFlags
+	cleanupHandler fs $ do
+		(fs', _, _) <- parseDynamicFlags fs (map noLoc ghcOpts)
+		_ <- setSessionDynFlags fs'
+		(result, _) <- GHC.liftIO $ initPackages fs'
+		return result
 
 -- | Format documentation to plain text.
 formatDoc :: Doc String -> String
+ src/HDocs/Ghc/Compat.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE CPP #-}
+
+module HDocs.Ghc.Compat (
+	pkgDatabase, cleanupHandler, UnitId, unitId, moduleUnitId, getPackageDetails
+	) where
+
+import qualified GHC
+import qualified Module
+import qualified Packages as GHC
+
+#if __GLASGOW_HASKELL__ == 710
+import Exception (ExceptionMonad)
+#endif
+
+pkgDatabase :: GHC.DynFlags -> Maybe [GHC.PackageConfig]
+#if __GLASGOW_HASKELL__ == 800
+pkgDatabase = fmap (concatMap snd) . GHC.pkgDatabase
+#elif __GLASGOW_HASKELL__ == 710
+pkgDatabase = GHC.pkgDatabase
+#endif
+
+#if __GLASGOW_HASKELL__ == 800
+cleanupHandler :: GHC.DynFlags -> m a -> m a
+cleanupHandler _ = id
+#elif __GLASGOW_HASKELL__ == 710
+cleanupHandler :: (ExceptionMonad m) => GHC.DynFlags -> m a -> m a
+cleanupHandler = GHC.defaultCleanupHandler
+#endif
+
+#if __GLASGOW_HASKELL__ == 800
+type UnitId = Module.UnitId
+#elif __GLASGOW_HASKELL__ == 710
+type UnitId = Module.PackageKey
+#endif
+
+unitId :: GHC.PackageConfig -> UnitId
+#if __GLASGOW_HASKELL__ == 800
+unitId = GHC.unitId
+#elif __GLASGOW_HASKELL__ == 710
+unitId = GHC.packageKey
+#endif
+
+moduleUnitId :: Module.Module -> UnitId
+#if __GLASGOW_HASKELL__ == 800
+moduleUnitId = Module.moduleUnitId
+#elif __GLASGOW_HASKELL__ == 710
+moduleUnitId = Module.modulePackageKey
+#endif
+
+getPackageDetails :: GHC.DynFlags -> UnitId -> GHC.PackageConfig
+getPackageDetails = GHC.getPackageDetails
src/HDocs/Haddock.hs view
@@ -34,12 +34,12 @@ 
 import Exception (gtry)
 import GHC (Ghc)
-import DynFlags
 import Module
 import Name
 import PackageConfig
 
 import HDocs.Base
+import HDocs.Ghc.Compat
 
 -- | Read all installed docs
 readInstalledDocs :: [String] -> ExceptT String IO (Map String ModuleDocMap)
src/HDocs/Module.hs view
@@ -25,6 +25,7 @@ import Name
 
 import HDocs.Base
+import qualified HDocs.Ghc.Compat as Compat
 import qualified HDocs.Haddock as H
 
 -- | Load docs for all exported module symbols
@@ -52,24 +53,24 @@ 		where
 			pkgs = filter exposed $ map snd $ lookupModuleInAllPackages d (mkModuleName mname)
 
-	namePackage :: Name -> PackageKey
-	namePackage = modulePackageKey . nameModule
+	namePackage :: Name -> Compat.UnitId
+	namePackage = Compat.moduleUnitId . nameModule
 
-	ifacePackageDeps :: InstalledInterface -> [PackageKey]
-	ifacePackageDeps i = (modulePackageKey $ instMod i) `delete` (nub . map namePackage . instExports $ i)
+	ifacePackageDeps :: InstalledInterface -> [Compat.UnitId]
+	ifacePackageDeps i = (Compat.moduleUnitId $ instMod i) `delete` (nub . map namePackage . instExports $ i)
 
 	ifaceDep :: InstalledInterface -> InstalledInterface -> Bool
 	ifaceDep i idep = instMod i /= instMod idep && instMod idep `elem` map nameModule (instExports i)
 
 	pkgId :: DynFlags -> PackageConfig -> String
-	pkgId d = showSDoc d . ppr . installedPackageId
+	pkgId d = showSDoc d . ppr . Compat.unitId
 
 -- | Load docs for all installed modules
 installedDocs :: [String] -> ExceptT String IO (Map String ModuleDocMap)
 installedDocs opts = ExceptT $ withInitializedPackages opts (runExceptT . installedDocs') where
 	installedDocs' :: DynFlags -> ExceptT String IO (Map String ModuleDocMap)
 	installedDocs' d = do
-		fs <- maybe (throwError "Package database empty") (return . concatMap haddockInterfaces) $ pkgDatabase d
+		fs <- maybe (throwError "Package database empty") (return . concatMap haddockInterfaces) $ Compat.pkgDatabase d
 		ifaces <- liftM concat $ mapM ((`mplus` return []) . H.readInstalledInterfaces) fs
 		let
 			idocs = H.installedInterfacesDocs ifaces