Skip to content

Commit 430e852

Browse files
committed
Merge pull request #2076 from ttuegel/binary-lbi
Use Binary to save/restore persistent build config
2 parents 468ca1d + 95b969a commit 430e852

21 files changed

+362
-122
lines changed

Cabal/Cabal.cabal

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ source-repository head
128128
library
129129
build-depends:
130130
base >= 4.2 && < 5,
131+
binary >= 0.7 && < 0.8,
131132
deepseq >= 1.3 && < 1.4,
132133
filepath >= 1 && < 1.4,
133134
directory >= 1 && < 1.3,
@@ -138,6 +139,10 @@ library
138139
pretty >= 1 && < 1.2,
139140
bytestring >= 0.9
140141

142+
-- Needed for GHC.Generics before GHC 7.6
143+
if impl(ghc < 7.6)
144+
build-depends: ghc-prim >= 0.2 && < 0.3
145+
141146
if !os(windows)
142147
build-depends:
143148
unix >= 2.0 && < 2.8
@@ -284,6 +289,7 @@ test-suite package-tests
284289
hs-source-dirs: tests
285290
build-depends:
286291
base,
292+
binary >= 0.7 && < 0.8,
287293
test-framework,
288294
test-framework-quickcheck2 >= 0.2.12,
289295
test-framework-hunit,

Cabal/Distribution/Compiler.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
24
-----------------------------------------------------------------------------
35
-- |
46
-- Module : Distribution.Compiler
@@ -35,10 +37,12 @@ module Distribution.Compiler (
3537
CompilerId(..),
3638
) where
3739

40+
import Data.Binary (Binary)
3841
import Data.Data (Data)
3942
import Data.Typeable (Typeable)
4043
import Data.Maybe (fromMaybe)
4144
import Distribution.Version (Version(..))
45+
import GHC.Generics (Generic)
4246

4347
import qualified System.Info (compilerName, compilerVersion)
4448
import Distribution.Text (Text(..), display)
@@ -52,7 +56,9 @@ import Control.Monad (when)
5256
data CompilerFlavor = GHC | NHC | YHC | Hugs | HBC | Helium | JHC | LHC | UHC
5357
| HaskellSuite String -- string is the id of the actual compiler
5458
| OtherCompiler String
55-
deriving (Show, Read, Eq, Ord, Typeable, Data)
59+
deriving (Generic, Show, Read, Eq, Ord, Typeable, Data)
60+
61+
instance Binary CompilerFlavor
5662

5763
knownCompilerFlavors :: [CompilerFlavor]
5864
knownCompilerFlavors = [GHC, NHC, YHC, Hugs, HBC, Helium, JHC, LHC, UHC]
@@ -125,7 +131,9 @@ defaultCompilerFlavor = case buildCompilerFlavor of
125131
-- ------------------------------------------------------------
126132

127133
data CompilerId = CompilerId CompilerFlavor Version
128-
deriving (Eq, Ord, Read, Show)
134+
deriving (Eq, Generic, Ord, Read, Show)
135+
136+
instance Binary CompilerId
129137

130138
instance Text CompilerId where
131139
disp (CompilerId f (Version [] _)) = disp f

Cabal/Distribution/InstalledPackageInfo.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE DeriveGeneric #-}
2+
13
-----------------------------------------------------------------------------
24
-- |
35
-- Module : Distribution.InstalledPackageInfo
@@ -89,6 +91,9 @@ import Distribution.Text
8991
import Text.PrettyPrint as Disp
9092
import qualified Distribution.Compat.ReadP as Parse
9193

94+
import Data.Binary (Binary)
95+
import GHC.Generics (Generic)
96+
9297
-- -----------------------------------------------------------------------------
9398
-- The InstalledPackageInfo type
9499

@@ -131,7 +136,9 @@ data InstalledPackageInfo_ m
131136
haddockInterfaces :: [FilePath],
132137
haddockHTMLs :: [FilePath]
133138
}
134-
deriving (Read, Show)
139+
deriving (Generic, Read, Show)
140+
141+
instance Binary m => Binary (InstalledPackageInfo_ m)
135142

136143
instance Package.Package (InstalledPackageInfo_ str) where
137144
packageId = sourcePackageId
@@ -192,7 +199,9 @@ data ModuleReexport = ModuleReexport {
192199
moduleReexportDefiningName :: ModuleName,
193200
moduleReexportName :: ModuleName
194201
}
195-
deriving (Read, Show)
202+
deriving (Generic, Read, Show)
203+
204+
instance Binary ModuleReexport
196205

197206
instance Text ModuleReexport where
198207
disp (ModuleReexport pkgid origname newname) =

Cabal/Distribution/License.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
24
-----------------------------------------------------------------------------
35
-- |
46
-- Module : Distribution.License
@@ -51,9 +53,11 @@ import Distribution.Text (Text(..), display)
5153
import qualified Distribution.Compat.ReadP as Parse
5254
import qualified Text.PrettyPrint as Disp
5355
import Text.PrettyPrint ((<>))
56+
import Data.Binary (Binary)
5457
import qualified Data.Char as Char (isAlphaNum)
5558
import Data.Data (Data)
5659
import Data.Typeable (Typeable)
60+
import GHC.Generics (Generic)
5761

