Skip to content

Commit e3bb1cf

Browse files
committed
Use tree-diff for config roundtrip tests.
1 parent 3d9a490 commit e3bb1cf

File tree

11 files changed

+286
-139
lines changed

11 files changed

+286
-139
lines changed

Cabal/Cabal.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ library
353353
Distribution.Simple.Hpc
354354
Distribution.Simple.Install
355355
Distribution.Simple.InstallDirs
356+
Distribution.Simple.InstallDirs.Internal
356357
Distribution.Simple.LocalBuildInfo
357358
Distribution.Simple.PackageIndex
358359
Distribution.Simple.PreProcess
@@ -457,6 +458,7 @@ library
457458
Distribution.Utils.ShortText
458459
Distribution.Utils.Progress
459460
Distribution.Verbosity
461+
Distribution.Verbosity.Internal
460462
Distribution.Version
461463
Language.Haskell.Extension
462464
Distribution.Compat.Binary

Cabal/Distribution/Simple/InstallDirs.hs

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import Distribution.Pretty
5656
import Distribution.Package
5757
import Distribution.System
5858
import Distribution.Compiler
59+
import Distribution.Simple.InstallDirs.Internal
5960

6061
import System.Directory (getAppUserDataDirectory)
6162
import System.FilePath
@@ -355,41 +356,6 @@ newtype PathTemplate = PathTemplate [PathComponent]
355356

356357
instance Binary PathTemplate
357358

358-
data PathComponent =
359-
Ordinary FilePath
360-
| Variable PathTemplateVariable
361-
deriving (Eq, Ord, Generic)
362-
363-
instance Binary PathComponent
364-
365-
data PathTemplateVariable =
366-
PrefixVar -- ^ The @$prefix@ path variable
367-
| BindirVar -- ^ The @$bindir@ path variable
368-
| LibdirVar -- ^ The @$libdir@ path variable
369-
| LibsubdirVar -- ^ The @$libsubdir@ path variable
370-
| DynlibdirVar -- ^ The @$dynlibdir@ path variable
371-
| DatadirVar -- ^ The @$datadir@ path variable
372-
| DatasubdirVar -- ^ The @$datasubdir@ path variable
373-
| DocdirVar -- ^ The @$docdir@ path variable
374-
| HtmldirVar -- ^ The @$htmldir@ path variable
375-
| PkgNameVar -- ^ The @$pkg@ package name path variable
376-
| PkgVerVar -- ^ The @$version@ package version path variable
377-
| PkgIdVar -- ^ The @$pkgid@ package Id path variable, eg @foo-1.0@
378-
| LibNameVar -- ^ The @$libname@ path variable
379-
| CompilerVar -- ^ The compiler name and version, eg @ghc-6.6.1@
380-
| OSVar -- ^ The operating system name, eg @windows@ or @linux@
381-
| ArchVar -- ^ The CPU architecture name, eg @i386@ or @x86_64@
382-
| AbiVar -- ^ The Compiler's ABI identifier, $arch-$os-$compiler-$abitag
383-
| AbiTagVar -- ^ The optional ABI tag for the compiler
384-
| ExecutableNameVar -- ^ The executable name; used in shell wrappers
385-
| TestSuiteNameVar -- ^ The name of the test suite being run
386-
| TestSuiteResultVar -- ^ The result of the test suite being run, eg
387-
-- @pass@, @fail@, or @error@.
388-
| BenchmarkNameVar -- ^ The name of the benchmark being run
389-
deriving (Eq, Ord, Generic)
390-
391-
instance Binary PathTemplateVariable
392-
393359
type PathTemplateEnv = [(PathTemplateVariable, PathTemplate)]
394360

395361
-- | Convert a 'FilePath' to a 'PathTemplate' including any template vars.
@@ -485,86 +451,6 @@ installDirsTemplateEnv dirs =
485451
-- spans which are either strings or variables, eg:
486452
-- PathTemplate [Variable PrefixVar, Ordinary "/bin" ]
487453

