From 13930a9d7d690f8bb8677efc23c1e0d83d8002c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Fri, 9 May 2014 21:12:52 +0200 Subject: [PATCH] Fix Cabal >= 1.18 --- Language/Haskell/GhcMod/CabalConfig.hs | 23 +++++++++++++---------- Language/Haskell/GhcMod/GhcPkg.hs | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Language/Haskell/GhcMod/CabalConfig.hs b/Language/Haskell/GhcMod/CabalConfig.hs index 6cb91cd..75dc525 100644 --- a/Language/Haskell/GhcMod/CabalConfig.hs +++ b/Language/Haskell/GhcMod/CabalConfig.hs @@ -57,18 +57,25 @@ configDependencies thisPkg config = map fromInstalledPackageId deps Right ps -> ps Left msg -> error msg --- errorExtract = error $ --- "cabalConfigDependencies: Error extracting dependencies from setup-config" + -- True if this dependency is an internal one (depends on the library + -- defined in the same package). + internal pkgid = pkgid == thisPkg -- Cabal >= 1.18 deps18 :: Either String [InstalledPackageId] deps18 = - concatMap (map fst . C18.componentPackageDeps . lbi) + map fst + <$> filterInternal <$> (readEither =<< extractField config "componentsConfigs") - lbi :: (ComponentName, C18.ComponentLocalBuildInfo, [ComponentName]) - -> C18.ComponentLocalBuildInfo - lbi (_,i,_) = i + filterInternal + :: [(ComponentName, C18.ComponentLocalBuildInfo, [ComponentName])] + -> [(InstalledPackageId, PackageIdentifier)] + + filterInternal ccfg = [ (ipkgid, pkgid) + | (_,clbi,_) <- ccfg + , (ipkgid, pkgid) <- C18.componentPackageDeps clbi + , not (internal pkgid) ] -- Cabal 1.16 and below deps16 :: Either String [InstalledPackageId] @@ -81,10 +88,6 @@ configDependencies thisPkg config = map fromInstalledPackageId deps return $ maybe [] C16.componentPackageDeps libraryConfig ++ concatMap (C16.componentPackageDeps . snd) cbi where - -- True if this dependency is an internal one (depends on the library - -- defined in the same package). - internal pkgid = pkgid == thisPkg - libraryConfig :: Maybe C16.ComponentLocalBuildInfo libraryConfig = do field <- find ("libraryConfig" `isPrefixOf`) (tails config) diff --git a/Language/Haskell/GhcMod/GhcPkg.hs b/Language/Haskell/GhcMod/GhcPkg.hs index b8b5a96..a2580cf 100644 --- a/Language/Haskell/GhcMod/GhcPkg.hs +++ b/Language/Haskell/GhcMod/GhcPkg.hs @@ -13,7 +13,7 @@ module Language.Haskell.GhcMod.GhcPkg ( import Config (cProjectVersionInt) import Control.Applicative ((<$>)) #if MIN_VERSION_Cabal(1,18,0) -import Control.Exception (SomeException(..)) +import qualified Control.Exception as E #endif import Data.Char (isSpace) import Data.List (isPrefixOf, intercalate) @@ -54,7 +54,7 @@ getPackageDbStack :: FilePath -- ^ Project Directory (where the #if MIN_VERSION_Cabal(1,18,0) getPackageDbStack cdir = (getSandboxDb cdir >>= \db -> return [GlobalDb, PackageDb db]) - `E.catch` \(_ :: SomeException) -> return [GlobalDb, UserDb] + `E.catch` \(_ :: E.SomeException) -> return [GlobalDb, UserDb] #else getPackageDbStack _ = return [GlobalDb, UserDb]