From 3f679480d356be30c912f3b971f3034e2cd9cb95 Mon Sep 17 00:00:00 2001 From: Samuel Pilz Date: Fri, 26 Jul 2019 11:22:43 +0200 Subject: [PATCH 1/2] fail installation if cabal-version is too low --- install/src/Cabal.hs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index c09527505..f92fc7d89 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -56,15 +56,14 @@ 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 <- liftIO (findExecutable "cabal") >>= \case + Nothing -> return False + Just _ -> do + checkCabal + return True -- 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 () From 6b5776e79a17a31334750097e7d53bb135b78466 Mon Sep 17 00:00:00 2001 From: Samuel Pilz Date: Fri, 26 Jul 2019 11:40:08 +0200 Subject: [PATCH 2/2] reafactor cabal-version-check in install script --- install/src/Cabal.hs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index f92fc7d89..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,11 +58,10 @@ cabalInstallHie versionNumber = do installCabal :: Action () installCabal = do -- try to find existing `cabal` executable with appropriate version - cabalExeOk <- liftIO (findExecutable "cabal") >>= \case - Nothing -> return False - Just _ -> do - checkCabal - return True + cabalExeOk <- do + c <- liftIO (findExecutable "cabal") + when (isJust c) checkCabal + return $ isJust c -- install `cabal-install` if not already installed unless cabalExeOk $ execStackShake_ ["install", "cabal-install"] @@ -68,7 +69,7 @@ installCabal = do -- | 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