-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split off process execution into library (#130)
- Loading branch information
Showing
3 changed files
with
37 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
-- | Execute commands within the properly configured Stack | ||
-- environment. | ||
|
||
module Stack.Exec where | ||
|
||
import Control.Monad.Reader | ||
import Path | ||
import Stack.Types | ||
import System.Exit | ||
import qualified System.Process as P | ||
import System.Process.Read | ||
|
||
-- | Execute a process within the Stack configured environment. | ||
exec :: (HasConfig r, MonadReader r m, MonadIO m) | ||
=> String -> [String] -> m b | ||
exec cmd args = do | ||
config <- asks getConfig | ||
liftIO $ do | ||
menv <- configEnvOverride config | ||
EnvSettings | ||
{ esIncludeLocals = True | ||
, esIncludeGhcPackagePath = True | ||
} | ||
cmd' <- join $ System.Process.Read.findExecutable menv cmd | ||
let cp = (P.proc (toFilePath cmd') args) | ||
{ P.env = envHelper menv | ||
, P.delegate_ctlc = True | ||
} | ||
(Nothing, Nothing, Nothing, ph) <- P.createProcess cp | ||
ec <- P.waitForProcess ph | ||
exitWith ec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters