Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 6b5776e

Browse files
committed
reafactor cabal-version-check in install script
1 parent 3f67948 commit 6b5776e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

install/src/Cabal.hs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import Development.Shake
44
import Development.Shake.Command
55
import Development.Shake.FilePath
66
import Control.Monad
7-
import Data.Maybe ( isNothing )
7+
import Data.Maybe ( isNothing
8+
, isJust
9+
)
810
import Control.Monad.Extra ( whenMaybe )
911
import System.Directory ( findExecutable
1012
, copyFile
@@ -56,19 +58,18 @@ cabalInstallHie versionNumber = do
5658
installCabal :: Action ()
5759
installCabal = do
5860
-- try to find existing `cabal` executable with appropriate version
59-
cabalExeOk <- liftIO (findExecutable "cabal") >>= \case
60-
Nothing -> return False
61-
Just _ -> do
62-
checkCabal
63-
return True
61+
cabalExeOk <- do
62+
c <- liftIO (findExecutable "cabal")
63+
when (isJust c) checkCabal
64+
return $ isJust c
6465

6566
-- install `cabal-install` if not already installed
6667
unless cabalExeOk $ execStackShake_ ["install", "cabal-install"]
6768

6869
-- | check `stack` has the required version
6970
checkCabal :: Action ()
7071
checkCabal = do
71-
cabalVersion <- trimmedStdout <$> execCabal ["--numeric-version"]
72+
cabalVersion <- getCabalVersion
7273
unless (checkVersion requiredCabalVersion cabalVersion) $ do
7374
printInStars $ cabalInstallIsOldFailMsg cabalVersion
7475
error $ stackExeIsOldFailMsg cabalVersion

0 commit comments

Comments
 (0)