1 {-# LANGUAGE RecordWildCards, TypeSynonymInstances, StandaloneDeriving, GeneralizedNewtypeDeriving #-}
2 {-# OPTIONS_GHC -fno-warn-orphans -fno-warn-name-shadowing #-}
3 -----------------------------------------------------------------------------
5 -- Module : Distribution.InstalledPackageInfo.Binary
6 -- Copyright : (c) The University of Glasgow 2009
8 -- Maintainer : cvs-ghc@haskell.org
9 -- Portability : portable
12 module Distribution.InstalledPackageInfo.Binary (
17 import Distribution.Version
18 import Distribution.Package hiding (depends)
19 import Distribution.License
20 import Distribution.InstalledPackageInfo as IPI
21 import Data.Binary as Bin
22 import Control.Exception as Exception
24 readBinPackageDB :: Binary m => FilePath -> IO [InstalledPackageInfo_ m]
26 = do xs <- Bin.decodeFile file
27 _ <- Exception.evaluate $ length xs
30 (\err -> error ("While parsing " ++ show file ++ ": " ++ err))
32 catchUserError :: IO a -> (String -> IO a) -> IO a
34 catchUserError io f = io `Exception.catch` \e -> case e of
35 ErrorCall err -> f err
38 catchUserError io f = io `Exception.catch` \(ErrorCall err) -> f err
41 writeBinPackageDB :: Binary m => FilePath -> [InstalledPackageInfo_ m] -> IO ()
42 writeBinPackageDB file ipis = Bin.encodeFile file ipis
44 instance Binary m => Binary (InstalledPackageInfo_ m) where
45 put = putInstalledPackageInfo
46 get = getInstalledPackageInfo
48 putInstalledPackageInfo :: Binary m => InstalledPackageInfo_ m -> Put
49 putInstalledPackageInfo ipi = do
50 put (sourcePackageId ipi)
51 put (installedPackageId ipi)
62 put (exposedModules ipi)
63 put (hiddenModules ipi)
67 put (extraLibraries ipi)
68 put (extraGHCiLibraries ipi)
75 put (frameworkDirs ipi)
77 put (haddockInterfaces ipi)
78 put (haddockHTMLs ipi)
80 getInstalledPackageInfo :: Binary m => Get (InstalledPackageInfo_ m)
81 getInstalledPackageInfo = do
82 sourcePackageId <- get
83 installedPackageId <- get
100 extraGHCiLibraries <- get
109 haddockInterfaces <- get
111 return InstalledPackageInfo{..}
113 instance Binary PackageIdentifier where
114 put pid = do put (pkgName pid); put (pkgVersion pid)
118 return PackageIdentifier{..}
120 instance Binary License where
121 put (GPL v) = do putWord8 0; put v
122 put (LGPL v) = do putWord8 1; put v
123 put BSD3 = do putWord8 2
124 put BSD4 = do putWord8 3
125 put MIT = do putWord8 4
126 put PublicDomain = do putWord8 5
127 put AllRightsReserved = do putWord8 6
128 put OtherLicense = do putWord8 7
129 put (UnknownLicense str) = do putWord8 8; put str
134 0 -> do v <- get; return (GPL v)
135 1 -> do v <- get; return (LGPL v)
139 5 -> return PublicDomain
140 6 -> return AllRightsReserved
141 7 -> return OtherLicense
142 _ -> do str <- get; return (UnknownLicense str)
144 instance Binary Version where
145 put v = do put (versionBranch v); put (versionTags v)
146 get = do versionBranch <- get; versionTags <- get; return Version{..}
148 deriving instance Binary PackageName
149 deriving instance Binary InstalledPackageId