@@ -32,7 +32,7 @@ import System.Directory (getCurrentDirectory, canonicalizePath, findEx
3232import System.Exit
3333import System.FilePath
3434import System.Log.Logger
35- import System.Process (readCreateProcessWithExitCode , shell )
35+ import System.Process (readCreateProcessWithExitCode , shell , CreateProcess ( .. ) )
3636
3737
3838-- ---------------------------------------------------------------------
@@ -105,7 +105,7 @@ execProjectGhc crdl args = do
105105 ghcOutput <- if isStackCradle crdl && isStackInstalled
106106 then do
107107 logm $ " Executing Stack GHC with args: " <> unwords args
108- catch (Just <$> tryCommand stackCmd) $ \ (_ :: IOException ) -> do
108+ catch (Just <$> tryCommand crdl stackCmd) $ \ (_ :: IOException ) -> do
109109 errorm $ " Command `" ++ stackCmd ++ " ` failed."
110110 execWithGhc
111111 -- The command `cabal v2-exec -v0 ghc` only works if the project has been
@@ -115,7 +115,7 @@ execProjectGhc crdl args = do
115115 --
116116 -- else if isCabalCradle crdl && isCabalInstalled then do
117117 -- let cmd = "cabal v2-exec -v0 ghc -- " ++ unwords args
118- -- catch (Just <$> tryCommand cmd) $ \(_ ::IOException) -> do
118+ -- catch (Just <$> tryCommand crdl cmd) $ \(_ ::IOException) -> do
119119 -- errorm $ "Command `" ++ cmd ++ "` failed."
120120 -- return Nothing
121121 else do
@@ -128,13 +128,14 @@ execProjectGhc crdl args = do
128128 plainCmd = " ghc " ++ unwords args
129129
130130 execWithGhc =
131- catch (Just <$> tryCommand plainCmd) $ \ (_ :: IOException ) -> do
131+ catch (Just <$> tryCommand crdl plainCmd) $ \ (_ :: IOException ) -> do
132132 errorm $ " Command `" ++ plainCmd ++ " ` failed."
133133 return Nothing
134134
135- tryCommand :: String -> IO String
136- tryCommand cmd = do
137- (code, sout, serr) <- readCreateProcessWithExitCode (shell cmd) " "
135+ tryCommand :: Cradle CabalHelper -> String -> IO String
136+ tryCommand crdl cmd = do
137+ let p = (shell cmd) { cwd = Just (cradleRootDir crdl) }
138+ (code, sout, serr) <- readCreateProcessWithExitCode p " "
138139 case code of
139140 ExitFailure e -> do
140141 let errmsg = concat
0 commit comments