mirror of
https://github.com/haskell/ghcide.git
synced 2024-12-03 05:23:25 +03:00
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:
parent
6a650be7e3
commit
15bb044269
24
exe/Rules.hs
24
exe/Rules.hs
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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."
|
||||
]
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user