@@ -47,7 +47,7 @@ import Control.Monad.Extra (unlessM)
47
47
import Control.Monad.Trans.Cont
48
48
import Control.Monad.Trans.Maybe
49
49
import Control.Monad.IO.Class
50
- import Data.Aeson ((.:) )
50
+ import Data.Aeson ((.:) , (.:?) )
51
51
import qualified Data.Aeson as Aeson
52
52
import qualified Data.Aeson.Types as Aeson
53
53
import Data.Bifunctor (first )
@@ -591,10 +591,13 @@ cabalCradle :: LogAction IO (WithSeverity Log) -> ResolvedCradles b -> FilePath
591
591
cabalCradle l cs wdir mc projectFile = do
592
592
res <- runCradleResultT $ callCabalPathForCompilerPath l (cradleBuildToolVersions cs) wdir projectFile
593
593
let
594
- ghcPath = case res of
595
- CradleSuccess path -> path
594
+ cabalPathOutput = case res of
595
+ CradleSuccess out -> out
596
596
_ -> Nothing
597
597
598
+ ghcPath = fst <$> cabalPathOutput
599
+ ghcVersion = snd =<< cabalPathOutput
600
+
598
601
runGhcCmd args = runCradleResultT $ do
599
602
case ghcPath of
600
603
Just p -> readProcessWithCwd_ l wdir p args " "
@@ -610,7 +613,7 @@ cabalCradle l cs wdir mc projectFile = do
610
613
pure $ CradleAction
611
614
{ actionName = Types. Cabal
612
615
, runCradle = \ fp ls -> do
613
- v <- getGhcVersion runGhcCmd
616
+ v <- maybe ( getGhcVersion runGhcCmd) ( pure . Just ) ghcVersion
614
617
runCradleResultT $ cabalAction cs wdir ghcPath v mc l projectFile fp ls
615
618
, runGhcCmd = runGhcCmd
616
619
}
@@ -853,22 +856,30 @@ cabalGhcDirs l cabalProject workDir = do
853
856
where
854
857
projectFileArgs = projectFileProcessArgs cabalProject
855
858
856
- callCabalPathForCompilerPath :: LogAction IO (WithSeverity Log ) -> BuildToolVersions -> FilePath -> CradleProjectConfig -> CradleLoadResultT IO (Maybe FilePath )
859
+ callCabalPathForCompilerPath :: LogAction IO (WithSeverity Log ) -> BuildToolVersions -> FilePath -> CradleProjectConfig -> CradleLoadResultT IO (Maybe ( FilePath , Maybe Version ) )
857
860
callCabalPathForCompilerPath l vs workDir projectFile = do
858
861
case isCabalPathSupported vs of
859
862
False -> pure Nothing
860
863
True -> do
861
864
let
862
865
args = [" path" , " --output-format=json" ] <> projectFileProcessArgs projectFile
863
866
bs = BS. fromStrict . T. encodeUtf8 . T. pack
864
- parse_compiler_path = Aeson. parseEither ((.: " compiler" ) >=> (.: " path" )) <=< Aeson. eitherDecode
865
-
866
867
compiler_info <- readProcessWithCwd_ l workDir " cabal" args " "
867
- case parse_compiler_path (bs compiler_info) of
868
+ let
869
+ parsed = do
870
+ json <- Aeson. eitherDecode (bs compiler_info)
871
+ flip Aeson. parseEither json $ \ o -> do
872
+ c <- o .: " compiler"
873
+ p <- c .: " path"
874
+ i <- c .:? " id"
875
+ let v = versionMaybe . T. unpack . T. takeWhileEnd (/= ' -' ) . T. pack =<< i
876
+ pure (p, v)
877
+
878
+ case parsed of
868
879
Left err -> do
869
880
liftIO $ l <& WithSeverity (LogCabalPath $ T. pack err) Warning
870
881
pure Nothing
871
- Right a -> pure a
882
+ Right a -> pure $ Just a
872
883
873
884
isCabalPathSupported :: BuildToolVersions -> Bool
874
885
isCabalPathSupported = maybe False (>= makeVersion [3 ,14 ]) . cabalVersion
0 commit comments