Some refactorings

This commit is contained in:
jneira 2019-10-10 11:20:32 +02:00
parent d5c50b995b
commit 5e216282c0
3 changed files with 15 additions and 17 deletions

View File

@ -17,7 +17,6 @@ import Version
import Print
import Env
import Stack
import Debug.Trace
execCabal :: CmdResult r => [String] -> Action r
execCabal = execCabalWithOriginalPath
@ -76,19 +75,17 @@ cabalInstallHie versionNumber = do
++ minorVerExe
++ " to " ++ localBin
installCabal :: Action ()
installCabal = do
installCabalWithStack :: Action ()
installCabalWithStack = do
-- try to find existing `cabal` executable with appropriate version
cabalExeOk <- do
c <- withOriginalPath (liftIO (findExecutable "cabal"))
liftIO $ traceIO $ show c
when (isJust c) checkCabal
return $ isJust c
-- install `cabal-install` if not already installed
if cabalExeOk
then printLine "There is already a cabal executable in $PATH with the required minimum version."
else execStackShake_ ["install", "cabal-install"]
mbc <- withOriginalPath (liftIO (findExecutable "cabal"))
case mbc of
Just c -> do
checkCabal
printLine "There is already a cabal executable in $PATH with the required minimum version."
-- install `cabal-install` if not already installed
Nothing -> execStackShake_ ["install", "cabal-install"]
-- | check `cabal` has the required version
checkCabal :: Action ()
@ -122,7 +119,7 @@ cabalInstallNotSuportedFailMsg =
-- | Error message when the `cabal` binary is an older version
cabalInstallIsOldFailMsg :: String -> String
cabalInstallIsOldFailMsg cabalVersion =
"The `cabal` executable is outdated.\n"
"The `cabal` executable found in $PATH is outdated.\n"
++ "found version is `"
++ cabalVersion
++ "`.\n"

View File

@ -63,7 +63,7 @@ defaultMain = do
want ["short-help"]
-- general purpose targets
phony "submodules" updateSubmodules
phony "cabal" installCabal
phony "cabal" installCabalWithStack
phony "short-help" shortHelpMessage
phony "all" shortHelpMessage
phony "help" (helpMessage versions)

View File

@ -104,7 +104,7 @@ withOriginalPath :: Action a -> Action a
withOriginalPath action = do
mbPath <- liftIO (lookupEnv "PATH")
case (mbPath,isRunFromStack) of
case (mbPath, isRunFromStack) of
(Just paths, True) -> do
snapshotDir <- trimmedStdout <$> execStackShake ["path", "--snapshot-install-root"]
@ -122,7 +122,8 @@ withOriginalPath action = do
otherwise -> action
where removePathsContaining str path =
intercalate [searchPathSeparator] (filter (not.(isInfixOf str)) (splitPaths path))
joinPaths (filter (not.(isInfixOf str)) (splitPaths path))
joinPaths = intercalate [searchPathSeparator]
splitPaths s =
case dropWhile (== searchPathSeparator) s of
"" -> []