@@ -284,15 +284,22 @@ resolvedCradlesToCradle logger buildCustomCradle root cs = mdo
284284 notNoneType _ = True
285285
286286
287- resolveCradleAction :: LogAction IO (WithSeverity Log ) -> (b -> CradleAction a ) -> ResolvedCradles b -> FilePath -> ResolvedCradle b -> CradleAction a
288- resolveCradleAction l buildCustomCradle cs root cradle =
287+ resolveCradleAction :: Show a => LogAction IO (WithSeverity Log ) -> (b -> CradleAction a ) -> ResolvedCradles b -> FilePath -> ResolvedCradle b -> CradleAction a
288+ resolveCradleAction l buildCustomCradle cs root cradle = addLoadStyleLogToCradleAction $
289289 case concreteCradle cradle of
290290 ConcreteCabal t -> cabalCradle l cs root (cabalComponent t) (projectConfigFromMaybe root (cabalProjectFile t))
291291 ConcreteStack t -> stackCradle l root (stackComponent t) (projectConfigFromMaybe root (stackYaml t))
292292 ConcreteBios bios deps mbGhc -> biosCradle l root bios deps mbGhc
293293 ConcreteDirect xs -> directCradle l root xs
294294 ConcreteNone -> noneCradle
295295 ConcreteOther a -> buildCustomCradle a
296+ where
297+ -- Add a log message to each loading operation.
298+ addLoadStyleLogToCradleAction crdlAct = crdlAct
299+ { runCradle = \ fp ls -> do
300+ l <& LogRequestedCradleLoadStyle (T. pack $ show $ actionName crdlAct) ls `WithSeverity ` Debug
301+ runCradle crdlAct fp ls
302+ }
296303
297304resolveCradleTree :: FilePath -> CradleConfig a -> [ResolvedCradle a ]
298305resolveCradleTree root (CradleConfig confDeps confTree) = go root confDeps confTree
@@ -458,7 +465,8 @@ directCradle :: LogAction IO (WithSeverity Log) -> FilePath -> [String] -> Cradl
458465directCradle l wdir args
459466 = CradleAction
460467 { actionName = Types. Direct
461- , runCradle = \ _ _ ->
468+ , runCradle = \ _ loadStyle -> do
469+ logCradleHasNoSupportForLoadWithContext l loadStyle " direct"
462470 return (CradleSuccess (ComponentOptions (args ++ argDynamic) wdir [] ))
463471 , runGhcCmd = runGhcCmdOnPath l wdir
464472 }
@@ -480,7 +488,7 @@ biosCradle l wdir biosCall biosDepsCall mbGhc
480488biosWorkDir :: FilePath -> MaybeT IO FilePath
481489biosWorkDir = findFileUpwards (" .hie-bios" == )
482490
483- biosDepsAction :: LogAction IO (WithSeverity Log ) -> FilePath -> Maybe Callable -> FilePath -> [ FilePath ] -> IO [FilePath ]
491+ biosDepsAction :: LogAction IO (WithSeverity Log ) -> FilePath -> Maybe Callable -> FilePath -> LoadStyle -> IO [FilePath ]
484492biosDepsAction l wdir (Just biosDepsCall) fp _prevs = do
485493 biosDeps' <- callableToProcess biosDepsCall (Just fp) -- TODO multi pass the previous files too
486494 (ex, sout, serr, [(_, args)]) <- readProcessWithOutputs [hie_bios_output] l wdir biosDeps'
@@ -495,16 +503,17 @@ biosAction
495503 -> Maybe Callable
496504 -> LogAction IO (WithSeverity Log )
497505 -> FilePath
498- -> [ FilePath ]
506+ -> LoadStyle
499507 -> IO (CradleLoadResult ComponentOptions )
500- biosAction wdir bios bios_deps l fp fps = do
508+ biosAction wdir bios bios_deps l fp loadStyle = do
509+ logCradleHasNoSupportForLoadWithContext l loadStyle " bios"
501510 bios' <- callableToProcess bios (Just fp) -- TODO pass all the files instead of listToMaybe
502511 (ex, _stdo, std, [(_, res),(_, mb_deps)]) <-
503512 readProcessWithOutputs [hie_bios_output, hie_bios_deps] l wdir bios'
504513
505514 deps <- case mb_deps of
506515 Just x -> return x
507- Nothing -> biosDepsAction l wdir bios_deps fp fps
516+ Nothing -> biosDepsAction l wdir bios_deps fp loadStyle
508517 -- Output from the program should be written to the output file and
509518 -- delimited by newlines.
510519 -- Execute the bios action and add dependencies of the cradle.
@@ -779,42 +788,56 @@ cabalGhcDirs l cabalProject workDir = do
779788 where
780789 projectFileArgs = projectFileProcessArgs cabalProject
781790
782-
783791cabalAction
784792 :: ResolvedCradles a
785793 -> FilePath
786794 -> Maybe String
787795 -> LogAction IO (WithSeverity Log )
788796 -> CradleProjectConfig
789797 -> FilePath
790- -> [ FilePath ]
798+ -> LoadStyle
791799 -> CradleLoadResultT IO ComponentOptions
792- cabalAction (ResolvedCradles root cs vs) workDir mc l projectFile fp fps = do
800+ cabalAction (ResolvedCradles root cs vs) workDir mc l projectFile fp loadStyle = do
793801 cabal_version <- liftIO $ runCachedIO $ cabalVersion vs
794802 ghc_version <- liftIO $ runCachedIO $ ghcVersion vs
803+ -- determine which load style is supported by this cabal cradle.
804+ determinedLoadStyle <- case (cabal_version, ghc_version) of
805+ (Just cabal, Just ghc)
806+ -- Multi-component supported from cabal-install 3.11
807+ -- and ghc 9.4
808+ | LoadWithContext _ <- loadStyle ->
809+ if ghc >= makeVersion [9 ,4 ] && cabal >= makeVersion [3 ,11 ]
810+ then pure loadStyle
811+ else do
812+ liftIO $ l <& WithSeverity
813+ (LogLoadWithContextUnsupported " cabal"
814+ $ Just " cabal or ghc version is too old. We require `cabal >= 3.11` and `ghc >= 9.4`"
815+ )
816+ Warning
817+ pure LoadFile
818+ _ -> pure LoadFile
819+
820+ let cabalArgs = case determinedLoadStyle of
821+ LoadFile -> [fromMaybe (fixTargetPath fp) mc]
822+ LoadWithContext fps -> concat
823+ [ [ " --keep-temp-files"
824+ , " --enable-multi-repl"
825+ , fromMaybe (fixTargetPath fp) mc
826+ ]
827+ , [fromMaybe (fixTargetPath old_fp) old_mc
828+ | old_fp <- fps
829+ -- Lookup the component for the old file
830+ , Just (ResolvedCradle {concreteCradle = ConcreteCabal ct}) <- [selectCradle prefix old_fp cs]
831+ -- Only include this file if the old component is in the same project
832+ , (projectConfigFromMaybe root (cabalProjectFile ct)) == projectFile
833+ , let old_mc = cabalComponent ct
834+ ]
835+ ]
836+
837+ liftIO $ l <& LogComputedCradleLoadStyle " cabal" determinedLoadStyle `WithSeverity ` Info
838+
795839 let
796840 cabalCommand = " v2-repl"
797- cabalArgs = case (cabal_version, ghc_version) of
798- (Just cabal, Just ghc)
799- -- Multi-component supported from cabal-install 3.11
800- -- and ghc 9.4
801- | ghc >= makeVersion [9 ,4 ]
802- , cabal >= makeVersion [3 ,11 ]
803- -> case fps of
804- [] -> [fromMaybe (fixTargetPath fp) mc]
805- -- Start a multi-component session with all the old files
806- _ -> " --keep-temp-files"
807- : " --enable-multi-repl"
808- : fromMaybe (fixTargetPath fp) mc
809- : [fromMaybe (fixTargetPath old_fp) old_mc
810- | old_fp <- fps
811- -- Lookup the component for the old file
812- , Just (ResolvedCradle {concreteCradle = ConcreteCabal ct}) <- [selectCradle prefix old_fp cs]
813- -- Only include this file if the old component is in the same project
814- , (projectConfigFromMaybe root (cabalProjectFile ct)) == projectFile
815- , let old_mc = cabalComponent ct
816- ]
817- _ -> [fromMaybe (fixTargetPath fp) mc]
818841
819842 cabalProc <- cabalProcess l projectFile workDir cabalCommand cabalArgs `modCradleError` \ err -> do
820843 deps <- cabalCradleDependencies projectFile workDir workDir
@@ -843,8 +866,7 @@ cabalAction (ResolvedCradles root cs vs) workDir mc l projectFile fp fps = do
843866 -- Best effort. Assume the working directory is the
844867 -- root of the component, so we are right in trivial cases at least.
845868 deps <- liftIO $ cabalCradleDependencies projectFile workDir workDir
846- throwCE (CradleError deps ex $
847- ([" Failed to parse result of calling cabal" ] <> errorDetails))
869+ throwCE (CradleError deps ex $ [" Failed to parse result of calling cabal" ] <> errorDetails)
848870 Just (componentDir, final_args) -> do
849871 deps <- liftIO $ cabalCradleDependencies projectFile workDir componentDir
850872 CradleLoadResultT $ pure $ makeCradleResult (ex, stde, componentDir, final_args) deps
@@ -963,9 +985,10 @@ stackAction
963985 -> CradleProjectConfig
964986 -> LogAction IO (WithSeverity Log )
965987 -> FilePath
966- -> [ FilePath ]
988+ -> LoadStyle
967989 -> IO (CradleLoadResult ComponentOptions )
968- stackAction workDir mc syaml l _fp _fps = do
990+ stackAction workDir mc syaml l _fp loadStyle = do
991+ logCradleHasNoSupportForLoadWithContext l loadStyle " stack"
969992 let ghcProcArgs = (" stack" , stackYamlProcessArgs syaml <> [" exec" , " ghc" , " --" ])
970993 -- Same wrapper works as with cabal
971994 wrapper_fp <- withGhcWrapperTool l ghcProcArgs workDir
@@ -1234,3 +1257,14 @@ readProcessWithCwd' l createdProcess stdin = do
12341257 Nothing -> throwCE $
12351258 CradleError [] ExitSuccess $
12361259 [" Couldn't execute " <> cmdString] <> prettyProcessEnv createdProcess
1260+
1261+ -- | Log that the cradle has no supported for loading with context, if and only if
1262+ -- 'LoadWithContext' was requested.
1263+ logCradleHasNoSupportForLoadWithContext :: Applicative m => LogAction m (WithSeverity Log ) -> LoadStyle -> T. Text -> m ()
1264+ logCradleHasNoSupportForLoadWithContext l (LoadWithContext _) crdlName =
1265+ l <& WithSeverity
1266+ (LogLoadWithContextUnsupported crdlName
1267+ $ Just $ crdlName <> " doesn't support loading multiple components at once"
1268+ )
1269+ Info
1270+ logCradleHasNoSupportForLoadWithContext _ _ _ = pure ()
0 commit comments