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
|
2015-08-07 04:47:34 +00:00
|
|
|
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
|
2015-08-19 06:46:56 +00:00
|
|
|
, worldCabalSandboxConfig :: Maybe TimedFile
|
2015-11-26 13:48:26 +00:00
|
|
|
} deriving (Eq)
|
2014-11-01 21:02:47 +00:00
|
|
|
|
2015-08-07 04:47:34 +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
|
|
|
|
2015-08-07 04:47:34 +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)
|
2015-08-19 06:46:56 +00:00
|
|
|
mCabalSandboxConfig <- liftIO $ timeMaybe (sandboxConfigFile crdl)
|
2014-11-01 21:02:47 +00:00
|
|
|
|
|
|
|
return World {
|
|
|
|
worldPackageCaches = pkgCaches
|
|
|
|
, worldCabalFile = mCabalFile
|
|
|
|
, worldCabalConfig = mCabalConfig
|
2015-08-19 06:46:56 +00:00
|
|
|
, worldCabalSandboxConfig = mCabalSandboxConfig
|
2014-11-01 21:02:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 04:47:34 +00:00
|
|
|
didWorldChange :: IOish m => World -> GhcModT m Bool
|
|
|
|
didWorldChange world = do
|
|
|
|
(world /=) <$> getCurrentWorld
|
2015-02-07 22:55:57 +00:00
|
|
|
|
|
|
|
isYoungerThanSetupConfig :: FilePath -> World -> IO Bool
|
|
|
|
isYoungerThanSetupConfig file World {..} = do
|
|
|
|
tfile <- timeFile file
|
|
|
|
return $ worldCabalConfig < Just tfile
|