diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index c09527505..ee79a9de8 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -4,7 +4,9 @@ import Development.Shake import Development.Shake.Command import Development.Shake.FilePath import Control.Monad -import Data.Maybe ( isNothing ) +import Data.Maybe ( isNothing + , isJust + ) import Control.Monad.Extra ( whenMaybe ) import System.Directory ( findExecutable , copyFile @@ -56,20 +58,18 @@ cabalInstallHie versionNumber = do installCabal :: Action () installCabal = do -- try to find existing `cabal` executable with appropriate version - cabalExe <- liftIO (findExecutable "cabal") >>= \case - Nothing -> return Nothing - Just cabalExe -> do - cabalVersion <- trimmedStdout <$> execCabal ["--numeric-version"] - whenMaybe (checkVersion requiredCabalVersion cabalVersion) - $ return cabalExe + cabalExeOk <- do + c <- liftIO (findExecutable "cabal") + when (isJust c) checkCabal + return $ isJust c -- install `cabal-install` if not already installed - when (isNothing cabalExe) $ execStackShake_ ["install", "cabal-install"] + unless cabalExeOk $ execStackShake_ ["install", "cabal-install"] -- | check `stack` has the required version checkCabal :: Action () checkCabal = do - cabalVersion <- trimmedStdout <$> execCabal ["--numeric-version"] + cabalVersion <- getCabalVersion unless (checkVersion requiredCabalVersion cabalVersion) $ do printInStars $ cabalInstallIsOldFailMsg cabalVersion error $ stackExeIsOldFailMsg cabalVersion