From 9058d436aa6d158b1adab58d689cea4673be3a2a Mon Sep 17 00:00:00 2001 From: jneira Date: Tue, 4 Feb 2020 08:37:22 +0100 Subject: [PATCH] Check there is one ghc in $PATH --- install/src/Cabal.hs | 1 - install/src/Env.hs | 17 +++++++++++++++++ install/src/HieInstall.hs | 16 ++++------------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index c36fde1a77..46c97270f0 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -114,7 +114,6 @@ cabalInstallIsOldFailMsg cabalVersion = ++ versionToString requiredCabalVersion ++ "`." - requiredCabalVersion :: RequiredVersion requiredCabalVersion | isWindowsSystem = requiredCabalVersionForWindows | otherwise = [2, 4, 1, 0] diff --git a/install/src/Env.hs b/install/src/Env.hs index 037e51bc98..6da957f568 100644 --- a/install/src/Env.hs +++ b/install/src/Env.hs @@ -62,6 +62,23 @@ findInstalledGhcs = do -- filter out stack provided GHCs (assuming that stack programs path is the default one in linux) $ filter (not . isInfixOf ".stack" . snd) (knownGhcs ++ availableGhcs) +showInstalledGhcs :: MonadIO m => [(VersionNumber, GhcPath)] -> m () +showInstalledGhcs ghcPaths = do + let msg = "Found the following GHC paths: \n" + ++ unlines + (map (\(version, path) -> "ghc-" ++ version ++ ": " ++ path) + ghcPaths + ) + printInStars msg + +checkInstalledGhcs :: MonadIO m => [(VersionNumber, GhcPath)] -> m () +checkInstalledGhcs ghcPaths = when (null ghcPaths) $ do + let msg = "No ghc installations found in $PATH. \n" + ++ "The script requires at least one ghc in $PATH \n" + ++ " to be able to build haskell-language-server.\n" + printInStars msg + error msg + -- | Get the path to a GHC that has the version specified by `VersionNumber` -- If no such GHC can be found, Nothing is returned. -- First, it is checked whether there is a GHC with the name `ghc-$VersionNumber`. diff --git a/install/src/HieInstall.hs b/install/src/HieInstall.hs index d27022a641..87267de528 100644 --- a/install/src/HieInstall.hs +++ b/install/src/HieInstall.hs @@ -88,22 +88,14 @@ defaultMain = do phony "haskell-language-server" (need ["data", "latest"]) -- stack specific targets - when isRunFromStack $ do - + when isRunFromStack $ phony "dev" $ stackInstallHieWithErrMsg Nothing -- cabal specific targets when isRunFromCabal $ do - - phony "ghcs" $ do - let - msg = - "Found the following GHC paths: \n" - ++ unlines - (map (\(version, path) -> "ghc-" ++ version ++ ": " ++ path) - ghcPaths - ) - printInStars msg + -- It throws an error if there is no ghc in $PATH + checkInstalledGhcs ghcPaths + phony "ghcs" $ showInstalledGhcs ghcPaths -- macos specific targets phony "icu-macos-fix"