Fall back to Cabal 1.16 format on runtime if extracting fails
This commit is contained in:
parent
4c93819da8
commit
a7b2c86985
@ -19,14 +19,11 @@ import Language.Haskell.GhcMod.Utils
|
|||||||
import Control.Applicative ((<$>))
|
import Control.Applicative ((<$>))
|
||||||
import Control.Exception (SomeException(..))
|
import Control.Exception (SomeException(..))
|
||||||
import qualified Control.Exception as E
|
import qualified Control.Exception as E
|
||||||
import Control.Monad (filterM)
|
import Control.Monad (filterM,mplus)
|
||||||
import CoreMonad (liftIO)
|
import CoreMonad (liftIO)
|
||||||
import Data.Maybe (maybeToList)
|
import Data.Maybe (maybeToList)
|
||||||
import Data.Set (fromList, toList)
|
import Data.Set (fromList, toList)
|
||||||
import Data.List (find,tails,isPrefixOf)
|
import Data.List (find,tails,isPrefixOf,nub,stripPrefix)
|
||||||
#if !MIN_VERSION_Cabal(1,18,0)
|
|
||||||
import Data.List (nub,stripPrefix)
|
|
||||||
#endif
|
|
||||||
import Distribution.ModuleName (ModuleName,toFilePath)
|
import Distribution.ModuleName (ModuleName,toFilePath)
|
||||||
import Distribution.Package (Dependency(Dependency)
|
import Distribution.Package (Dependency(Dependency)
|
||||||
, PackageName(PackageName)
|
, PackageName(PackageName)
|
||||||
@ -233,43 +230,44 @@ cabalConfigDependencies :: PackageIdentifier -> CabalConfig -> [Package]
|
|||||||
cabalConfigDependencies thisPkg config = cfgDepends
|
cabalConfigDependencies thisPkg config = cfgDepends
|
||||||
where
|
where
|
||||||
pids :: [InstalledPackageId]
|
pids :: [InstalledPackageId]
|
||||||
pids = fst <$> components thisPkg
|
pids = let
|
||||||
|
mps = map fst <$> (components18 thisPkg `mplus` components16 thisPkg)
|
||||||
|
in case mps of
|
||||||
|
Just ps -> ps
|
||||||
|
Nothing -> errorExtract
|
||||||
cfgDepends = filter (("inplace" /=) . pkgId)
|
cfgDepends = filter (("inplace" /=) . pkgId)
|
||||||
$ fromInstalledPackageId <$> pids
|
$ fromInstalledPackageId <$> pids
|
||||||
|
|
||||||
errorExtract f = error $
|
errorExtract = error $
|
||||||
"cabalConfigDependencies: Extracting field `"++ f ++"' from"
|
"cabalConfigDependencies: Error extracting dependencies from setup-config"
|
||||||
++ " setup-config failed"
|
|
||||||
|
|
||||||
components :: PackageIdentifier -> [(InstalledPackageId,PackageIdentifier)]
|
-- Cabal 1.18
|
||||||
#if MIN_VERSION_Cabal(1,18,0)
|
components18 :: PackageIdentifier
|
||||||
components _ = case extractCabalSetupConfig config "componentsConfigs" of
|
-> Maybe [(InstalledPackageId,PackageIdentifier)]
|
||||||
Just comps -> concatMap (componentPackageDeps . lbi) comps
|
components18 _ =
|
||||||
Nothing -> errorExtract "componentsConfigs"
|
concatMap (componentPackageDeps . lbi)
|
||||||
|
<$> extractCabalSetupConfig config "componentsConfigs"
|
||||||
|
|
||||||
lbi :: (ComponentName, ComponentLocalBuildInfo, [ComponentName])
|
lbi :: (ComponentName, ComponentLocalBuildInfo, [ComponentName])
|
||||||
-> ComponentLocalBuildInfo
|
-> ComponentLocalBuildInfo
|
||||||
lbi (_,i,_) = i
|
lbi (_,i,_) = i
|
||||||
#elif MIN_VERSION_Cabal(1,16,0)
|
|
||||||
components thisPkg' = filter (not . internal . snd) $ nub $
|
-- Cabal 1.16 and below
|
||||||
maybe [] componentPackageDeps libraryConfig
|
components16 :: PackageIdentifier
|
||||||
++ concatMap (componentPackageDeps . snd) executableConfigs
|
-> Maybe [(InstalledPackageId,PackageIdentifier)]
|
||||||
++ concatMap (componentPackageDeps . snd) testSuiteConfigs
|
components16 thisPkg' = filter (not . internal . snd) . nub <$> do
|
||||||
++ concatMap (componentPackageDeps . snd) benchmarkConfigs
|
cbi <- concat <$> sequence [ extract "executableConfigs"
|
||||||
|
, extract "testSuiteConfigs"
|
||||||
|
, extract "benchmarkConfigs" ]
|
||||||
|
:: Maybe [(String, ComponentLocalBuildInfo)]
|
||||||
|
|
||||||
|
return $ maybe [] componentPackageDeps libraryConfig
|
||||||
|
++ concatMap (componentPackageDeps . snd) cbi
|
||||||
where
|
where
|
||||||
-- True if this dependency is an internal one (depends on the library
|
-- True if this dependency is an internal one (depends on the library
|
||||||
-- defined in the same package).
|
-- defined in the same package).
|
||||||
internal pkgid = pkgid == thisPkg'
|
internal pkgid = pkgid == thisPkg'
|
||||||
|
|
||||||
executableConfigs :: [(String, ComponentLocalBuildInfo)]
|
|
||||||
executableConfigs = extract "executableConfigs"
|
|
||||||
|
|
||||||
testSuiteConfigs :: [(String, ComponentLocalBuildInfo)]
|
|
||||||
testSuiteConfigs = extract "testSuiteConfigs"
|
|
||||||
|
|
||||||
benchmarkConfigs ::[(String, ComponentLocalBuildInfo)]
|
|
||||||
benchmarkConfigs = extract "benchmarkConfigs"
|
|
||||||
|
|
||||||
libraryConfig :: Maybe ComponentLocalBuildInfo
|
libraryConfig :: Maybe ComponentLocalBuildInfo
|
||||||
libraryConfig = do
|
libraryConfig = do
|
||||||
field <- find ("libraryConfig" `isPrefixOf`) (tails config)
|
field <- find ("libraryConfig" `isPrefixOf`) (tails config)
|
||||||
@ -278,11 +276,8 @@ cabalConfigDependencies thisPkg config = cfgDepends
|
|||||||
then Nothing
|
then Nothing
|
||||||
else read <$> stripPrefix "Just " clbi
|
else read <$> stripPrefix "Just " clbi
|
||||||
|
|
||||||
extract :: Read r => String -> r
|
extract :: Read r => String -> Maybe r
|
||||||
extract field = case extractCabalSetupConfig config field of
|
extract field = extractCabalSetupConfig config field
|
||||||
Nothing -> errorExtract field
|
|
||||||
Just f -> f
|
|
||||||
#endif
|
|
||||||
|
|
||||||
-- | Extract part of cabal's @setup-config@, this is done with a mix of manual
|
-- | Extract part of cabal's @setup-config@, this is done with a mix of manual
|
||||||
-- string processing and use of 'read'. This way we can extract a field from
|
-- string processing and use of 'read'. This way we can extract a field from
|
||||||
|
Loading…
Reference in New Issue
Block a user