Skip to content

Commit

Permalink
Add support for Cabal-2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bgamari committed Dec 24, 2018
1 parent 9e131f1 commit a2d5003
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hpc-coveralls.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ library
aeson >= 0.7.1 && <1.5,
base >= 4 && < 5,
bytestring >= 0.10 && <0.11,
Cabal <2.4,
Cabal >= 2.4 && <2.6,
containers >= 0.5 && <0.7,
cmdargs >= 0.10 && <0.11,
curl >= 1.3.8 && <1.4,
Expand All @@ -80,7 +80,7 @@ executable hpc-coveralls
aeson >= 0.7.1 && <1.5,
base >= 4 && < 5,
bytestring >= 0.10 && <0.11,
Cabal,
Cabal >= 2.4 && <2.6,
containers >= 0.5 && <0.7,
cmdargs >= 0.10 && <0.11,
curl >= 1.3.8 && <1.4,
Expand Down
17 changes: 17 additions & 0 deletions src/Trace/Hpc/Coveralls/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ import Control.Monad.Trans.Maybe
import Data.List (intercalate, isSuffixOf)
import Distribution.Package
import Distribution.PackageDescription
#if MIN_VERSION_Cabal(2,4,0)
import Distribution.PackageDescription.Parsec
import qualified Data.ByteString as BS
#else
import Distribution.PackageDescription.Parse
#endif
import Distribution.Version
import System.Directory

Expand All @@ -30,6 +35,17 @@ getCabalFile dir = do
where isCabal filename = ".cabal" `isSuffixOf` filename && length filename > 6

getPackageNameVersion :: FilePath -> IO (Maybe String)
#if MIN_VERSION_Cabal(2,4,0)
getPackageNameVersion file = do
orig <- BS.readFile file
case runParseResult $ parseGenericPackageDescription orig of
(_warnings, Left _) -> return Nothing
(_warnings, Right gpd) -> return $ Just $ name ++ "-" ++ version
where pkg = package . packageDescription $ gpd
name = unPackageName $ pkgName pkg
version = showVersion (pkgVersion pkg)
showVersion = intercalate "." . map show . versionNumbers
#else
getPackageNameVersion file = do
orig <- readFile file
case parsePackageDescription orig of
Expand All @@ -39,6 +55,7 @@ getPackageNameVersion file = do
name = unPackageName $ pkgName pkg
version = showVersion (pkgVersion pkg)
showVersion = intercalate "." . map show . versionNumbers
#endif

currDirPkgNameVer :: IO (Maybe String)
currDirPkgNameVer = runMaybeT $ pkgNameVersion currentDir
Expand Down

0 comments on commit a2d5003

Please sign in to comment.