@@ -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 )
@@ -540,10 +540,13 @@ cabalCradle :: LogAction IO (WithSeverity Log) -> ResolvedCradles b -> FilePath
540
540
cabalCradle l cs wdir mc projectFile = do
541
541
res <- runCradleResultT $ callCabalPathForCompilerPath l (cradleBuildToolVersions cs) wdir projectFile
542
542
let
543
- ghcPath = case res of
544
- CradleSuccess path -> path
543
+ cabalPathOutput = case res of
544
+ CradleSuccess out -> out
545
545
_ -> Nothing
546
546
547
+ ghcPath = fst <$> cabalPathOutput
548
+ ghcVersion = snd =<< cabalPathOutput
549
+
547
550
runGhcCmd args = runCradleResultT $ do
548
551
case ghcPath of
549
552
Just p -> readProcessWithCwd_ l wdir p args " "
@@ -559,7 +562,7 @@ cabalCradle l cs wdir mc projectFile = do
559
562
pure $ CradleAction
560
563
{ actionName = Types. Cabal
561
564
, runCradle = \ fp ls -> do
562
- v <- getGhcVersion runGhcCmd
565
+ v <- maybe ( getGhcVersion runGhcCmd) ( pure . Just ) ghcVersion
563
566
runCradleResultT $ cabalAction cs wdir ghcPath v mc l projectFile fp ls
564
567
, runGhcCmd = runGhcCmd
565
568
}
@@ -808,22 +811,30 @@ cabalGhcDirs l cabalProject workDir = do
808
811
where
809
812
projectFileArgs = projectFileProcessArgs cabalProject
810
813
811
- callCabalPathForCompilerPath :: LogAction IO (WithSeverity Log ) -> BuildToolVersions -> FilePath -> CradleProjectConfig -> CradleLoadResultT IO (Maybe FilePath )
814
+ callCabalPathForCompilerPath :: LogAction IO (WithSeverity Log ) -> BuildToolVersions -> FilePath -> CradleProjectConfig -> CradleLoadResultT IO (Maybe ( FilePath , Maybe Version ) )
812
815
callCabalPathForCompilerPath l vs workDir projectFile = do
813
816
case isCabalPathSupported vs of
814
817
False -> pure Nothing
815
818
True -> do
816
819
let
817
820
args = [" path" , " --output-format=json" ] <> projectFileProcessArgs projectFile
818
821
bs = BS. fromStrict . T. encodeUtf8 . T. pack
819
- parse_compiler_path = Aeson. parseEither ((.: " compiler" ) >=> (.: " path" )) <=< Aeson. eitherDecode
820
-
821
822
compiler_info <- readProcessWithCwd_ l workDir " cabal" args " "
822
- case parse_compiler_path (bs compiler_info) of
823
+ let
824
+ parsed = do
825
+ json <- Aeson. eitherDecode (bs compiler_info)
826
+ flip Aeson. parseEither json $ \ o -> do
827
+ c <- o .: " compiler"
828
+ p <- c .: " path"
829
+ i <- c .:? " id"
830
+ let v = versionMaybe . T. unpack . T. takeWhileEnd (/= ' -' ) . T. pack =<< i
831
+ pure (p, v)
832
+
833
+ case parsed of
823
834
Left err -> do
824
835
liftIO $ l <& WithSeverity (LogCabalPath $ T. pack err) Warning
825
836
pure Nothing
826
- Right a -> pure a
837
+ Right a -> pure $ Just a
827
838
828
839
isCabalPathSupported :: BuildToolVersions -> Bool
829
840
isCabalPathSupported = maybe False (>= makeVersion [3 ,14 ]) . cabalVersion
0 commit comments