5
5
6
6
module Ide.Cradle where
7
7
8
+ import Control.Applicative (optional )
8
9
import Control.Exception
9
10
import Data.Foldable (toList )
10
11
import Data.Function ((&) )
@@ -21,7 +22,8 @@ import Distribution.Helper (Package, projectPackages, pUnits,
21
22
unChModuleName , Ex (.. ), ProjLoc (.. ),
22
23
QueryEnv , mkQueryEnv , runQuery ,
23
24
Unit , unitInfo , uiComponents ,
24
- ChEntrypoint (.. ), UnitInfo (.. ))
25
+ ChEntrypoint (.. ), UnitInfo (.. ),
26
+ qePrograms , ghcProgram )
25
27
import Distribution.Helper.Discover (findProjects , getDefaultDistDir )
26
28
import Ide.Logger
27
29
import HIE.Bios as Bios
@@ -31,7 +33,7 @@ import qualified HIE.Bios.Types as Bios
31
33
import System.Directory (getCurrentDirectory , canonicalizePath , findExecutable )
32
34
import System.Exit
33
35
import System.FilePath
34
- import System.Process (readCreateProcessWithExitCode , shell , CreateProcess (.. ))
36
+ import System.Process (readCreateProcessWithExitCode , shell , CreateProcess (.. ), proc )
35
37
36
38
37
39
-- ---------------------------------------------------------------------
@@ -470,7 +472,7 @@ cabalHelperCradle file = do
470
472
, componentRoot = cwd
471
473
, componentDependencies = []
472
474
}
473
- , runGhcCmd = \ _ -> pure CradleNone
475
+ , runGhcCmd = \ args -> readProcessWithCwd cwd " ghc " args " "
474
476
}
475
477
}
476
478
Just (Ex proj) -> do
@@ -519,7 +521,9 @@ cabalHelperCradle file = do
519
521
realPackage
520
522
normalisedPackageLocation
521
523
fp
522
- , runGhcCmd = \ _ -> pure CradleNone
524
+ , runGhcCmd = \ args -> do
525
+ let programs = qePrograms env
526
+ readProcessWithCwd normalisedPackageLocation (ghcProgram programs) args " "
523
527
}
524
528
}
525
529
@@ -908,3 +912,14 @@ cradleDisplay cradle = fromString result
908
912
name = Bios. actionName (Bios. cradleOptsProg cradle)
909
913
910
914
-- ---------------------------------------------------------------------
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