mirror of
https://github.com/haskell/haskell-ide-engine.git
synced 2024-10-26 11:18:42 +03:00
Some refactorings
This commit is contained in:
parent
d5c50b995b
commit
5e216282c0
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
"" -> []
|
||||
|
Loading…
Reference in New Issue
Block a user