summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2020-03-27 14:06:39 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-04-02 01:49:21 -0400
commit27740f24cb70fc14b00c1212c06642a144a6117d (patch)
tree3aa2e2ed2dd5be5ee2370e85fb5ed3dfc43727bb
parent88f38b03025386f0f1e8f5861eed67d80495168a (diff)
downloadhaskell-27740f24cb70fc14b00c1212c06642a144a6117d.tar.gz
Make Hadrian build with Cabal-3.2
GHC 8.10 ships with `Cabal-3.2.0.0`, so it would be convenient to make Hadrian supporting building against 3.2.* instead of having to rebuild the entirety of `Cabal-3.0.0.0`. There is one API change in `Cabal-3.2.*` that affects Hadrian: the `synopsis` and `description` functions now return `ShortText` instead of `String`. Since Hadrian manipulates these `String`s in various places, I found that the simplest fix was to use CPP to convert `ShortText` to `String`s where appropriate.
-rw-r--r--hadrian/hadrian.cabal2
-rw-r--r--hadrian/src/Hadrian/Haskell/Cabal/Parse.hs17
-rw-r--r--hadrian/src/Rules/Library.hs2
3 files changed, 18 insertions, 3 deletions
diff --git a/hadrian/hadrian.cabal b/hadrian/hadrian.cabal
index dd95e88299..8e3a9289d4 100644
--- a/hadrian/hadrian.cabal
+++ b/hadrian/hadrian.cabal
@@ -133,7 +133,7 @@ executable hadrian
other-extensions: MultiParamTypeClasses
, TypeFamilies
build-depends: base >= 4.8 && < 5
- , Cabal >= 3.0 && < 3.1
+ , Cabal >= 3.0 && < 3.3
, containers >= 0.5 && < 0.7
, directory >= 1.3.1.0 && < 1.4
, extra >= 1.4.7
diff --git a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
index 12e654cee3..ace24dc87d 100644
--- a/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
+++ b/hadrian/src/Hadrian/Haskell/Cabal/Parse.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
-- |
-- Module : Hadrian.Haskell.Cabal.Parse
@@ -38,6 +39,9 @@ import qualified Distribution.Text as C
import qualified Distribution.Types.LocalBuildInfo as C
import qualified Distribution.Types.CondTree as C
import qualified Distribution.Types.MungedPackageId as C
+#if MIN_VERSION_Cabal(3,2,0)
+import qualified Distribution.Utils.ShortText as C
+#endif
import qualified Distribution.Verbosity as C
import Hadrian.Expression
import Hadrian.Haskell.Cabal
@@ -69,7 +73,10 @@ parsePackageData pkg = do
sorted = sort [ C.unPackageName p | C.Dependency p _ _ <- allDeps ]
deps = nubOrd sorted \\ [name]
depPkgs = catMaybes $ map findPackageByName deps
- return $ PackageData name version (C.synopsis pd) (C.description pd) depPkgs gpd
+ return $ PackageData name version
+ (shortTextToString (C.synopsis pd))
+ (shortTextToString (C.description pd))
+ depPkgs gpd
where
-- Collect an overapproximation of dependencies by ignoring conditionals
collectDeps :: Maybe (C.CondTree v [C.Dependency] a) -> [C.Dependency]
@@ -78,6 +85,14 @@ parsePackageData pkg = do
where
f (C.CondBranch _ t mt) = collectDeps (Just t) ++ collectDeps mt
+#if MIN_VERSION_Cabal(3,2,0)
+ shortTextToString :: C.ShortText -> String
+ shortTextToString = C.fromShortText
+#else
+ shortTextToString :: String -> String
+ shortTextToString = id
+#endif
+
-- | Parse the package identifier from a Cabal file.
parseCabalPkgId :: FilePath -> IO String
parseCabalPkgId file = C.display . C.package . C.packageDescription <$> C.readGenericPackageDescription C.silent file
diff --git a/hadrian/src/Rules/Library.hs b/hadrian/src/Rules/Library.hs
index 5f839215dc..066f609a49 100644
--- a/hadrian/src/Rules/Library.hs
+++ b/hadrian/src/Rules/Library.hs
@@ -140,7 +140,7 @@ extraObjects context
-- | Return all the object files to be put into the library we're building for
-- the given 'Context'.
libraryObjects :: Context -> Action [FilePath]
-libraryObjects context@Context{..} = do
+libraryObjects context = do
hsObjs <- hsObjects context
noHsObjs <- nonHsObjects context
need $ noHsObjs ++ hsObjs