summaryrefslogtreecommitdiff
path: root/hadrian/src/Rules/Register.hs
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2019-01-07 00:59:23 +0100
committerBen Gamari <ben@well-typed.com>2019-01-14 09:30:40 -0500
commitcb31b23d39151c9a8b3c80ca11dd299224940f0d (patch)
tree0c420ced8f14c3d6bc6ec3731714bc85b5731da3 /hadrian/src/Rules/Register.hs
parentce11f6f25c1160262830d9670c4eaaebac37cbaf (diff)
downloadhaskell-cb31b23d39151c9a8b3c80ca11dd299224940f0d.tar.gz
Update `Cabal` submodule
This also requires adapting `ghc-pkg` to use the new Cabal parsing API as the old ReadP-based one has finally been evicted for good. Hadrian bit finished by: Ben Gamari <ben@smart-cactus.org>
Diffstat (limited to 'hadrian/src/Rules/Register.hs')
-rw-r--r--hadrian/src/Rules/Register.hs16
1 files changed, 9 insertions, 7 deletions
diff --git a/hadrian/src/Rules/Register.hs b/hadrian/src/Rules/Register.hs
index b513c37097..ef56da5eae 100644
--- a/hadrian/src/Rules/Register.hs
+++ b/hadrian/src/Rules/Register.hs
@@ -10,10 +10,11 @@ import Settings.Default
import Target
import Utilities
-import Distribution.ParseUtils
import Distribution.Version (Version)
+import qualified Distribution.Parsec as Cabal
+import qualified Distribution.Types.PackageName as Cabal
+import qualified Distribution.Types.PackageId as Cabal
-import qualified Distribution.Compat.ReadP as Parse
import qualified Hadrian.Haskell.Cabal.Parse as Cabal
import qualified System.Directory as IO
import qualified Text.Parsec as Parsec
@@ -127,13 +128,14 @@ getPackageNameFromConfFile :: FilePath -> Action String
getPackageNameFromConfFile conf
| takeBaseName conf == "rts" = return "rts"
| otherwise = case parseCabalName (takeBaseName conf) of
- Nothing -> error $ "getPackageNameFromConfFile: couldn't parse " ++ conf
- Just (name, _) -> return name
+ Left err -> error $ "getPackageNameFromConfFile: couldn't parse " ++ takeBaseName conf ++ ": " ++ err
+ Right (name, _) -> return name
-parseCabalName :: String -> Maybe (String, Version)
-parseCabalName = readPToMaybe parse
+parseCabalName :: String -> Either String (String, Version)
+parseCabalName = fmap f . Cabal.eitherParsec
where
- parse = (,) <$> (parsePackageName <* Parse.char '-') <*> parseOptVersion
+ f :: Cabal.PackageId -> (String, Version)
+ f pkg_id = (Cabal.unPackageName $ Cabal.pkgName pkg_id, Cabal.pkgVersion pkg_id)
getPackageByName :: String -> Action Package
getPackageByName n = case findPackageByName n of