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