packages feed

ghc-pkg-lib 0.3 → 0.3.1

raw patch · 2 files changed

+41/−26 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ghc-pkg-lib.cabal view
@@ -1,5 +1,5 @@ name:           ghc-pkg-lib-version:        0.3+version:        0.3.1 cabal-version:  >=1.14 build-type:     Simple author:         Thiago Arrais, JP Moresmau@@ -13,13 +13,13 @@ category:       Development homepage:       https://github.com/JPMoresmau/ghc-pkg-lib -flag lib-Werror-  default: False-  manual: True+--flag lib-Werror+--  default: False+--  manual: True  library   hs-source-dirs:   src-  build-depends:   +  build-depends:                     base < 5,                     ghc-paths >=0.1.0,                     filepath,@@ -29,9 +29,9 @@   ghc-options:      -Wall   exposed-modules:  Language.Haskell.Packages   default-language: Haskell98-  -  if flag(lib-Werror)-    ghc-options: -Werror++--  if flag(lib-Werror)+--    ghc-options: -Werror  source-repository head   type:     git
src/Language/Haskell/Packages.hs view
@@ -3,11 +3,11 @@ -- Module      : Language.Haskell.Packages
 -- Copyright   : (c) Thiago Arrais 2009
 -- License     : BSD3
--- 
+--
 -- Maintainer  : jpmoresmau@gmail.com
 -- Stability   : beta
 -- Portability : portable
--- 
+--
 -- Packages from packages databases (global, user).
 -- see <http://stackoverflow.com/questions/1522104/how-to-programmatically-retrieve-ghc-package-information>
 module Language.Haskell.Packages ( getPkgInfos ) where
@@ -16,12 +16,19 @@ import Prelude hiding (Maybe)
 import qualified System.Info
 import qualified Config
-import Control.Applicative
+
 import Data.List
 import Data.Maybe
 import Control.Monad
 import Distribution.InstalledPackageInfo
+#if MIN_VERSION_Cabal(1,22,0)
+import Distribution.ModuleName
+#else
+import Control.Applicative
 import Distribution.Text
+#endif
+
+
 import System.Directory
 import System.Environment (getEnv)
 import System.FilePath
@@ -33,7 +40,11 @@ import qualified Control.Exception as Exception
 
 -- This was borrowed from the ghc-pkg source:
+#if MIN_VERSION_Cabal(1,22,0)
+type InstalledPackageInfoString = InstalledPackageInfo_ ModuleName
+#else
 type InstalledPackageInfoString = InstalledPackageInfo_ String
+#endif
 
 -- | Types of cabal package databases
 data CabalPkgDBType =
@@ -48,7 +59,7 @@ -- databases, mimicking the functionality of ghc-pkg.
 getPkgInfos :: Maybe FilePath   -- ^ the path to the cabal sandbox if any
         -> IO InstalledPackagesList
-getPkgInfos msandbox= 
+getPkgInfos msandbox=
   let
     -- | Test for package database's presence in a given directory
     -- NB: The directory is returned for later scanning by listConf,
@@ -61,10 +72,10 @@         path_sd_dir= dir </> ("packages-" ++ ghcVersion ++ ".conf")
         -- cabal sandboxes
         path_ghc_dir= dir </> currentArch ++ '-' : currentOS ++ "-ghc-" ++ ghcVersion ++ "-packages.conf.d"
-                           
+
       in join . listToMaybe . filter isJust <$>
            mapM readIfExists [PkgDirectory path_dir,PkgFile path_file,PkgDirectory path_sd_dir,PkgDirectory path_ghc_dir]
-       
+
     currentArch :: String
     currentArch = System.Info.arch
 
@@ -87,7 +98,7 @@             e_appdir <- Exc.try $ getAppUserDataDirectory "ghc"
             case e_appdir of
                     Left (_::Exc.IOException) -> return []
-                    Right appdir -> do 
+                    Right appdir -> do
                        let subdir
                              = currentArch ++ '-' : currentOS ++ '-' : ghcVersion
                            dir = appdir </> subdir
@@ -114,13 +125,13 @@ readIfExists :: CabalPkgDBType -> IO (Maybe InstalledPackagesList)
 readIfExists p@(PkgDirectory path_dir) = do
         exists_dir <- doesDirectoryExist path_dir
-        if exists_dir 
-          then Just <$> readContents p 
+        if exists_dir
+          then Just <$> readContents p
           else return Nothing
 readIfExists p@(PkgFile path_dir) = do
         exists_dir <- doesFileExist path_dir
-        if exists_dir 
-          then Just <$> readContents p 
+        if exists_dir
+          then Just <$> readContents p
           else return Nothing
 
 -- | Read the contents of the given directory, searching for ".conf" files, and parse the
@@ -130,7 +141,7 @@                 -> IO InstalledPackagesList      -- ^ Installed packages
 
 readContents pkgdb =
-  let 
+  let
     -- | List package configuration files that might live in the given directory
     listConf :: FilePath -> IO [FilePath]
     listConf dbdir = do
@@ -158,8 +169,8 @@ #else
       hGetContents h
 #endif
-      
 
+
     -- | This function was lifted directly from ghc-pkg. Its sole purpose is
     -- parsing an input package description string and producing an
     -- InstalledPackageInfo structure.
@@ -169,7 +180,11 @@                                          hiddenModules = h })) =
             pkgconf{ exposedModules = convert e,
                      hiddenModules  = convert h }
+#if MIN_VERSION_Cabal(1,22,0)
+        where convert = map id
+#else
         where convert = mapMaybe simpleParse
+#endif
 
     -- | Utility function that just flips the arguments to Control.Exception.catch
     catchError :: IO a -> (String -> IO a) -> IO a
@@ -181,7 +196,7 @@     -- pairs.
     pkgInfoReader ::  FilePath
                       -> IO [InstalledPackageInfo]
-    pkgInfoReader f = 
+    pkgInfoReader f =
       Exc.catch (
          do
               pkgStr <- readUTF8File f
@@ -192,7 +207,7 @@                         print err
                         return [emptyInstalledPackageInfo]
         ) (\(_::Exc.IOException)->return [emptyInstalledPackageInfo])
-        
+
   in case pkgdb of
       (PkgDirectory pkgdbDir) -> do
         confs <- listConf pkgdbDir
@@ -212,9 +227,9 @@ getLibDir :: String
 getLibDir = libdir
 
--- | read an object from a String, with a given error message if it fails 
+-- | read an object from a String, with a given error message if it fails
 readObj :: Read a=> String -> String -> a
 readObj msg s=let parses=reads s -- :: [(a,String)]
-        in if null parses 
+        in if null parses
                 then error (msg ++ ": " ++ s ++ ".")
-                else fst $ head parses +                else fst $ head parses