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

fail installation if cabal-version is too low #1344

Merged
merged 2 commits into from
Aug 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions install/src/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down