@@ -47,7 +47,7 @@ import Control.Monad.Extra (unlessM)
4747import Control.Monad.Trans.Cont
4848import Control.Monad.Trans.Maybe
4949import Control.Monad.IO.Class
50- import Data.Aeson ((.:) )
50+ import Data.Aeson ((.:) , (.:?) )
5151import qualified Data.Aeson as Aeson
5252import qualified Data.Aeson.Types as Aeson
5353import Data.Bifunctor (first )
@@ -592,10 +592,13 @@ cabalCradle :: LogAction IO (WithSeverity Log) -> ResolvedCradles b -> FilePath
592592cabalCradle l cs wdir mc projectFile = do
593593 res <- runCradleResultT $ callCabalPathForCompilerPath l (cradleBuildToolVersions cs) wdir projectFile
594594 let
595- ghcPath = case res of
596- CradleSuccess path -> path
595+ cabalPathOutput = case res of
596+ CradleSuccess out -> out
597597 _ -> Nothing
598598
599+ ghcPath = fst <$> cabalPathOutput
600+ ghcVersion = snd =<< cabalPathOutput
601+
599602 runGhcCmd args = runCradleResultT $ do
600603 case ghcPath of
601604 Just p -> readProcessWithCwd_ l wdir p args " "
@@ -611,7 +614,7 @@ cabalCradle l cs wdir mc projectFile = do
611614 pure $ CradleAction
612615 { actionName = Types. Cabal
613616 , runCradle = \ fp ls -> do
614- v <- getGhcVersion runGhcCmd
617+ v <- maybe ( getGhcVersion runGhcCmd) ( pure . Just ) ghcVersion
615618 runCradleResultT $ cabalAction cs wdir ghcPath v mc l projectFile fp ls
616619 , runGhcCmd = runGhcCmd
617620 }
@@ -854,22 +857,30 @@ cabalGhcDirs l cabalProject workDir = do
854857 where
855858 projectFileArgs = projectFileProcessArgs cabalProject
856859
857- callCabalPathForCompilerPath :: LogAction IO (WithSeverity Log ) -> BuildToolVersions -> FilePath -> CradleProjectConfig -> CradleLoadResultT IO (Maybe FilePath )
860+ callCabalPathForCompilerPath :: LogAction IO (WithSeverity Log ) -> BuildToolVersions -> FilePath -> CradleProjectConfig -> CradleLoadResultT IO (Maybe ( FilePath , Maybe Version ) )
858861callCabalPathForCompilerPath l vs workDir projectFile = do
859862 case isCabalPathSupported vs of
860863 False -> pure Nothing
861864 True -> do
862865 let
863866 args = [" path" , " --output-format=json" ] <> projectFileProcessArgs projectFile
864867 bs = BS. fromStrict . T. encodeUtf8 . T. pack
865- parse_compiler_path = Aeson. parseEither ((.: " compiler" ) >=> (.: " path" )) <=< Aeson. eitherDecode
866-
867868 compiler_info <- readProcessWithCwd_ l workDir " cabal" args " "
868- case parse_compiler_path (bs compiler_info) of
869+ let
870+ parsed = do
871+ json <- Aeson. eitherDecode (bs compiler_info)
872+ flip Aeson. parseEither json $ \ o -> do
873+ c <- o .: " compiler"
874+ p <- c .: " path"
875+ i <- c .:? " id"
876+ let v = versionMaybe . T. unpack . T. takeWhileEnd (/= ' -' ) . T. pack =<< i
877+ pure (p, v)
878+
879+ case parsed of
869880 Left err -> do
870881 liftIO $ l <& WithSeverity (LogCabalPath $ T. pack err) Warning
871882 pure Nothing
872- Right a -> pure a
883+ Right a -> pure $ Just a
873884
874885isCabalPathSupported :: BuildToolVersions -> Bool
875886isCabalPathSupported = maybe False (>= makeVersion [3 ,14 ]) . cabalVersion
0 commit comments