From ca64cf7e5f5258193647a49ca4f3f331cf2d5e62 Mon Sep 17 00:00:00 2001 From: jneira Date: Tue, 4 Feb 2020 08:22:28 +0100 Subject: [PATCH 1/2] Check there is one ghc in $PATH --- install/src/Cabal.hs | 3 ++- install/src/Env.hs | 16 ++++++++++++++++ install/src/HieInstall.hs | 25 +++++++++---------------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index 171cb7667..820abb34d 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -113,10 +113,11 @@ cabalInstallIsOldFailMsg cabalVersion = ++ versionToString requiredCabalVersion ++ "`." - requiredCabalVersion :: RequiredVersion requiredCabalVersion | isWindowsSystem = requiredCabalVersionForWindows | otherwise = [2, 4, 1, 0] requiredCabalVersionForWindows :: RequiredVersion requiredCabalVersionForWindows = [3, 0, 0, 0] + + diff --git a/install/src/Env.hs b/install/src/Env.hs index 037e51bc9..83c23b0fc 100644 --- a/install/src/Env.hs +++ b/install/src/Env.hs @@ -62,6 +62,22 @@ 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 to be able to build hie.\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 a5cc1fafa..d46e2bffe 100644 --- a/install/src/HieInstall.hs +++ b/install/src/HieInstall.hs @@ -78,34 +78,27 @@ defaultMain = do (\version -> phony ("hie-" ++ version) $ do need ["submodules"] need ["check"] - if isRunFromStack then do + if isRunFromStack then stackInstallHieWithErrMsg (Just version) else cabalInstallHie version ) - - phony "latest" (need ["hie-" ++ latestVersion]) - phony "hie" (need ["data", "latest"]) + + unless (null versions) $ do + phony "latest" (need ["hie-" ++ latestVersion]) + phony "hie" (need ["data", "latest"]) -- stack specific targets -- Default `stack.yaml` uses ghc-8.8.2 and we can't build hie in windows -- TODO: Enable for windows when it uses ghc-8.8.3 - when (isRunFromStack && not isWindowsSystem) $ do - + when (isRunFromStack && not isWindowsSystem) $ 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" From 3bc34d7bf6dca8f76a02e2c047545d305cc9a87b Mon Sep 17 00:00:00 2001 From: jneira Date: Tue, 4 Feb 2020 08:39:13 +0100 Subject: [PATCH 2/2] Remove new lines --- install/src/Cabal.hs | 2 -- 1 file changed, 2 deletions(-) diff --git a/install/src/Cabal.hs b/install/src/Cabal.hs index 820abb34d..72fd00b04 100644 --- a/install/src/Cabal.hs +++ b/install/src/Cabal.hs @@ -119,5 +119,3 @@ requiredCabalVersion | isWindowsSystem = requiredCabalVersionForWindows requiredCabalVersionForWindows :: RequiredVersion requiredCabalVersionForWindows = [3, 0, 0, 0] - -