ghc-mod/core/GhcMod/World.hs

56 lines
1.6 KiB
Haskell
Raw Normal View History

module GhcMod.World where
2014-11-01 21:02:47 +00:00
import GhcMod.GhcPkg
import GhcMod.PathsAndFiles
import GhcMod.Types
import GhcMod.Monad.Types
import GhcMod.Utils
2014-11-01 21:02:47 +00:00
2015-08-03 01:09:56 +00:00
import Control.Applicative
2014-11-01 21:02:47 +00:00
import Data.Maybe
2015-08-03 05:51:23 +00:00
import Data.Traversable hiding (mapM)
2014-11-01 21:02:47 +00:00
import System.FilePath ((</>))
import GHC.Paths (libdir)
2015-08-03 01:09:56 +00:00
import Prelude
2014-11-01 21:02:47 +00:00
data World = World {
worldPackageCaches :: [TimedFile]
, worldCabalFile :: Maybe TimedFile
, worldCabalConfig :: Maybe TimedFile
, worldCabalSandboxConfig :: Maybe TimedFile
2016-01-28 21:57:35 +00:00
, worldMappedFiles :: FileMappingMap
} deriving (Eq)
2014-11-01 21:02:47 +00:00
timedPackageCaches :: IOish m => GhcModT m [TimedFile]
timedPackageCaches = do
fs <- mapM (liftIO . mightExist) . map (</> packageCache)
=<< getPackageCachePaths libdir
(liftIO . timeFile) `mapM` catMaybes fs
2014-11-01 21:02:47 +00:00
getCurrentWorld :: IOish m => GhcModT m World
getCurrentWorld = do
crdl <- cradle
pkgCaches <- timedPackageCaches
mCabalFile <- liftIO $ timeFile `traverse` cradleCabalFile crdl
mCabalConfig <- liftIO $ timeMaybe (setupConfigFile crdl)
mCabalSandboxConfig <- liftIO $ timeMaybe (sandboxConfigFile crdl)
2016-01-28 21:57:35 +00:00
mFileMap <- getMMappedFiles
2014-11-01 21:02:47 +00:00
return World {
worldPackageCaches = pkgCaches
, worldCabalFile = mCabalFile
, worldCabalConfig = mCabalConfig
, worldCabalSandboxConfig = mCabalSandboxConfig
2016-01-28 21:57:35 +00:00
, worldMappedFiles = mFileMap
2014-11-01 21:02:47 +00:00
}
didWorldChange :: IOish m => World -> GhcModT m Bool
didWorldChange world = do
(world /=) <$> getCurrentWorld
isYoungerThanSetupConfig :: FilePath -> World -> IO Bool
isYoungerThanSetupConfig file World {..} = do
tfile <- timeFile file
return $ worldCabalConfig < Just tfile