@@ -84,31 +84,31 @@ findCradle wfile = do
8484 runMaybeT (yamlConfig wdir)
8585
8686-- | Given root\/hie.yaml load the Cradle.
87- loadCradle :: FilePath -> IO (Cradle Void )
88- loadCradle = loadCradleWithOpts absurd
87+ loadCradle :: LogAction IO ( WithSeverity Log ) -> FilePath -> IO (Cradle Void )
88+ loadCradle l = loadCradleWithOpts l absurd
8989
9090-- | Given root\/foo\/bar.hs, load an implicit cradle
91- loadImplicitCradle :: Show a => FilePath -> IO (Cradle a )
92- loadImplicitCradle wfile = do
91+ loadImplicitCradle :: Show a => LogAction IO ( WithSeverity Log ) -> FilePath -> IO (Cradle a )
92+ loadImplicitCradle l wfile = do
9393 let wdir = takeDirectory wfile
9494 cfg <- runMaybeT (implicitConfig wdir)
9595 case cfg of
96- Just bc -> getCradle absurd bc
97- Nothing -> return $ defaultCradle wdir
96+ Just bc -> getCradle l absurd bc
97+ Nothing -> return $ defaultCradle l wdir
9898
9999-- | Finding 'Cradle'.
100100-- Find a cabal file by tracing ancestor directories.
101101-- Find a sandbox according to a cabal sandbox config
102102-- in a cabal directory.
103- loadCradleWithOpts :: (Yaml. FromJSON b , Show a ) => (b -> CradleAction a ) -> FilePath -> IO (Cradle a )
104- loadCradleWithOpts buildCustomCradle wfile = do
103+ loadCradleWithOpts :: (Yaml. FromJSON b , Show a ) => LogAction IO ( WithSeverity Log ) -> (b -> CradleAction a ) -> FilePath -> IO (Cradle a )
104+ loadCradleWithOpts l buildCustomCradle wfile = do
105105 cradleConfig <- readCradleConfig wfile
106- getCradle buildCustomCradle (cradleConfig, takeDirectory wfile)
106+ getCradle l buildCustomCradle (cradleConfig, takeDirectory wfile)
107107
108- getCradle :: Show a => (b -> CradleAction a ) -> (CradleConfig b , FilePath ) -> IO (Cradle a )
109- getCradle buildCustomCradle (cc, wdir) = do
108+ getCradle :: Show a => LogAction IO ( WithSeverity Log ) -> (b -> CradleAction a ) -> (CradleConfig b , FilePath ) -> IO (Cradle a )
109+ getCradle l buildCustomCradle (cc, wdir) = do
110110 rcs <- canonicalizeResolvedCradles wdir cs
111- resolvedCradlesToCradle buildCustomCradle wdir rcs
111+ resolvedCradlesToCradle l buildCustomCradle wdir rcs
112112 where
113113 cs = resolveCradleTree wdir cc
114114
@@ -147,36 +147,34 @@ data ProgramVersions =
147147 , ghcVersion :: Maybe Version
148148 }
149149
150- makeVersions :: ([String ] -> IO (CradleLoadResult String )) -> IO ProgramVersions
151- makeVersions ghc = do
152- cabalVersion <- unsafeInterleaveIO getCabalVersion
153- stackVersion <- unsafeInterleaveIO getStackVersion
150+ makeVersions :: LogAction IO ( WithSeverity Log ) -> FilePath -> ([String ] -> IO (CradleLoadResult String )) -> IO ProgramVersions
151+ makeVersions l wdir ghc = do
152+ cabalVersion <- unsafeInterleaveIO ( getCabalVersion l wdir)
153+ stackVersion <- unsafeInterleaveIO ( getStackVersion l wdir)
154154 ghcVersion <- unsafeInterleaveIO (getGhcVersion ghc)
155155 pure ProgramVersions {.. }
156156
157- getCabalVersion :: IO (Maybe Version )
158- getCabalVersion = do
159- let p = proc " cabal" [" --numeric-version" ]
160- res <- optional $ readCreateProcessWithExitCode p " "
157+ getCabalVersion :: LogAction IO (WithSeverity Log ) -> FilePath -> IO (Maybe Version )
158+ getCabalVersion l wdir = do
159+ res <- readProcessWithCwd l wdir " cabal" [" --numeric-version" ] " "
161160 case res of
162- Just ( ExitSuccess , stdo,_) ->
161+ CradleSuccess stdo ->
163162 pure $ versionMaybe stdo
164163 _ -> pure Nothing
165164
166- getStackVersion :: IO (Maybe Version )
167- getStackVersion = do
168- let p = proc " stack" [" --numeric-version" ]
169- res <- optional $ readCreateProcessWithExitCode p " "
165+ getStackVersion :: LogAction IO (WithSeverity Log ) -> FilePath -> IO (Maybe Version )
166+ getStackVersion l wdir = do
167+ res <- readProcessWithCwd l wdir " stack" [" --numeric-version" ] " "
170168 case res of
171- Just ( ExitSuccess , stdo,_) ->
169+ CradleSuccess stdo ->
172170 pure $ versionMaybe stdo
173171 _ -> pure Nothing
174172
175173getGhcVersion :: ([String ] -> IO (CradleLoadResult String )) -> IO (Maybe Version )
176174getGhcVersion ghc = do
177- res <- optional $ ghc [" --numeric-version" ]
175+ res <- ghc [" --numeric-version" ]
178176 case res of
179- Just ( CradleSuccess stdo) ->
177+ CradleSuccess stdo ->
180178 pure $ versionMaybe stdo
181179 _ -> pure Nothing
182180
@@ -194,9 +192,9 @@ addActionDeps deps =
194192 (\ (ComponentOptions os' dir ds) -> CradleSuccess (ComponentOptions os' dir (ds `union` deps)))
195193
196194
197- resolvedCradlesToCradle :: Show a => (b -> CradleAction a ) -> FilePath -> [ResolvedCradle b ] -> IO (Cradle a )
198- resolvedCradlesToCradle buildCustomCradle root cs = mdo
199- let run_ghc_cmd l args =
195+ resolvedCradlesToCradle :: Show a => LogAction IO ( WithSeverity Log ) -> (b -> CradleAction a ) -> FilePath -> [ResolvedCradle b ] -> IO (Cradle a )
196+ resolvedCradlesToCradle logger buildCustomCradle root cs = mdo
197+ let run_ghc_cmd args =
200198 -- We're being lazy here and just returning the ghc path for the
201199 -- first non-none cradle. This shouldn't matter in practice: all
202200 -- sub cradles should be using the same ghc version!
@@ -205,11 +203,10 @@ resolvedCradlesToCradle buildCustomCradle root cs = mdo
205203 (act: _) ->
206204 runGhcCmd
207205 act
208- l
209206 args
210- versions <- makeVersions (run_ghc_cmd mempty )
207+ versions <- makeVersions logger root run_ghc_cmd
211208 let rcs = ResolvedCradles root cs versions
212- cradleActions = [ (c, resolveCradleAction buildCustomCradle rcs root c) | c <- cs ]
209+ cradleActions = [ (c, resolveCradleAction logger buildCustomCradle rcs root c) | c <- cs ]
213210 err_msg fp
214211 = [" Multi Cradle: No prefixes matched"
215212 , " pwd: " ++ root
@@ -218,13 +215,14 @@ resolvedCradlesToCradle buildCustomCradle root cs = mdo
218215 ] ++ [show (prefix pf, actionName cc) | (pf, cc) <- cradleActions]
219216 pure $ Cradle
220217 { cradleRootDir = root
218+ , cradleLogger = logger
221219 , cradleOptsProg = CradleAction
222220 { actionName = multiActionName
223- , runCradle = \ l fp prev -> do
221+ , runCradle = \ fp prev -> do
224222 absfp <- makeAbsolute fp
225223 case selectCradle (prefix . fst ) absfp cradleActions of
226224 Just (rc, act) -> do
227- addActionDeps (cradleDeps rc) <$> runCradle act l fp prev
225+ addActionDeps (cradleDeps rc) <$> runCradle act fp prev
228226 Nothing -> return $ CradleFail $ CradleError [] ExitSuccess (err_msg fp)
229227 , runGhcCmd = run_ghc_cmd
230228 }
@@ -266,13 +264,13 @@ resolvedCradlesToCradle buildCustomCradle root cs = mdo
266264 notNoneType _ = True
267265
268266
269- resolveCradleAction :: (b -> CradleAction a ) -> ResolvedCradles b -> FilePath -> ResolvedCradle b -> CradleAction a
270- resolveCradleAction buildCustomCradle cs root cradle =
267+ resolveCradleAction :: LogAction IO ( WithSeverity Log ) -> (b -> CradleAction a ) -> ResolvedCradles b -> FilePath -> ResolvedCradle b -> CradleAction a
268+ resolveCradleAction l buildCustomCradle cs root cradle =
271269 case concreteCradle cradle of
272- ConcreteCabal t -> cabalCradle cs root (cabalComponent t) (projectConfigFromMaybe root (cabalProjectFile t))
273- ConcreteStack t -> stackCradle root (stackComponent t) (projectConfigFromMaybe root (stackYaml t))
274- ConcreteBios bios deps mbGhc -> biosCradle root bios deps mbGhc
275- ConcreteDirect xs -> directCradle root xs
270+ ConcreteCabal t -> cabalCradle l cs root (cabalComponent t) (projectConfigFromMaybe root (cabalProjectFile t))
271+ ConcreteStack t -> stackCradle l root (stackComponent t) (projectConfigFromMaybe root (stackYaml t))
272+ ConcreteBios bios deps mbGhc -> biosCradle l root bios deps mbGhc
273+ ConcreteDirect xs -> directCradle l root xs
276274 ConcreteNone -> noneCradle
277275 ConcreteOther a -> buildCustomCradle a
278276
@@ -391,15 +389,16 @@ isOtherCradle crdl = case actionName (cradleOptsProg crdl) of
391389
392390-- | Default cradle has no special options, not very useful for loading
393391-- modules.
394- defaultCradle :: FilePath -> Cradle a
395- defaultCradle cur_dir =
392+ defaultCradle :: LogAction IO ( WithSeverity Log ) -> FilePath -> Cradle a
393+ defaultCradle l cur_dir =
396394 Cradle
397395 { cradleRootDir = cur_dir
396+ , cradleLogger = l
398397 , cradleOptsProg = CradleAction
399398 { actionName = Types. Default
400- , runCradle = \ _ _ _ ->
399+ , runCradle = \ _ _ ->
401400 return (CradleSuccess (ComponentOptions argDynamic cur_dir [] ))
402- , runGhcCmd = \ l -> runGhcCmdOnPath l cur_dir
401+ , runGhcCmd = runGhcCmdOnPath l cur_dir
403402 }
404403 }
405404
@@ -410,8 +409,8 @@ noneCradle :: CradleAction a
410409noneCradle =
411410 CradleAction
412411 { actionName = Types. None
413- , runCradle = \ _ _ _ -> return CradleNone
414- , runGhcCmd = \ _ _ -> return CradleNone
412+ , runCradle = \ _ _ -> return CradleNone
413+ , runGhcCmd = \ _ -> return CradleNone
415414 }
416415
417416---------------------------------------------------------------
@@ -435,13 +434,13 @@ selectCradle k cur_fp (c: css) =
435434
436435-------------------------------------------------------------------------
437436
438- directCradle :: FilePath -> [String ] -> CradleAction a
439- directCradle wdir args
437+ directCradle :: LogAction IO ( WithSeverity Log ) -> FilePath -> [String ] -> CradleAction a
438+ directCradle l wdir args
440439 = CradleAction
441440 { actionName = Types. Direct
442- , runCradle = \ _ _ _ ->
441+ , runCradle = \ _ _ ->
443442 return (CradleSuccess (ComponentOptions (args ++ argDynamic) wdir [] ))
444- , runGhcCmd = \ l -> runGhcCmdOnPath l wdir
443+ , runGhcCmd = runGhcCmdOnPath l wdir
445444 }
446445
447446
@@ -450,12 +449,12 @@ directCradle wdir args
450449
451450-- | Find a cradle by finding an executable `hie-bios` file which will
452451-- be executed to find the correct GHC options to use.
453- biosCradle :: FilePath -> Callable -> Maybe Callable -> Maybe FilePath -> CradleAction a
454- biosCradle wdir biosCall biosDepsCall mbGhc
452+ biosCradle :: LogAction IO ( WithSeverity Log ) -> FilePath -> Callable -> Maybe Callable -> Maybe FilePath -> CradleAction a
453+ biosCradle l wdir biosCall biosDepsCall mbGhc
455454 = CradleAction
456455 { actionName = Types. Bios
457- , runCradle = biosAction wdir biosCall biosDepsCall
458- , runGhcCmd = \ l args -> readProcessWithCwd l wdir (fromMaybe " ghc" mbGhc) args " "
456+ , runCradle = biosAction wdir biosCall biosDepsCall l
457+ , runGhcCmd = \ args -> readProcessWithCwd l wdir (fromMaybe " ghc" mbGhc) args " "
459458 }
460459
461460biosWorkDir :: FilePath -> MaybeT IO FilePath
@@ -513,12 +512,12 @@ projectLocationOrDefault = \case
513512
514513-- | Cabal Cradle
515514-- Works for new-build by invoking `v2-repl`.
516- cabalCradle :: ResolvedCradles b -> FilePath -> Maybe String -> CradleProjectConfig -> CradleAction a
517- cabalCradle cs wdir mc projectFile
515+ cabalCradle :: LogAction IO ( WithSeverity Log ) -> ResolvedCradles b -> FilePath -> Maybe String -> CradleProjectConfig -> CradleAction a
516+ cabalCradle l cs wdir mc projectFile
518517 = CradleAction
519518 { actionName = Types. Cabal
520- , runCradle = \ l fp -> runCradleResultT . cabalAction cs wdir mc l projectFile fp
521- , runGhcCmd = \ l args -> runCradleResultT $ do
519+ , runCradle = \ fp -> runCradleResultT . cabalAction cs wdir mc l projectFile fp
520+ , runGhcCmd = \ args -> runCradleResultT $ do
522521 buildDir <- liftIO $ cabalBuildDir wdir
523522 -- Workaround for a cabal-install bug on 3.0.0.0:
524523 -- ./dist-newstyle/tmp/environment.-24811: createDirectory: does not exist (No such file or directory)
@@ -906,12 +905,12 @@ stackYamlLocationOrDefault (ExplicitConfig yaml) = yaml
906905
907906-- | Stack Cradle
908907-- Works for by invoking `stack repl` with a wrapper script
909- stackCradle :: FilePath -> Maybe String -> CradleProjectConfig -> CradleAction a
910- stackCradle wdir mc syaml =
908+ stackCradle :: LogAction IO ( WithSeverity Log ) -> FilePath -> Maybe String -> CradleProjectConfig -> CradleAction a
909+ stackCradle l wdir mc syaml =
911910 CradleAction
912911 { actionName = Types. Stack
913- , runCradle = stackAction wdir mc syaml
914- , runGhcCmd = \ l args -> runCradleResultT $ do
912+ , runCradle = stackAction wdir mc syaml l
913+ , runGhcCmd = \ args -> runCradleResultT $ do
915914 -- Setup stack silently, since stack might print stuff to stdout in some cases (e.g. on Win)
916915 -- Issue 242 from HLS: https://github.com/haskell/haskell-language-server/issues/242
917916 _ <- readProcessWithCwd_ l wdir " stack" (stackYamlProcessArgs syaml <> [" setup" , " --silent" ]) " "
0 commit comments