Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Cabal 2.4 #81

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions hpc-coveralls.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
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