Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit edec0b3

Browse files
committed
Set current working directory when executing project ghc
1 parent bac1c20 commit edec0b3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

hie-plugin-api/Haskell/Ide/Engine/Cradle.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import Control.Exception
3030
import System.FilePath
3131
import System.Directory (getCurrentDirectory, canonicalizePath, findExecutable)
3232
import System.Exit
33-
import System.Process (readCreateProcessWithExitCode, shell)
33+
import System.Process (readCreateProcessWithExitCode, shell, CreateProcess(..))
3434

3535
import Haskell.Ide.Engine.Logger
3636

@@ -102,7 +102,7 @@ execProjectGhc crdl args = do
102102
ghcOutput <- if isStackCradle crdl && isStackInstalled
103103
then do
104104
logm $ "Executing Stack GHC with args: " <> unwords args
105-
catch (Just <$> tryCommand stackCmd) $ \(_ :: IOException) -> do
105+
catch (Just <$> tryCommand crdl stackCmd) $ \(_ :: IOException) -> do
106106
errorm $ "Command `" ++ stackCmd ++"` failed."
107107
execWithGhc
108108
-- The command `cabal v2-exec -v0 ghc` only works if the project has been
@@ -112,7 +112,7 @@ execProjectGhc crdl args = do
112112
--
113113
-- else if isCabalCradle crdl && isCabalInstalled then do
114114
-- let cmd = "cabal v2-exec -v0 ghc -- " ++ unwords args
115-
-- catch (Just <$> tryCommand cmd) $ \(_ ::IOException) -> do
115+
-- catch (Just <$> tryCommand crdl cmd) $ \(_ ::IOException) -> do
116116
-- errorm $ "Command `" ++ cmd ++ "` failed."
117117
-- return Nothing
118118
else do
@@ -125,13 +125,14 @@ execProjectGhc crdl args = do
125125
plainCmd = "ghc " ++ unwords args
126126

127127
execWithGhc =
128-
catch (Just <$> tryCommand plainCmd) $ \(_ :: IOException) -> do
128+
catch (Just <$> tryCommand crdl plainCmd) $ \(_ :: IOException) -> do
129129
errorm $ "Command `" ++ plainCmd ++"` failed."
130130
return Nothing
131131

132-
tryCommand :: String -> IO String
133-
tryCommand cmd = do
134-
(code, sout, serr) <- readCreateProcessWithExitCode (shell cmd) ""
132+
tryCommand :: Cradle -> String -> IO String
133+
tryCommand crdl cmd = do
134+
let p = (shell cmd) { cwd = Just (cradleRootDir crdl) }
135+
(code, sout, serr) <- readCreateProcessWithExitCode p ""
135136
case code of
136137
ExitFailure e -> do
137138
let errmsg = concat

0 commit comments

Comments
 (0)