diff --git a/hpc-coveralls.cabal b/hpc-coveralls.cabal index f2acb39..e3b7dec 100644 --- a/hpc-coveralls.cabal +++ b/hpc-coveralls.cabal @@ -56,11 +56,11 @@ library Trace.Hpc.Coveralls.GitInfo, Trace.Hpc.Coveralls.Paths build-depends: - aeson >= 0.7.1 && <1.3, + aeson >= 0.7.1 && <1.5, base >= 4 && < 5, bytestring >= 0.10 && <0.11, - Cabal, - containers >= 0.5 && <0.6, + Cabal >= 2.4 && <2.6, + containers >= 0.5 && <0.7, cmdargs >= 0.10 && <0.11, curl >= 1.3.8 && <1.4, directory >= 1.2 && <1.4, @@ -77,11 +77,11 @@ executable hpc-coveralls hs-source-dirs: src main-is: HpcCoverallsMain.hs build-depends: - aeson >= 0.7.1 && <1.3, + aeson >= 0.7.1 && <1.5, base >= 4 && < 5, bytestring >= 0.10 && <0.11, - Cabal, - containers >= 0.5 && <0.6, + Cabal >= 2.4 && <2.6, + containers >= 0.5 && <0.7, cmdargs >= 0.10 && <0.11, curl >= 1.3.8 && <1.4, directory >= 1.2 && <1.4, diff --git a/src/Trace/Hpc/Coveralls/Cabal.hs b/src/Trace/Hpc/Coveralls/Cabal.hs index b303045..8f28a8e 100644 --- a/src/Trace/Hpc/Coveralls/Cabal.hs +++ b/src/Trace/Hpc/Coveralls/Cabal.hs @@ -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 @@ -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 @@ -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