1
+ {-# LANGUAGE CPP #-}
1
2
{-# LANGUAGE DeriveGeneric #-}
2
3
{-# LANGUAGE RecordWildCards #-}
3
4
{-# LANGUAGE BangPatterns #-}
@@ -51,30 +52,39 @@ import Distribution.Package
51
52
, Package (.. ), packageVersion , packageName )
52
53
import Distribution.Types.Dependency
53
54
import Distribution.Simple.PackageIndex (InstalledPackageIndex )
54
- import qualified Distribution.PackageDescription.Parse as PackageDesc.Parse
55
55
import Distribution.PackageDescription
56
56
( GenericPackageDescription )
57
- import Distribution.PackageDescription.Parse
58
- ( parsePackageDescription )
59
57
import Distribution.Simple.Compiler
60
58
( Compiler , PackageDBStack )
61
59
import Distribution.Simple.Program
62
60
( ProgramDb )
63
61
import qualified Distribution.Simple.Configure as Configure
64
62
( getInstalledPackages , getInstalledPackagesMonitorFiles )
65
- import Distribution.ParseUtils
66
- ( ParseResult (.. ) )
67
63
import Distribution.Version
68
64
( mkVersion , intersectVersionRanges )
69
65
import Distribution.Text
70
66
( display , simpleParse )
71
67
import Distribution.Verbosity
72
68
( Verbosity , normal , lessVerbose )
73
69
import Distribution.Simple.Utils
74
- ( die , warn , info , fromUTF8 , ignoreBOM )
70
+ ( die , warn , info )
75
71
import Distribution.Client.Setup
76
72
( RepoContext (.. ) )
77
73
74
+ #ifdef CABAL_PARSEC
75
+ import Distribution.PackageDescription.Parsec
76
+ ( parseGenericPackageDescriptionMaybe )
77
+ import qualified Distribution.PackageDescription.Parsec as PackageDesc.Parse
78
+ #else
79
+ import Distribution.ParseUtils
80
+ ( ParseResult (.. ) )
81
+ import Distribution.PackageDescription.Parse
82
+ ( parseGenericPackageDescription )
83
+ import Distribution.Simple.Utils
84
+ ( fromUTF8 , ignoreBOM )
85
+ import qualified Distribution.PackageDescription.Parse as PackageDesc.Parse
86
+ #endif
87
+
78
88
import Distribution.Solver.Types.PackageIndex (PackageIndex )
79
89
import qualified Distribution.Solver.Types.PackageIndex as PackageIndex
80
90
import Distribution.Solver.Types.SourcePackage
@@ -434,12 +444,20 @@ extractPkg entry blockNo = case Tar.entryContent entry of
434
444
Just ver -> Just . return $ Just (NormalPackage pkgid descr content blockNo)
435
445
where
436
446
pkgid = PackageIdentifier (mkPackageName pkgname) ver
437
- parsed = parsePackageDescription . ignoreBOM . fromUTF8 . BS.Char8. unpack
447
+ #ifdef CABAL_PARSEC
448
+ parsed = parseGenericPackageDescriptionMaybe (BS. toStrict content)
449
+ descr = case parsed of
450
+ Just d -> d
451
+ Nothing -> error $ " Couldn't read cabal file "
452
+ ++ show fileName
453
+ #else
454
+ parsed = parseGenericPackageDescription . ignoreBOM . fromUTF8 . BS.Char8. unpack
438
455
$ content
439
456
descr = case parsed of
440
457
ParseOk _ d -> d
441
458
_ -> error $ " Couldn't read cabal file "
442
459
++ show fileName
460
+ #endif
443
461
_ -> Nothing
444
462
_ -> Nothing
445
463
@@ -451,7 +469,7 @@ extractPkg entry blockNo = case Tar.entryContent entry of
451
469
result <- if not dirExists then return Nothing
452
470
else do
453
471
cabalFile <- tryFindAddSourcePackageDesc path " Error reading package index."
454
- descr <- PackageDesc.Parse. readPackageDescription normal cabalFile
472
+ descr <- PackageDesc.Parse. readGenericPackageDescription normal cabalFile
455
473
return . Just $ BuildTreeRef (refTypeFromTypeCode typeCode) (packageId descr)
456
474
descr path blockNo
457
475
return result
@@ -674,7 +692,7 @@ packageListFromCache mkPkg hnd Cache{..} mode = accum mempty [] mempty cacheEntr
674
692
path <- liftM byteStringToFilePath . getEntryContent $ blockno
675
693
pkg <- do let err = " Error reading package index from cache."
676
694
file <- tryFindAddSourcePackageDesc path err
677
- PackageDesc.Parse. readPackageDescription normal file
695
+ PackageDesc.Parse. readGenericPackageDescription normal file
678
696
let srcpkg = mkPkg (BuildTreeRef refType (packageId pkg) pkg path blockno)
679
697
accum srcpkgs (srcpkg: btrs) prefs entries
680
698
@@ -693,9 +711,15 @@ packageListFromCache mkPkg hnd Cache{..} mode = accum mempty [] mempty cacheEntr
693
711
694
712
readPackageDescription :: ByteString -> IO GenericPackageDescription
695
713
readPackageDescription content =
696
- case parsePackageDescription . ignoreBOM . fromUTF8 . BS.Char8. unpack $ content of
714
+ #ifdef CABAL_PARSEC
715
+ case parseGenericPackageDescriptionMaybe (BS. toStrict content) of
716
+ Just gpd -> return gpd
717
+ Nothing -> interror " failed to parse .cabal file"
718
+ #else
719
+ case parseGenericPackageDescription . ignoreBOM . fromUTF8 . BS.Char8. unpack $ content of
697
720
ParseOk _ d -> return d
698
721
_ -> interror " failed to parse .cabal file"
722
+ #endif
699
723
700
724
interror msg = die $ " internal error when reading package index: " ++ msg
701
725
++ " The package index or index cache is probably "
0 commit comments