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

View File

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

View File

@ -167,7 +167,7 @@ moduleImportPath (takeDirectory . fromNormalizedFilePath -> pathDir) mn
data HscEnvEq data HscEnvEq
= HscEnvEq !Unique !HscEnv = HscEnvEq !Unique !HscEnv
| GhcVersionMismatch { compileTime :: !Version | GhcVersionMismatch { compileTime :: !Version
, runTime :: !(Maybe Version) , runTime :: !Version
} }
-- | Unwrap an 'HsEnvEq'. -- | Unwrap an 'HsEnvEq'.
@ -181,7 +181,7 @@ hscEnv' GhcVersionMismatch{..} = Left $
["ghcide compiled against GHC" ["ghcide compiled against GHC"
,showVersion compileTime ,showVersion compileTime
,"but currently using" ,"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." ,". 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-base-0.94.0.0
- regex-tdfa-1.3.1.0 - regex-tdfa-1.3.1.0
- haddock-library-1.8.0 - haddock-library-1.8.0
- ghc-check-0.1.0.3 - ghc-check-0.3.0.1
nix: nix:
packages: [zlib] packages: [zlib]
flags: flags:

View File

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

View File

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

View File

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