Change the representation of the package database
[ghc-hetmet.git] / libraries / bin-package-db / Distribution / InstalledPackageInfo / Binary.hs
1 {-# LANGUAGE RecordWildCards, TypeSynonymInstances, StandaloneDeriving, GeneralizedNewtypeDeriving #-}
2 -----------------------------------------------------------------------------
3 -- |
4 -- Module      :  Distribution.InstalledPackageInfo.Binary
5 -- Copyright   :  (c) The University of Glasgow 2009
6 --
7 -- Maintainer  :  cvs-ghc@haskell.org
8 -- Portability :  portable
9 --
10
11 module Distribution.InstalledPackageInfo.Binary (
12        readBinPackageDB,
13        writeBinPackageDB
14   ) where
15
16 import Distribution.Version
17 import Distribution.Package
18 import Distribution.License
19 import Distribution.InstalledPackageInfo as IPI
20 import Data.Binary as Bin
21
22 readBinPackageDB :: Binary m => FilePath -> IO [InstalledPackageInfo_ m]
23 readBinPackageDB file = Bin.decodeFile file
24
25 writeBinPackageDB :: Binary m => FilePath -> [InstalledPackageInfo_ m] -> IO ()
26 writeBinPackageDB file ipis = Bin.encodeFile file ipis
27
28 instance Binary m => Binary (InstalledPackageInfo_ m) where
29   put = putInstalledPackageInfo
30   get = getInstalledPackageInfo
31
32 putInstalledPackageInfo :: Binary m => InstalledPackageInfo_ m -> Put
33 putInstalledPackageInfo ipi = do
34   put (sourcePackageId ipi)
35   put (installedPackageId ipi)
36   put (license ipi)
37   put (copyright ipi)
38   put (maintainer ipi)
39   put (author ipi)
40   put (stability ipi)
41   put (homepage ipi)
42   put (pkgUrl ipi)
43   put (description ipi)
44   put (category ipi)
45   put (exposed ipi)
46   put (exposedModules ipi)
47   put (hiddenModules ipi)
48   put (importDirs ipi)
49   put (libraryDirs ipi)
50   put (hsLibraries ipi)
51   put (extraLibraries ipi)
52   put (extraGHCiLibraries ipi)
53   put (includeDirs ipi)
54   put (includes ipi)
55   put (IPI.depends ipi)
56   put (hugsOptions ipi)
57   put (ccOptions ipi)
58   put (ldOptions ipi)
59   put (frameworkDirs ipi)
60   put (frameworks ipi)
61   put (haddockInterfaces ipi)
62   put (haddockHTMLs ipi)
63
64 getInstalledPackageInfo :: Binary m => Get (InstalledPackageInfo_ m)
65 getInstalledPackageInfo = do
66   sourcePackageId <- get
67   installedPackageId <- get
68   license <- get
69   copyright <- get
70   maintainer <- get
71   author <- get
72   stability <- get
73   homepage <- get
74   pkgUrl <- get
75   description <- get
76   category <- get
77   exposed <- get
78   exposedModules <- get
79   hiddenModules <- get
80   importDirs <- get
81   libraryDirs <- get
82   hsLibraries <- get
83   extraLibraries <- get
84   extraGHCiLibraries <- get
85   includeDirs <- get
86   includes <- get
87   depends <- get
88   hugsOptions <- get
89   ccOptions <- get
90   ldOptions <- get
91   frameworkDirs <- get
92   frameworks <- get
93   haddockInterfaces <- get
94   haddockHTMLs <- get
95   return InstalledPackageInfo{..}
96
97 instance Binary PackageIdentifier where
98   put pid = do put (pkgName pid); put (pkgVersion pid)
99   get = do 
100     pkgName <- get
101     pkgVersion <- get
102     return PackageIdentifier{..}
103
104 instance Binary License where
105   put (GPL v)              = do putWord8 0; put v
106   put (LGPL v)             = do putWord8 1; put v
107   put BSD3                 = do putWord8 2
108   put BSD4                 = do putWord8 3
109   put MIT                  = do putWord8 4
110   put PublicDomain         = do putWord8 5
111   put AllRightsReserved    = do putWord8 6
112   put OtherLicense         = do putWord8 7
113   put (UnknownLicense str) = do putWord8 8; put str
114
115   get = do
116     n <- getWord8
117     case n of
118       0 -> do v <- get; return (GPL v)
119       1 -> do v <- get; return (LGPL v)
120       2 -> return BSD3
121       3 -> return BSD4
122       4 -> return MIT
123       5 -> return PublicDomain
124       6 -> return AllRightsReserved
125       7 -> return OtherLicense
126       8 -> do str <- get; return (UnknownLicense str)
127
128 instance Binary Version where
129   put v = do put (versionBranch v); put (versionTags v)
130   get = do versionBranch <- get; versionTags <- get; return Version{..}
131
132 deriving instance Binary PackageName
133 deriving instance Binary InstalledPackageId