Skip to content

Commit 734227f

Browse files
committed
Fix hackage-tests roundtrip
1 parent 7b6627f commit 734227f

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

Cabal/Cabal.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ test-suite parser-tests
605605

606606
if impl(ghc >= 7.8)
607607
build-depends:
608-
tree-diff >= 0.0.1 && <0.1
608+
tree-diff >= 0.0.2 && <0.1
609609
other-modules:
610610
Instances.TreeDiff
611611
Instances.TreeDiff.Language
@@ -671,7 +671,7 @@ test-suite hackage-tests
671671

672672
if impl(ghc >= 7.8)
673673
build-depends:
674-
tree-diff >= 0.0.1 && <0.1
674+
tree-diff >= 0.0.2 && <0.1
675675
other-modules:
676676
Instances.TreeDiff
677677
Instances.TreeDiff.Language

Cabal/Distribution/PackageDescription/Parsec.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ import qualified Data.Map.Strict as Map
8080
import qualified Data.Set as Set
8181
import qualified Distribution.Compat.Newtype as Newtype
8282
import qualified Distribution.Types.BuildInfo.Lens as L
83+
import qualified Distribution.Types.Executable.Lens as L
84+
import qualified Distribution.Types.ForeignLib.Lens as L
8385
import qualified Distribution.Types.GenericPackageDescription.Lens as L
8486
import qualified Distribution.Types.PackageDescription.Lens as L
8587
import qualified Text.Parsec as P
@@ -292,7 +294,7 @@ goSections specVer = traverse_ process
292294
| name == "foreign-library" = do
293295
commonStanzas <- use stateCommonStanzas
294296
name' <- parseUnqualComponentName pos args
295-
flib <- lift $ parseCondTree' (foreignLibFieldGrammar name') fromBuildInfo' commonStanzas fields
297+
flib <- lift $ parseCondTree' (foreignLibFieldGrammar name') (fromBuildInfo' name') commonStanzas fields
296298

297299
let hasType ts = foreignLibType ts /= foreignLibType mempty
298300
unless (onAllBranches hasType flib) $ lift $ parseFailure pos $ concat
@@ -309,14 +311,14 @@ goSections specVer = traverse_ process
309311
| name == "executable" = do
310312
commonStanzas <- use stateCommonStanzas
311313
name' <- parseUnqualComponentName pos args
312-
exe <- lift $ parseCondTree' (executableFieldGrammar name') fromBuildInfo' commonStanzas fields
314+
exe <- lift $ parseCondTree' (executableFieldGrammar name') (fromBuildInfo' name') commonStanzas fields
313315
-- TODO check duplicate name here?
314316
stateGpd . L.condExecutables %= snoc (name', exe)
315317

316318
| name == "test-suite" = do
317319
commonStanzas <- use stateCommonStanzas
318320
name' <- parseUnqualComponentName pos args
319-
testStanza <- lift $ parseCondTree' testSuiteFieldGrammar fromBuildInfo' commonStanzas fields
321+
testStanza <- lift $ parseCondTree' testSuiteFieldGrammar (fromBuildInfo' name') commonStanzas fields
320322
testSuite <- lift $ traverse (validateTestSuite pos) testStanza
321323

322324
let hasType ts = testInterface ts /= testInterface mempty
@@ -334,7 +336,7 @@ goSections specVer = traverse_ process
334336
| name == "benchmark" = do
335337
commonStanzas <- use stateCommonStanzas
336338
name' <- parseUnqualComponentName pos args
337-
benchStanza <- lift $ parseCondTree' benchmarkFieldGrammar fromBuildInfo' commonStanzas fields
339+
benchStanza <- lift $ parseCondTree' benchmarkFieldGrammar (fromBuildInfo' name') commonStanzas fields
338340
bench <- lift $ traverse (validateBenchmark pos) benchStanza
339341

340342
let hasType ts = benchmarkInterface ts /= benchmarkInterface mempty
@@ -547,10 +549,13 @@ with new AST, this all need to be rewritten.
547549
type CondTreeBuildInfo = CondTree ConfVar [Dependency] BuildInfo
548550

549551
-- | Create @a@ from 'BuildInfo'.
552+
-- This class is used to implement common stanza parsing.
550553
--
551554
-- Law: @view buildInfo . fromBuildInfo = id@
555+
--
556+
-- This takes name, as 'FieldGrammar's take names too.
552557
class L.HasBuildInfo a => FromBuildInfo a where
553-
fromBuildInfo' :: BuildInfo -> a
558+
fromBuildInfo' :: UnqualComponentName -> BuildInfo -> a
554559

555560
libraryFromBuildInfo :: LibraryName -> BuildInfo -> Library
556561
libraryFromBuildInfo n bi = emptyLibrary
@@ -561,15 +566,15 @@ libraryFromBuildInfo n bi = emptyLibrary
561566
, libBuildInfo = bi
562567
}
563568

564-
instance FromBuildInfo BuildInfo where fromBuildInfo' = id
565-
instance FromBuildInfo ForeignLib where fromBuildInfo' bi = set L.buildInfo bi emptyForeignLib
566-
instance FromBuildInfo Executable where fromBuildInfo' bi = set L.buildInfo bi emptyExecutable
569+
instance FromBuildInfo BuildInfo where fromBuildInfo' _ = id
570+
instance FromBuildInfo ForeignLib where fromBuildInfo' n bi = set L.foreignLibName n $ set L.buildInfo bi emptyForeignLib
571+
instance FromBuildInfo Executable where fromBuildInfo' n bi = set L.exeName n $ set L.buildInfo bi emptyExecutable
567572

568573
instance FromBuildInfo TestSuiteStanza where
569-
fromBuildInfo' = TestSuiteStanza Nothing Nothing Nothing
574+
fromBuildInfo' _ bi = TestSuiteStanza Nothing Nothing Nothing bi
570575

571576
instance FromBuildInfo BenchmarkStanza where
572-
fromBuildInfo' = BenchmarkStanza Nothing Nothing Nothing
577+
fromBuildInfo' _ bi = BenchmarkStanza Nothing Nothing Nothing bi
573578

574579
parseCondTreeWithCommonStanzas
575580
:: forall a. L.HasBuildInfo a

Cabal/tests/HackageTests.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ import qualified Distribution.Types.PackageDescription.Lens as L
7070
import qualified Options.Applicative as O
7171

7272
#ifdef MIN_VERSION_tree_diff
73-
import Data.TreeDiff (ansiWlEditExpr, ediff)
73+
import Data.TreeDiff (ediff)
74+
import Data.TreeDiff.Pretty (ansiWlEditExprCompact)
7475
import Instances.TreeDiff ()
7576
#endif
7677

@@ -238,7 +239,7 @@ roundtripTest testFieldsTransform fpath bs = do
238239
assertEqual' bs' x y = unless (x == y || fpath == "ixset/1.0.4/ixset.cabal") $ do
239240
putStrLn fpath
240241
#ifdef MIN_VERSION_tree_diff
241-
print $ ansiWlEditExpr $ ediff x y
242+
print $ ansiWlEditExprCompact $ ediff x y
242243
#else
243244
putStrLn "<<<<<<"
244245
print x

0 commit comments

Comments
 (0)