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)
65 put (exposedModules ipi)
66 put (hiddenModules ipi)
70 put (extraLibraries ipi)
71 put (extraGHCiLibraries ipi)
78 put (frameworkDirs ipi)
80 put (haddockInterfaces ipi)
81 put (haddockHTMLs ipi)
83 getInstalledPackageInfo :: Binary m => Get (InstalledPackageInfo_ m)
84 getInstalledPackageInfo = do
85 sourcePackageId <- get
86 installedPackageId <- get
102 extraLibraries <- get
103 extraGHCiLibraries <- get
112 haddockInterfaces <- get
114 return InstalledPackageInfo{..}
116 instance Binary PackageIdentifier where
117 put pid = do put (pkgName pid); put (pkgVersion pid)
121 return PackageIdentifier{..}
123 instance Binary License where
124 put (GPL v) = do putWord8 0; put v
125 put (LGPL v) = do putWord8 1; put v
126 put BSD3 = do putWord8 2
127 put BSD4 = do putWord8 3
128 put MIT = do putWord8 4
129 put PublicDomain = do putWord8 5
130 put AllRightsReserved = do putWord8 6
131 put OtherLicense = do putWord8 7
132 put (UnknownLicense str) = do putWord8 8; put str
137 0 -> do v <- get; return (GPL v)
138 1 -> do v <- get; return (LGPL v)
142 5 -> return PublicDomain
143 6 -> return AllRightsReserved
144 7 -> return OtherLicense
145 _ -> do str <- get; return (UnknownLicense str)
147 instance Binary Version where
148 put v = do put (versionBranch v); put (versionTags v)
149 get = do versionBranch <- get; versionTags <- get; return Version{..}
151 deriving instance Binary PackageName
152 deriving instance Binary InstalledPackageId