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

53 lines
1.6 KiB
Haskell
Raw Normal View History

2014-11-01 21:02:47 +00:00
module Language.Haskell.GhcMod.World where
import Language.Haskell.GhcMod.GhcPkg
import Language.Haskell.GhcMod.PathsAndFiles
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Monad.Types
2014-11-01 21:02:47 +00:00
import Language.Haskell.GhcMod.Utils
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
} 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)
2014-11-01 21:02:47 +00:00
return World {
worldPackageCaches = pkgCaches
, worldCabalFile = mCabalFile
, worldCabalConfig = mCabalConfig
, worldCabalSandboxConfig = mCabalSandboxConfig
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