Skip to content

Commit

Permalink
[cabal-7825] Add $CABAL env variable for external commands
Browse files Browse the repository at this point in the history
This is a follow-up of #9063
  • Loading branch information
yvan-sraka committed Nov 3, 2023
1 parent 1157461 commit 02d38c9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Cabal/src/Distribution/Simple/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +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)
import System.Process (CreateProcess (env), createProcess, proc)

data CommandUI flags = CommandUI
{ commandName :: String
Expand Down Expand Up @@ -663,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 02d38c9

Please sign in to comment.