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

Commit caf7223

Browse files
authored
Merge pull request #1632 from jneira/install-check-ghcs
Install script with cabal: check there is one ghc in $PATH
2 parents 98485c3 + 3bc34d7 commit caf7223

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

install/src/Cabal.hs

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ cabalInstallIsOldFailMsg cabalVersion =
113113
++ versionToString requiredCabalVersion
114114
++ "`."
115115

116-
117116
requiredCabalVersion :: RequiredVersion
118117
requiredCabalVersion | isWindowsSystem = requiredCabalVersionForWindows
119118
| otherwise = [2, 4, 1, 0]

install/src/Env.hs

+16
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ findInstalledGhcs = do
6262
-- filter out stack provided GHCs (assuming that stack programs path is the default one in linux)
6363
$ filter (not . isInfixOf ".stack" . snd) (knownGhcs ++ availableGhcs)
6464

65+
showInstalledGhcs :: MonadIO m => [(VersionNumber, GhcPath)] -> m ()
66+
showInstalledGhcs ghcPaths = do
67+
let msg = "Found the following GHC paths: \n"
68+
++ unlines
69+
(map (\(version, path) -> "ghc-" ++ version ++ ": " ++ path)
70+
ghcPaths
71+
)
72+
printInStars msg
73+
74+
checkInstalledGhcs :: MonadIO m => [(VersionNumber, GhcPath)] -> m ()
75+
checkInstalledGhcs ghcPaths = when (null ghcPaths) $ do
76+
let msg = "No ghc installations found in $PATH. \n"
77+
++ "The script requires at least one ghc in $PATH to be able to build hie.\n"
78+
printInStars msg
79+
error msg
80+
6581
-- | Get the path to a GHC that has the version specified by `VersionNumber`
6682
-- If no such GHC can be found, Nothing is returned.
6783
-- First, it is checked whether there is a GHC with the name `ghc-$VersionNumber`.

install/src/HieInstall.hs

+9-16
Original file line numberDiff line numberDiff line change
@@ -78,34 +78,27 @@ defaultMain = do
7878
(\version -> phony ("hie-" ++ version) $ do
7979
need ["submodules"]
8080
need ["check"]
81-
if isRunFromStack then do
81+
if isRunFromStack then
8282
stackInstallHieWithErrMsg (Just version)
8383
else
8484
cabalInstallHie version
8585
)
86-
87-
phony "latest" (need ["hie-" ++ latestVersion])
88-
phony "hie" (need ["data", "latest"])
86+
87+
unless (null versions) $ do
88+
phony "latest" (need ["hie-" ++ latestVersion])
89+
phony "hie" (need ["data", "latest"])
8990

9091
-- stack specific targets
9192
-- Default `stack.yaml` uses ghc-8.8.2 and we can't build hie in windows
9293
-- TODO: Enable for windows when it uses ghc-8.8.3
93-
when (isRunFromStack && not isWindowsSystem) $ do
94-
94+
when (isRunFromStack && not isWindowsSystem) $
9595
phony "dev" $ stackInstallHieWithErrMsg Nothing
9696

9797
-- cabal specific targets
9898
when isRunFromCabal $ do
99-
100-
phony "ghcs" $ do
101-
let
102-
msg =
103-
"Found the following GHC paths: \n"
104-
++ unlines
105-
(map (\(version, path) -> "ghc-" ++ version ++ ": " ++ path)
106-
ghcPaths
107-
)
108-
printInStars msg
99+
-- It throws an error if there is no ghc in $PATH
100+
checkInstalledGhcs ghcPaths
101+
phony "ghcs" $ showInstalledGhcs ghcPaths
109102

110103
-- macos specific targets
111104
phony "icu-macos-fix"

0 commit comments

Comments
 (0)