Fix Cabal >= 1.18

This commit is contained in:
Daniel Gröber 2014-05-09 21:12:52 +02:00
parent 175635505d
commit 13930a9d7d
2 changed files with 15 additions and 12 deletions

View File

@ -57,18 +57,25 @@ configDependencies thisPkg config = map fromInstalledPackageId deps
Right ps -> ps Right ps -> ps
Left msg -> error msg Left msg -> error msg
-- errorExtract = error $ -- True if this dependency is an internal one (depends on the library
-- "cabalConfigDependencies: Error extracting dependencies from setup-config" -- defined in the same package).
internal pkgid = pkgid == thisPkg
-- Cabal >= 1.18 -- Cabal >= 1.18
deps18 :: Either String [InstalledPackageId] deps18 :: Either String [InstalledPackageId]
deps18 = deps18 =
concatMap (map fst . C18.componentPackageDeps . lbi) map fst
<$> filterInternal
<$> (readEither =<< extractField config "componentsConfigs") <$> (readEither =<< extractField config "componentsConfigs")
lbi :: (ComponentName, C18.ComponentLocalBuildInfo, [ComponentName]) filterInternal
-> C18.ComponentLocalBuildInfo :: [(ComponentName, C18.ComponentLocalBuildInfo, [ComponentName])]
lbi (_,i,_) = i -> [(InstalledPackageId, PackageIdentifier)]
filterInternal ccfg = [ (ipkgid, pkgid)
| (_,clbi,_) <- ccfg
, (ipkgid, pkgid) <- C18.componentPackageDeps clbi
, not (internal pkgid) ]
-- Cabal 1.16 and below -- Cabal 1.16 and below
deps16 :: Either String [InstalledPackageId] deps16 :: Either String [InstalledPackageId]
@ -81,10 +88,6 @@ configDependencies thisPkg config = map fromInstalledPackageId deps
return $ maybe [] C16.componentPackageDeps libraryConfig return $ maybe [] C16.componentPackageDeps libraryConfig
++ concatMap (C16.componentPackageDeps . snd) cbi ++ concatMap (C16.componentPackageDeps . snd) cbi
where 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 :: Maybe C16.ComponentLocalBuildInfo
libraryConfig = do libraryConfig = do
field <- find ("libraryConfig" `isPrefixOf`) (tails config) field <- find ("libraryConfig" `isPrefixOf`) (tails config)

View File

@ -13,7 +13,7 @@ module Language.Haskell.GhcMod.GhcPkg (
import Config (cProjectVersionInt) import Config (cProjectVersionInt)
import Control.Applicative ((<$>)) import Control.Applicative ((<$>))
#if MIN_VERSION_Cabal(1,18,0) #if MIN_VERSION_Cabal(1,18,0)
import Control.Exception (SomeException(..)) import qualified Control.Exception as E
#endif #endif
import Data.Char (isSpace) import Data.Char (isSpace)
import Data.List (isPrefixOf, intercalate) import Data.List (isPrefixOf, intercalate)
@ -54,7 +54,7 @@ getPackageDbStack :: FilePath -- ^ Project Directory (where the
#if MIN_VERSION_Cabal(1,18,0) #if MIN_VERSION_Cabal(1,18,0)
getPackageDbStack cdir = getPackageDbStack cdir =
(getSandboxDb cdir >>= \db -> return [GlobalDb, PackageDb db]) (getSandboxDb cdir >>= \db -> return [GlobalDb, PackageDb db])
`E.catch` \(_ :: SomeException) -> return [GlobalDb, UserDb] `E.catch` \(_ :: E.SomeException) -> return [GlobalDb, UserDb]
#else #else
getPackageDbStack _ = getPackageDbStack _ =
return [GlobalDb, UserDb] return [GlobalDb, UserDb]