ghc-mod/Language/Haskell/GhcMod/CabalConfig.hs

43 lines
1.3 KiB
Haskell
Raw Normal View History

2015-01-16 14:47:56 +00:00
{-# LANGUAGE CPP #-}
2014-06-29 08:28:28 +00:00
2015-01-16 14:47:56 +00:00
-- | This module abstracts extracting information from Cabal's on-disk
-- 'LocalBuildInfo' (@dist/setup-config@) for different version combinations of
-- Cabal and GHC.
module Language.Haskell.GhcMod.CabalConfig (
2015-01-16 14:47:56 +00:00
cabalConfigDependencies
, cabalConfigFlags
) where
2015-01-16 14:47:56 +00:00
import Control.Applicative
import Distribution.Package (PackageIdentifier)
import Distribution.PackageDescription (FlagAssignment)
2015-01-16 14:47:56 +00:00
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Error
2014-07-17 08:16:44 +00:00
2015-01-16 14:47:56 +00:00
#if __GLASGOW_HASKELL__ >= 710
import Language.Haskell.GhcMod.CabalConfig.Ghc710
2014-06-29 08:28:28 +00:00
#else
2015-01-16 14:47:56 +00:00
import Language.Haskell.GhcMod.CabalConfig.PreGhc710
2014-06-29 08:28:28 +00:00
#endif
2014-08-11 21:45:33 +00:00
-- | Get list of 'Package's needed by all components of the current package
cabalConfigDependencies :: (IOish m, MonadError GhcModError m)
=> Cradle
-> PackageIdentifier
-> m [Package]
cabalConfigDependencies cradle thisPkg =
configDependencies thisPkg <$> getConfig cradle
-- | Get the flag assignment from the local build info of the given cradle
cabalConfigFlags :: (IOish m, MonadError GhcModError m)
=> Cradle
-> m FlagAssignment
cabalConfigFlags cradle = do
config <- getConfig cradle
case configFlags config of
Right x -> return x
Left msg -> throwError (GMECabalFlags (GMEString msg))