2015-01-16 14:47:56 +00:00
|
|
|
module Language.Haskell.GhcMod.CabalConfig.Ghc710 (
|
|
|
|
configDependencies
|
|
|
|
, configFlags
|
|
|
|
, getConfig
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Control.Monad
|
|
|
|
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo, externalPackageDeps)
|
|
|
|
import qualified Distribution.Simple.LocalBuildInfo as LBI
|
|
|
|
import Distribution.Simple.Configure (getConfigStateFile)
|
|
|
|
import Distribution.Simple.Setup (configConfigurationsFlags)
|
|
|
|
import Distribution.PackageDescription (FlagAssignment)
|
|
|
|
|
|
|
|
import MonadUtils (liftIO)
|
|
|
|
|
|
|
|
import Language.Haskell.GhcMod.Error
|
|
|
|
import Language.Haskell.GhcMod.GhcPkg
|
|
|
|
import Language.Haskell.GhcMod.PathsAndFiles
|
|
|
|
import Language.Haskell.GhcMod.Types
|
2015-02-07 22:55:57 +00:00
|
|
|
import Language.Haskell.GhcMod.Monad.Types
|
2015-01-16 14:47:56 +00:00
|
|
|
import Language.Haskell.GhcMod.Utils
|
|
|
|
import Language.Haskell.GhcMod.World
|
|
|
|
|
|
|
|
|
|
|
|
-- | Get contents of the file containing 'LocalBuildInfo' data. If it doesn't
|
|
|
|
-- exist run @cabal configure@ i.e. configure with default options like @cabal
|
|
|
|
-- build@ would do.
|
2015-02-07 22:55:57 +00:00
|
|
|
getConfig :: (IOish m, GmError m)
|
2015-01-16 14:47:56 +00:00
|
|
|
=> Cradle
|
|
|
|
-> m LocalBuildInfo
|
2015-02-07 22:55:57 +00:00
|
|
|
getConfig cradle = liftIO (getCurrentWorld cradle) >>= \world -> do
|
|
|
|
when (isSetupConfigOutOfDate world) configure
|
2015-01-16 14:47:56 +00:00
|
|
|
liftIO (getConfigStateFile file) `tryFix` \_ ->
|
|
|
|
configure `modifyError'` GMECabalConfigure
|
|
|
|
where
|
|
|
|
file = setupConfigFile cradle
|
|
|
|
prjDir = cradleRootDir cradle
|
|
|
|
|
2015-02-07 22:55:57 +00:00
|
|
|
configure :: (IOish m, GmError m) => m ()
|
2015-01-16 14:47:56 +00:00
|
|
|
configure = withDirectory_ prjDir $ void $ readProcess' "cabal" ["configure"]
|
|
|
|
|
|
|
|
configDependencies :: a -> LocalBuildInfo -> [Package]
|
|
|
|
configDependencies _ lbi =
|
|
|
|
[ fromInstalledPackageId instPkgId
|
|
|
|
| (instPkgId, _) <- externalPackageDeps lbi ]
|
|
|
|
|
|
|
|
|
|
|
|
configFlags :: LocalBuildInfo -> Either String FlagAssignment
|
|
|
|
configFlags = Right . configConfigurationsFlags . LBI.configFlags
|