Skip to content

Commit 754f6ff

Browse files
committed
Configure cabal-helper to use the new 'runGhcCmd' API
1 parent 9cab854 commit 754f6ff

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Ide/Cradle.hs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
module Ide.Cradle where
77

8+
import Control.Applicative (optional)
89
import Control.Exception
910
import Data.Foldable (toList)
1011
import Data.Function ((&))
@@ -21,7 +22,8 @@ import Distribution.Helper (Package, projectPackages, pUnits,
2122
unChModuleName, Ex(..), ProjLoc(..),
2223
QueryEnv, mkQueryEnv, runQuery,
2324
Unit, unitInfo, uiComponents,
24-
ChEntrypoint(..), UnitInfo(..))
25+
ChEntrypoint(..), UnitInfo(..),
26+
qePrograms, ghcProgram)
2527
import Distribution.Helper.Discover (findProjects, getDefaultDistDir)
2628
import Ide.Logger
2729
import HIE.Bios as Bios
@@ -31,7 +33,7 @@ import qualified HIE.Bios.Types as Bios
3133
import System.Directory (getCurrentDirectory, canonicalizePath, findExecutable)
3234
import System.Exit
3335
import System.FilePath
34-
import System.Process (readCreateProcessWithExitCode, shell, CreateProcess(..))
36+
import System.Process (readCreateProcessWithExitCode, shell, CreateProcess(..), proc)
3537

3638

3739
-- ---------------------------------------------------------------------
@@ -470,7 +472,7 @@ cabalHelperCradle file = do
470472
, componentRoot = cwd
471473
, componentDependencies = []
472474
}
473-
, runGhcCmd = \_ -> pure CradleNone
475+
, runGhcCmd = \args -> readProcessWithCwd cwd "ghc" args ""
474476
}
475477
}
476478
Just (Ex proj) -> do
@@ -519,7 +521,9 @@ cabalHelperCradle file = do
519521
realPackage
520522
normalisedPackageLocation
521523
fp
522-
, runGhcCmd = \_ -> pure CradleNone
524+
, runGhcCmd = \args -> do
525+
let programs = qePrograms env
526+
readProcessWithCwd normalisedPackageLocation (ghcProgram programs) args ""
523527
}
524528
}
525529

@@ -908,3 +912,14 @@ cradleDisplay cradle = fromString result
908912
name = Bios.actionName (Bios.cradleOptsProg cradle)
909913

910914
-- ---------------------------------------------------------------------
915+
-- | Wrapper around 'readCreateProcess' that sets the working directory
916+
readProcessWithCwd :: FilePath -> FilePath -> [String] -> String -> IO (CradleLoadResult String)
917+
readProcessWithCwd dir cmd args stdi = do
918+
let createProc = (proc cmd args) { cwd = Just dir }
919+
mResult <- optional $ readCreateProcessWithExitCode createProc stdi
920+
case mResult of
921+
Just (ExitSuccess, stdo, _) -> pure $ CradleSuccess stdo
922+
Just (exitCode, stdo, stde) -> pure $ CradleFail $
923+
CradleError [] exitCode ["Error when calling " <> cmd <> " " <> unwords args, stdo, stde]
924+
Nothing -> pure $ CradleFail $
925+
CradleError [] ExitSuccess ["Couldn't execute " <> cmd <> " " <> unwords args]

0 commit comments

Comments
 (0)