Skip to content

Commit

Permalink
'stack ghci' is now spawned fixes commercialhaskell#1306
Browse files Browse the repository at this point in the history
  • Loading branch information
luigy committed Mar 2, 2016
1 parent 6af4831 commit e1886d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions src/Stack/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import Control.Monad.Catch hiding (try)
import Control.Monad.Trans.Control (MonadBaseControl)
import Stack.Types
import System.Process.Log
import System.Process.Read (EnvOverride)

#ifdef WINDOWS
import Control.Exception.Lifted
import Data.Streaming.Process (ProcessExitedUnsuccessfully(..))
import System.Exit
import System.Process.Run (callProcess, Cmd(..))
#ifdef WINDOWS
import System.Process.Read (EnvOverride)
#else
import System.Process.Read (envHelper, preProcess)
import System.Posix.Process (executeFile)
import System.Process.Read (EnvOverride, envHelper, preProcess)
#endif

-- | Default @EnvSettings@ which includes locals and GHC_PACKAGE_PATH
Expand All @@ -47,14 +47,21 @@ plainEnvSettings = EnvSettings
-- | Execute a process within the Stack configured environment.
exec :: (MonadIO m, MonadLogger m, MonadThrow m, MonadBaseControl IO m)
=> EnvOverride -> String -> [String] -> m b
#ifdef WINDOWS
exec = execSpawn
#else
exec menv cmd0 args = do
$logProcessRun cmd0 args
#ifdef WINDOWS
cmd <- preProcess Nothing menv cmd0
liftIO $ executeFile cmd True args (envHelper menv)
#endif

-- | Execute a spawned process within the Stack configured environment.
execSpawn :: (MonadIO m, MonadLogger m, MonadThrow m, MonadBaseControl IO m)
=> EnvOverride -> String -> [String] -> m b
execSpawn menv cmd0 args = do
$logProcessRun cmd0 args
e <- try (callProcess (Cmd Nothing cmd0 menv args))
liftIO $ case e of
Left (ProcessExitedUnsuccessfully _ ec) -> exitWith ec
Right () -> exitSuccess
#else
cmd <- preProcess Nothing menv cmd0
liftIO $ executeFile cmd True args (envHelper menv)
#endif
2 changes: 1 addition & 1 deletion src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ghci opts@GhciOpts{..} = do
T.intercalate ", " (map (packageNameText . ghciPkgName) pkgs))
let execGhci extras = do
menv <- liftIO $ configEnvOverride config defaultEnvSettings
exec menv
execSpawn menv
(fromMaybe (compilerExeName wc) ghciGhcCommand)
("--interactive" :
-- This initial "-i" resets the include directories to not
Expand Down

0 comments on commit e1886d8

Please sign in to comment.