From 02d38c96acdd2fa8fda8418f762c25a8fedf9e34 Mon Sep 17 00:00:00 2001 From: Yvan Sraka Date: Fri, 3 Nov 2023 12:09:29 +0100 Subject: [PATCH] [cabal-7825] Add `$CABAL` env variable for external commands This is a follow-up of #9063 --- Cabal/src/Distribution/Simple/Command.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Command.hs b/Cabal/src/Distribution/Simple/Command.hs index dc2be1a698b..1f201319930 100644 --- a/Cabal/src/Distribution/Simple/Command.hs +++ b/Cabal/src/Distribution/Simple/Command.hs @@ -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 @@ -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)