Improve ghc version check (#535)

- retrieve runtime version from ghc executable, not from pkg db (ghc-check 0.3.0.0)
- Do not error when unable to retrieve runtime version
This commit is contained in:
Pepe Iborra 2020-05-08 14:48:05 +01:00 committed by GitHub
parent 6a650be7e3
commit 15bb044269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 19 deletions

View File

@ -15,7 +15,6 @@ import Data.ByteString.Base16 (encode)
import qualified Data.ByteString.Char8 as B
import Data.Functor ((<&>))
import Data.Text (Text, pack)
import Data.Version (Version)
import Development.IDE.Core.Rules (defineNoFile)
import Development.IDE.Core.Service (getIdeOptions)
import Development.IDE.Core.Shake (actionLogger, sendEvent, define, useNoFile_)
@ -24,7 +23,7 @@ import Development.IDE.Types.Location (fromNormalizedFilePath)
import Development.IDE.Types.Options (IdeOptions(IdeOptions, optTesting))
import Development.Shake
import GHC
import GHC.Check (runTimeVersion, compileTimeVersionFromLibdir)
import GHC.Check (VersionCheck(..), makeGhcVersionChecker)
import HIE.Bios
import HIE.Bios.Cradle
import HIE.Bios.Environment (addCmdOpts)
@ -102,15 +101,20 @@ getComponentOptions cradle = do
-- That will require some more changes.
CradleNone -> fail "'none' cradle is not yet supported"
compileTimeGhcVersion :: Version
compileTimeGhcVersion = $$(compileTimeVersionFromLibdir getLibdir)
ghcVersionChecker :: IO VersionCheck
ghcVersionChecker = $$(makeGhcVersionChecker (pure <$> getLibdir))
checkGhcVersion :: Ghc (Maybe HscEnvEq)
checkGhcVersion :: IO (Maybe HscEnvEq)
checkGhcVersion = do
v <- runTimeVersion
return $ if v == Just compileTimeGhcVersion
then Nothing
else Just GhcVersionMismatch {compileTime = compileTimeGhcVersion, runTime = v}
res <- ghcVersionChecker
case res of
Failure err -> do
putStrLn $ "Error while checking GHC version: " ++ show err
return Nothing
Mismatch {..} ->
return $ Just GhcVersionMismatch {..}
_ ->
return Nothing
createSession :: ComponentOptions -> IO HscEnvEq
createSession (ComponentOptions theOpts _) = do
@ -122,7 +126,7 @@ createSession (ComponentOptions theOpts _) = do
dflags <- getSessionDynFlags
(dflags', _targets) <- addCmdOpts theOpts dflags
setupDynFlags cacheDir dflags'
versionMismatch <- checkGhcVersion
versionMismatch <- liftIO checkGhcVersion
case versionMismatch of
Just mismatch -> return mismatch
Nothing -> do

View File

@ -192,7 +192,7 @@ executable ghcide
directory,
extra,
filepath,
ghc-check >= 0.1.0.3,
ghc-check >= 0.3.0.1,
ghc-paths,
ghc,
gitrev,

View File

@ -167,7 +167,7 @@ moduleImportPath (takeDirectory . fromNormalizedFilePath -> pathDir) mn
data HscEnvEq
= HscEnvEq !Unique !HscEnv
| GhcVersionMismatch { compileTime :: !Version
, runTime :: !(Maybe Version)
, runTime :: !Version
}
-- | Unwrap an 'HsEnvEq'.
@ -181,7 +181,7 @@ hscEnv' GhcVersionMismatch{..} = Left $
["ghcide compiled against GHC"
,showVersion compileTime
,"but currently using"
,maybe "an unknown version of GHC" (\v -> "GHC " <> showVersion v) runTime
,showVersion runTime
,". This is unsupported, ghcide must be compiled with the same GHC version as the project."
]

View File

@ -13,7 +13,7 @@ extra-deps:
- regex-base-0.94.0.0
- regex-tdfa-1.3.1.0
- haddock-library-1.8.0
- ghc-check-0.1.0.3
- ghc-check-0.3.0.1
nix:
packages: [zlib]
flags:

View File

@ -14,6 +14,6 @@ extra-deps:
- parser-combinators-1.2.1
- haddock-library-1.8.0
- tasty-rerun-1.1.17
- ghc-check-0.1.0.3
- ghc-check-0.3.0.1
nix:
packages: [zlib]

View File

@ -22,8 +22,7 @@ extra-deps:
- unordered-containers-0.2.10.0
- file-embed-0.0.11.2
- heaps-0.3.6.1
- ghc-check-0.1.0.3
- ghc-check-0.3.0.1
# For tasty-retun
- ansi-terminal-0.10.3
- ansi-wl-pprint-0.6.9

View File

@ -5,7 +5,6 @@ extra-deps:
- haskell-lsp-0.21.0.0
- haskell-lsp-types-0.21.0.0
- lsp-test-0.10.2.0
- ghc-check-0.1.0.3
- ghc-check-0.3.0.1
nix:
packages: [zlib]