@@ -19,6 +19,7 @@ import Control.Monad.Extra ( unlessM
19
19
)
20
20
import Data.Maybe ( isJust )
21
21
import System.Directory ( findExecutable
22
+ , findExecutables
22
23
, listDirectory
23
24
)
24
25
import System.Environment ( getProgName
@@ -34,6 +35,8 @@ import Data.Maybe ( isNothing
34
35
import Data.List ( dropWhileEnd
35
36
, intersperse
36
37
, intercalate
38
+ , isInfixOf
39
+ , nubBy
37
40
, sort
38
41
)
39
42
import qualified Data.Text as T
@@ -42,7 +45,9 @@ import Data.Version ( parseVersion
42
45
, makeVersion
43
46
, showVersion
44
47
)
45
- import Data.Function ( (&) )
48
+ import Data.Function ( (&)
49
+ , on
50
+ )
46
51
import Text.ParserCombinators.ReadP ( readP_to_S )
47
52
48
53
type VersionNumber = String
@@ -143,7 +148,7 @@ main = do
143
148
forM_ ghcVersions cabalTest
144
149
145
150
forM_
146
- hieVersions
151
+ ghcVersions
147
152
(\ version -> phony (" cabal-hie-" ++ version) $ do
148
153
validateCabalNewInstallIsSupported
149
154
need [" submodules" ]
@@ -182,7 +187,7 @@ validateCabalNewInstallIsSupported = when isWindowsSystem $ do
182
187
183
188
configureCabal :: VersionNumber -> Action ()
184
189
configureCabal versionNumber = do
185
- ghcPath <- getGhcPath versionNumber >>= \ case
190
+ ghcPath <- getGhcPathOf versionNumber >>= \ case
186
191
Nothing -> do
187
192
liftIO $ putStrLn $ embedInStars (ghcVersionNotFoundFailMsg versionNumber)
188
193
error (ghcVersionNotFoundFailMsg versionNumber)
@@ -193,12 +198,18 @@ configureCabal versionNumber = do
193
198
findInstalledGhcs :: IO [(VersionNumber , GhcPath )]
194
199
findInstalledGhcs = do
195
200
hieVersions <- getHieVersions :: IO [VersionNumber ]
196
- mapMaybeM
197
- (\ version -> getGhcPath version >>= \ case
201
+ knownGhcs <- mapMaybeM
202
+ (\ version -> getGhcPathOf version >>= \ case
198
203
Nothing -> return Nothing
199
204
Just p -> return $ Just (version, p)
200
205
)
201
206
(reverse hieVersions)
207
+ availableGhcs <- getGhcPaths
208
+ return
209
+ -- nub by version. knownGhcs takes precedence.
210
+ $ nubBy ((==) `on` fst )
211
+ -- filter out stack provided GHCs
212
+ $ filter (not . isInfixOf " .stack" . snd ) (knownGhcs ++ availableGhcs)
202
213
203
214
cabalBuildHie :: VersionNumber -> Action ()
204
215
cabalBuildHie versionNumber = do
@@ -515,16 +526,19 @@ getStackGhcPathShake = do
515
526
-- First, it is checked whether there is a GHC with the name `ghc-$VersionNumber`.
516
527
-- If this yields no result, it is checked, whether the numeric-version of the `ghc`
517
528
-- command fits to the desired version.
518
- getGhcPath :: MonadIO m => VersionNumber -> m (Maybe GhcPath )
519
- getGhcPath ghcVersion = liftIO $
520
- findExecutable (" ghc-" ++ ghcVersion) >>= \ case
521
- Nothing -> do
522
- findExecutable " ghc" >>= \ case
523
- Nothing -> return Nothing
524
- Just p -> do
525
- Stdout version <- cmd p [" --numeric-version" ] :: IO (Stdout String )
526
- if ghcVersion == trim version then return $ Just p else return Nothing
527
- p -> return p
529
+ getGhcPathOf :: MonadIO m => VersionNumber -> m (Maybe GhcPath )
530
+ getGhcPathOf ghcVersion =
531
+ liftIO $ findExecutable (" ghc-" ++ ghcVersion) >>= \ case
532
+ Nothing -> lookup ghcVersion <$> getGhcPaths
533
+ path -> return path
534
+
535
+ -- | Get a list of GHCs that are available in $PATH
536
+ getGhcPaths :: MonadIO m => m [(VersionNumber , GhcPath )]
537
+ getGhcPaths = liftIO $ do
538
+ paths <- findExecutables " ghc"
539
+ forM paths $ \ path -> do
540
+ Stdout version <- cmd path [" --numeric-version" ]
541
+ return (trim version, path)
528
542
529
543
-- | Read the local install root of the stack project specified by the VersionNumber
530
544
-- Returns the filepath of the local install root.
0 commit comments