488-
instance Show PathTemplateVariable where
489-
show PrefixVar = "prefix"
490-
show LibNameVar = "libname"
491-
show BindirVar = "bindir"
492-
show LibdirVar = "libdir"
493-
show LibsubdirVar = "libsubdir"
494-
show DynlibdirVar = "dynlibdir"
495-
show DatadirVar = "datadir"
496-
show DatasubdirVar = "datasubdir"
497-
show DocdirVar = "docdir"
498-
show HtmldirVar = "htmldir"
499-
show PkgNameVar = "pkg"
500-
show PkgVerVar = "version"
501-
show PkgIdVar = "pkgid"
502-
show CompilerVar = "compiler"
503-
show OSVar = "os"
504-
show ArchVar = "arch"
505-
show AbiTagVar = "abitag"
506-
show AbiVar = "abi"
507-
show ExecutableNameVar = "executablename"
508-
show TestSuiteNameVar = "test-suite"
509-
show TestSuiteResultVar = "result"
510-
show BenchmarkNameVar = "benchmark"
511-
512-
instance Read PathTemplateVariable where
513-
readsPrec _ s =
514-
take 1
515-
[ (var, drop (length varStr) s)
516-
| (varStr, var) <- vars
517-
, varStr `isPrefixOf` s ]
518-
-- NB: order matters! Longer strings first
519-
where vars = [("prefix", PrefixVar)
520-
,("bindir", BindirVar)
521-
,("libdir", LibdirVar)
522-
,("libsubdir", LibsubdirVar)
523-
,("dynlibdir", DynlibdirVar)
524-
,("datadir", DatadirVar)
525-
,("datasubdir", DatasubdirVar)
526-
,("docdir", DocdirVar)
527-
,("htmldir", HtmldirVar)
528-
,("pkgid", PkgIdVar)
529-
,("libname", LibNameVar)
530-
,("pkgkey", LibNameVar) -- backwards compatibility
531-
,("pkg", PkgNameVar)
532-
,("version", PkgVerVar)
533-
,("compiler", CompilerVar)
534-
,("os", OSVar)
535-
,("arch", ArchVar)
536-
,("abitag", AbiTagVar)
537-
,("abi", AbiVar)
538-
,("executablename", ExecutableNameVar)
539-
,("test-suite", TestSuiteNameVar)
540-
,("result", TestSuiteResultVar)
541-
,("benchmark", BenchmarkNameVar)]
542-
543-
instance Show PathComponent where
544-
show (Ordinary path) = path
545-
show (Variable var) = '$':show var
546-
showList = foldr (\x -> (shows x .)) id
547-
548-
instance Read PathComponent where
549-
-- for some reason we collapse multiple $ symbols here
550-
readsPrec _ = lex0
551-
where lex0 [] = []
552-
lex0 ('$':'$':s') = lex0 ('$':s')
553-
lex0 ('$':s') = case [ (Variable var, s'')
554-
| (var, s'') <- reads s' ] of
555-
[] -> lex1 "$" s'
556-
ok -> ok
557-
lex0 s' = lex1 [] s'
558-
lex1 "" "" = []
559-
lex1 acc "" = [(Ordinary (reverse acc), "")]
560-
lex1 acc ('$':'$':s) = lex1 acc ('$':s)
561-
lex1 acc ('$':s) = [(Ordinary (reverse acc), '$':s)]
562-
lex1 acc (c:s) = lex1 (c:acc) s
563-
readList [] = [([],"")]
564-
readList s = [ (component:components, s'')
565-
| (component, s') <- reads s
566-
, (components, s'') <- readList s' ]
567-
568454
instance Show PathTemplate where
569455
show (PathTemplate template) = show (show template)
570456

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{-# LANGUAGE DeriveGeneric #-}
2+
module Distribution.Simple.InstallDirs.Internal
3+
( PathComponent(..)
4+
, PathTemplateVariable(..)
5+
) where
6+
7+
import Prelude ()
8+
import Distribution.Compat.Prelude
9+
10+
data PathComponent =
11+
Ordinary FilePath
12+
| Variable PathTemplateVariable
13+
deriving (Eq, Ord, Generic)
14+
15+
instance Binary PathComponent
16+
17+
data PathTemplateVariable =
18+
PrefixVar -- ^ The @$prefix@ path variable
19+
| BindirVar -- ^ The @$bindir@ path variable
20+
| LibdirVar -- ^ The @$libdir@ path variable
21+
| LibsubdirVar -- ^ The @$libsubdir@ path variable
22+
| DynlibdirVar -- ^ The @$dynlibdir@ path variable
23+
| DatadirVar -- ^ The @$datadir@ path variable
24+
| DatasubdirVar -- ^ The @$datasubdir@ path variable
25+
| DocdirVar -- ^ The @$docdir@ path variable
26+
| HtmldirVar -- ^ The @$htmldir@ path variable
27+
| PkgNameVar -- ^ The @$pkg@ package name path variable
28+
| PkgVerVar -- ^ The @$version@ package version path variable
29+
| PkgIdVar -- ^ The @$pkgid@ package Id path variable, eg @foo-1.0@
30+
| LibNameVar -- ^ The @$libname@ path variable
31+
| CompilerVar -- ^ The compiler name and version, eg @ghc-6.6.1@
32+
| OSVar -- ^ The operating system name, eg @windows@ or @linux@
33+
| ArchVar -- ^ The CPU architecture name, eg @i386@ or @x86_64@
34+
| AbiVar -- ^ The compiler's ABI identifier,
35+
--- $arch-$os-$compiler-$abitag
36+
| AbiTagVar -- ^ The optional ABI tag for the compiler
37+
| ExecutableNameVar -- ^ The executable name; used in shell wrappers
38+
| TestSuiteNameVar -- ^ The name of the test suite being run
39+
| TestSuiteResultVar -- ^ The result of the test suite being run, eg
40+
-- @pass@, @fail@, or @error@.
41+
| BenchmarkNameVar -- ^ The name of the benchmark being run
42+
deriving (Eq, Ord, Generic)
43+
44+
instance Binary PathTemplateVariable
45+
46+
instance Show PathTemplateVariable where
47+
show PrefixVar = "prefix"
48+
show LibNameVar = "libname"
49+
show BindirVar = "bindir"
50+
show LibdirVar = "libdir"
51+
show LibsubdirVar = "libsubdir"
52+
show DynlibdirVar = "dynlibdir"
53+
show DatadirVar = "datadir"
54+
show DatasubdirVar = "datasubdir"
55+
show DocdirVar = "docdir"
56+
show HtmldirVar = "htmldir"
57+
show PkgNameVar = "pkg"
58+
show PkgVerVar = "version"
59+
show PkgIdVar = "pkgid"
60+
show CompilerVar = "compiler"
61+
show OSVar = "os"
62+
show ArchVar = "arch"
63+
show AbiTagVar = "abitag"
64+
show AbiVar = "abi"
65+
show ExecutableNameVar = "executablename"
66+
show TestSuiteNameVar = "test-suite"
67+
show TestSuiteResultVar = "result"
68+
show BenchmarkNameVar = "benchmark"
69+
70+
instance Read PathTemplateVariable where
71+
readsPrec _ s =
72+
take 1
73+
[ (var, drop (length varStr) s)
74+
| (varStr, var) <- vars
75+
, varStr `isPrefixOf` s ]
76+
-- NB: order matters! Longer strings first
77+
where vars = [("prefix", PrefixVar)
78+
,("bindir", BindirVar)
79+
,("libdir", LibdirVar)
80+
,("libsubdir", LibsubdirVar)
81+
,("dynlibdir", DynlibdirVar)
82+
,("datadir", DatadirVar)
83+
,("datasubdir", DatasubdirVar)
84+
,("docdir", DocdirVar)
85+
,("htmldir", HtmldirVar)
86+
,("pkgid", PkgIdVar)
87+
,("libname", LibNameVar)
88+
,("pkgkey", LibNameVar) -- backwards compatibility
89+
,("pkg", PkgNameVar)
90+
,("version", PkgVerVar)
91+
,("compiler", CompilerVar)
92+
,("os", OSVar)
93+
,("arch", ArchVar)
94+
,("abitag", AbiTagVar)
95+
,("abi", AbiVar)
96+
,("executablename", ExecutableNameVar)
97+
,("test-suite", TestSuiteNameVar)
98+
,("result", TestSuiteResultVar)
99+
,("benchmark", BenchmarkNameVar)]
100+
101+
instance Show PathComponent where
102+
show (Ordinary path) = path
103+
show (Variable var) = '$':show var
104+
showList = foldr (\x -> (shows x .)) id
105+
106+
instance Read PathComponent where
107+
-- for some reason we collapse multiple $ symbols here
108+
readsPrec _ = lex0
109+
where lex0 [] = []
110+
lex0 ('$':'$':s') = lex0 ('$':s')
111+
lex0 ('$':s') = case [ (Variable var, s'')
112+
| (var, s'') <- reads s' ] of
113+
[] -> lex1 "$" s'
114+
ok -> ok
115+
lex0 s' = lex1 [] s'
116+
lex1 "" "" = []
117+
lex1 acc "" = [(Ordinary (reverse acc), "")]
118+
lex1 acc ('$':'$':s) = lex1 acc ('$':s)
119+
lex1 acc ('$':s) = [(Ordinary (reverse acc), '$':s)]
120+
lex1 acc (c:s) = lex1 (c:acc) s
121+
readList [] = [([],"")]
122+
readList s = [ (component:components, s'')
123+
| (component, s') <- reads s
124+
, (components, s'') <- readList s' ]

Cabal/Distribution/Utils/NubList.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
2+
{-# LANGUAGE DeriveGeneric #-}
23
module Distribution.Utils.NubList
34
( NubList -- opaque
45
, toNubList -- smart construtor
@@ -21,7 +22,7 @@ import qualified Text.Read as R
2122
-- | NubList : A de-duplicated list that maintains the original order.
2223
newtype NubList a =
2324
NubList { fromNubList :: [a] }
24-
deriving (Eq, Typeable)
25+
deriving (Eq, Generic, Typeable)
2526

2627
-- NubList assumes that nub retains the list order while removing duplicate
2728
-- elements (keeping the first occurence). Documentation for "Data.List.nub"

Cabal/Distribution/Verbosity.hs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import Distribution.ReadE
5757
import Data.List (elemIndex)
5858
import Data.Set (Set)
5959
import Distribution.Parsec
60+
import Distribution.Verbosity.Internal
6061

6162
import qualified Data.Set as Set
6263
import qualified Distribution.Compat.CharParsing as P
@@ -86,11 +87,6 @@ instance Bounded Verbosity where
8687

8788
instance Binary Verbosity
8889

89-
data VerbosityLevel = Silent | Normal | Verbose | Deafening
90-
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)
91-
92-
instance Binary VerbosityLevel
93-
9490
-- We shouldn't print /anything/ unless an error occurs in silent mode
9591
silent :: Verbosity
9692
silent = mkVerbosity Silent
@@ -221,16 +217,6 @@ showForGHC v = maybe (error "unknown verbosity") show $
221217
elemIndex v [silent,normal,__,verbose,deafening]
222218
where __ = silent -- this will be always ignored by elemIndex
223219

224-
data VerbosityFlag
225-
= VCallStack
226-
| VCallSite
227-
| VNoWrap
228-
| VMarkOutput
229-
| VTimestamp
230-
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)
231-
232-
instance Binary VerbosityFlag
233-
234220
-- | Turn on verbose call-site printing when we log.
235221
verboseCallSite :: Verbosity -> Verbosity
236222
verboseCallSite = verboseFlag VCallSite
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{-# LANGUAGE DeriveGeneric #-}
2+
module Distribution.Verbosity.Internal
3+
( VerbosityLevel(..)
4+
, VerbosityFlag(..)
5+
) where
6+
7+
import Prelude ()
8+
import Distribution.Compat.Prelude
9+
10+
data VerbosityLevel = Silent | Normal | Verbose | Deafening
11+
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)
12+
13+
instance Binary VerbosityLevel
14+
15+
data VerbosityFlag
16+
= VCallStack
17+
| VCallSite
18+
| VNoWrap
19+
| VMarkOutput
20+
| VTimestamp
21+
deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)
22+
23+
instance Binary VerbosityFlag

cabal-install/Distribution/Client/IndexUtils/Timestamp.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import GHC.Generics (Generic)
3939

4040
-- | UNIX timestamp (expressed in seconds since unix epoch, i.e. 1970).
4141
newtype Timestamp = TS Int64 -- Tar.EpochTime
42-
deriving (Eq,Ord,Enum,NFData,Show)
42+
deriving (Eq,Ord,Enum,NFData,Show,Generic)
4343

4444
epochTimeToTimestamp :: Tar.EpochTime -> Maybe Timestamp
4545
epochTimeToTimestamp et

0 commit comments

Comments
 (0)