5862
-- | Indicates the license under which a package's source code is released.
5963
-- Versions of the licenses not listed here will be rejected by Hackage and
@@ -110,7 +114,9 @@ data License =
110114

111115
-- | Indicates an erroneous license name.
112116
| UnknownLicense String
113-
deriving (Read, Show, Eq, Typeable, Data)
117+
deriving (Generic, Read, Show, Eq, Typeable, Data)
118+
119+
instance Binary License
114120

115121
-- | The list of all currently recognised licenses.
116122
knownLicenses :: [License]

Cabal/Distribution/ModuleName.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
24
-----------------------------------------------------------------------------
35
-- |
46
-- Module : Distribution.ModuleName
@@ -22,21 +24,25 @@ module Distribution.ModuleName (
2224
import Distribution.Text
2325
( Text(..) )
2426

27+
import Data.Binary (Binary)
28+
import qualified Data.Char as Char
29+
( isAlphaNum, isUpper )
2530
import Data.Data (Data)
2631
import Data.Typeable (Typeable)
2732
import qualified Distribution.Compat.ReadP as Parse
2833
import qualified Text.PrettyPrint as Disp
29-
import qualified Data.Char as Char
30-
( isAlphaNum, isUpper )
31-
import System.FilePath
32-
( pathSeparator )
3334
import Data.List
3435
( intercalate, intersperse )
36+
import GHC.Generics (Generic)
37+
import System.FilePath
38+
( pathSeparator )
3539

3640
-- | A valid Haskell module name.
3741
--
3842
newtype ModuleName = ModuleName [String]
39-
deriving (Eq, Ord, Read, Show, Typeable, Data)
43+
deriving (Eq, Generic, Ord, Read, Show, Typeable, Data)
44+
45+
instance Binary ModuleName
4046

4147
instance Text ModuleName where
4248
disp (ModuleName ms) =

Cabal/Distribution/Package.hs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
3+
24
-----------------------------------------------------------------------------
35
-- |
46
-- Module : Distribution.Package
@@ -46,19 +48,24 @@ import Distribution.Text (Text(..))
4648
import qualified Distribution.Compat.ReadP as Parse
4749
import Distribution.Compat.ReadP ((<++))
4850
import qualified Text.PrettyPrint as Disp
49-
import Text.PrettyPrint ((<>), (<+>), text)
51+
5052
import Control.DeepSeq (NFData(..))
53+
import Data.Binary (Binary)
5154
import qualified Data.Char as Char
5255
( isDigit, isAlphaNum, isUpper, isLower, ord, chr )
53-
import Data.List ( intercalate, sort, foldl' )
5456
import Data.Data ( Data )
57+
import Data.List ( intercalate, sort, foldl' )
5558
import Data.Typeable ( Typeable )
56-
import GHC.Fingerprint ( Fingerprint(..), fingerprintString )
5759
import Data.Word ( Word64 )
60+
import GHC.Fingerprint ( Fingerprint(..), fingerprintString )
61+
import GHC.Generics (Generic)
5862
import Numeric ( showIntAtBase )
63+
import Text.PrettyPrint ((<>), (<+>), text)
5964

6065
newtype PackageName = PackageName { unPackageName :: String }
61-
deriving (Read, Show, Eq, Ord, Typeable, Data)
66+
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
67+
68+
instance Binary PackageName
6269

6370
instance Text PackageName where
6471
disp (PackageName n) = Disp.text n
@@ -84,7 +91,9 @@ data PackageIdentifier
8491
pkgName :: PackageName, -- ^The name of this package, eg. foo
8592
pkgVersion :: Version -- ^the version of this package, eg 1.2
8693
}
87-
deriving (Read, Show, Eq, Ord, Typeable, Data)
94+
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
95+
96+
instance Binary PackageIdentifier
8897

8998
instance Text PackageIdentifier where
9099
disp (PackageIdentifier n v) = case v of
@@ -108,7 +117,9 @@ instance NFData PackageIdentifier where
108117
-- in a package database, or overlay of databases.
109118
--
110119
newtype InstalledPackageId = InstalledPackageId String
111-
deriving (Read,Show,Eq,Ord,Typeable,Data)
120+
deriving (Generic, Read,Show,Eq,Ord,Typeable,Data)
121+
122+
instance Binary InstalledPackageId
112123

113124
instance Text InstalledPackageId where
114125
disp (InstalledPackageId str) = text str
@@ -137,7 +148,9 @@ data PackageKey
137148
-- old versions of GHC assume that the 'sourcePackageId' recorded for an
138149
-- installed package coincides with the package key it was compiled with.
139150
| OldPackageKey !PackageId
140-
deriving (Read, Show, Eq, Ord, Typeable, Data)
151+
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
152+
153+
instance Binary PackageKey
141154

142155
-- | Convenience function which converts a fingerprint into a new-style package
143156
-- key.
@@ -231,7 +244,9 @@ instance NFData PackageKey where
231244
-- | Describes a dependency on a source package (API)
232245
--
233246
data Dependency = Dependency PackageName VersionRange
234-
deriving (Read, Show, Eq, Typeable, Data)
247+
deriving (Generic, Read, Show, Eq, Typeable, Data)
248+
249+
instance Binary Dependency
235250

236251
instance Text Dependency where
237252
disp (Dependency name ver) =

0 commit comments

Comments
 (0)