1 {-# LANGUAGE RecordWildCards, TypeSynonymInstances, StandaloneDeriving, GeneralizedNewtypeDeriving #-}
2 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
3 -- This module deliberately defines orphan instances for now. Should
4 -- become unnecessary once we move to using the binary package properly:
5 {-# OPTIONS_GHC -fno-warn-orphans #-}
6 -----------------------------------------------------------------------------
8 -- Module : Distribution.InstalledPackageInfo.Binary
9 -- Copyright : (c) The University of Glasgow 2009
11 -- Maintainer : cvs-ghc@haskell.org
12 -- Portability : portable
15 module Distribution.InstalledPackageInfo.Binary (
20 import Distribution.Version
21 import Distribution.Package hiding (depends)
22 import Distribution.License
23 import Distribution.InstalledPackageInfo as IPI
24 import Data.Binary as Bin
25 import Control.Exception as Exception
27 readBinPackageDB :: Binary m => FilePath -> IO [InstalledPackageInfo_ m]
29 = do xs <- Bin.decodeFile file
30 _ <- Exception.evaluate $ length xs
33 (\err -> error ("While parsing " ++ show file ++ ": " ++ err))
35 catchUserError :: IO a -> (String -> IO a) -> IO a
37 catchUserError io f = io `Exception.catch` \e -> case e of
38 ErrorCall err -> f err
41 catchUserError io f = io `Exception.catch` \(ErrorCall err) -> f err
44 writeBinPackageDB :: Binary m => FilePath -> [InstalledPackageInfo_ m] -> IO ()
45 writeBinPackageDB file ipis = Bin.encodeFile file ipis
47 instance Binary m => Binary (InstalledPackageInfo_ m) where
48 put = putInstalledPackageInfo
49 get = getInstalledPackageInfo
51 putInstalledPackageInfo :: Binary m => InstalledPackageInfo_ m -> Put
52 putInstalledPackageInfo ipi = do
53 put (sourcePackageId ipi)
54 put (installedPackageId ipi)
66 put (exposedModules ipi)
67 put (hiddenModules ipi)
71 put (extraLibraries ipi)
72 put (extraGHCiLibraries ipi)
79 put (frameworkDirs ipi)
81 put (haddockInterfaces ipi)
82 put (haddockHTMLs ipi)
84 getInstalledPackageInfo :: Binary m => Get (InstalledPackageInfo_ m)
85 getInstalledPackageInfo = do
86 sourcePackageId <- get
87 installedPackageId <- get
104 extraLibraries <- get
105 extraGHCiLibraries <- get
114 haddockInterfaces <- get
116 return InstalledPackageInfo{..}
118 instance Binary PackageIdentifier where
119 put pid = do put (pkgName pid); put (pkgVersion pid)
123 return PackageIdentifier{..}
125 instance Binary License where
126 put (GPL v) = do putWord8 0; put v
127 put (LGPL v) = do putWord8 1; put v
128 put BSD3 = do putWord8 2
129 put BSD4 = do putWord8 3
130 put MIT = do putWord8 4
131 put PublicDomain = do putWord8 5
132 put AllRightsReserved = do putWord8 6
133 put OtherLicense = do putWord8 7
134 put (UnknownLicense str) = do putWord8 8; put str
139 0 -> do v <- get; return (GPL v)
140 1 -> do v <- get; return (LGPL v)
144 5 -> return PublicDomain
145 6 -> return AllRightsReserved
146 7 -> return OtherLicense
147 _ -> do str <- get; return (UnknownLicense str)
149 instance Binary Version where
150 put v = do put (versionBranch v); put (versionTags v)
151 get = do versionBranch <- get; versionTags <- get; return Version{..}
153 deriving instance Binary PackageName
154 deriving instance Binary InstalledPackageId