Fix ghc-mod tempdirs not being removed on exit

This commit is contained in:
Daniel Gröber 2014-12-17 17:52:50 +01:00
parent 80e826a199
commit 782f234981

View File

@ -270,16 +270,18 @@ runGhcModT :: IOish m
=> Options => Options
-> GhcModT m a -> GhcModT m a
-> m (Either GhcModError a, GhcModLog) -> m (Either GhcModError a, GhcModLog)
runGhcModT opt action = do runGhcModT opt action = gbracket newEnv delEnv $ \env -> do
env <- liftBase $ newGhcModEnv opt =<< getCurrentDirectory
r <- first (fst <$>) <$> (runGhcModT' env defaultState $ do r <- first (fst <$>) <$> (runGhcModT' env defaultState $ do
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
defaultCleanupHandler dflags $ do defaultCleanupHandler dflags $ do
initializeFlagsWithCradle opt (gmCradle env) initializeFlagsWithCradle opt (gmCradle env)
action) action)
liftBase $ cleanupGhcModEnv env
return r return r
where
newEnv = liftBase $ newGhcModEnv opt =<< getCurrentDirectory
delEnv = liftBase . cleanupGhcModEnv
-- | @hoistGhcModT result@. Embed a GhcModT computation's result into a GhcModT -- | @hoistGhcModT result@. Embed a GhcModT computation's result into a GhcModT
-- computation. Note that if the computation that returned @result@ modified the -- computation. Note that if the computation that returned @result@ modified the
-- state part of GhcModT this cannot be restored. -- state part of GhcModT this cannot be restored.