Skip to content

Commit

Permalink
Use createProcess instead of callExternal
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Nov 3, 2023
1 parent 87f2ddd commit 71dc0d1
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Cabal/src/Distribution/Simple/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ import qualified Distribution.GetOpt as GetOpt
import Distribution.ReadE
import Distribution.Simple.Utils
import System.Directory (findExecutable)
import System.Process (callProcess)
import System.Environment (getExecutablePath, setEnv)
import System.Process (createProcess, CreateProcess (env), proc)
import System.Environment (getExecutablePath)

data CommandUI flags = CommandUI
{ commandName :: String
Expand Down Expand Up @@ -652,10 +652,7 @@ commandsRun globalCommand commands args =
_ -> do
mCommand <- findExecutable $ "cabal-" <> name
case mCommand of
Just exec -> do
execPath <- getExecutablePath
void $ setEnv "CABAL" execPath
callExternal flags exec cmdArgs
Just exec -> callExternal flags exec cmdArgs
Nothing -> pure $ CommandReadyToGo (flags, badCommand name)
[] -> pure $ CommandReadyToGo (flags, noCommand)
where
Expand All @@ -667,7 +664,8 @@ commandsRun globalCommand commands args =

callExternal :: a -> String -> [String] -> IO (CommandParse (a, CommandParse action))
callExternal flags exec cmdArgs = do
result <- try $ callProcess exec cmdArgs
execPath <- getExecutablePath
result <- try $ createProcess (proc exec cmdArgs) { env = Just [("CABAL", execPath)] }
case result of
Left ex -> pure $ CommandErrors ["Error executing external command: " ++ show (ex :: SomeException)]
Right _ -> pure $ CommandReadyToGo (flags, CommandDelegate)
Expand Down

0 comments on commit 71dc0d1

Please sign in to comment.