on master help sign in
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

commit15bb04426997c3fe6c7a7cfd3fc177230bf13c06 authorPepe Iborra <pepeiborra@gmail.com> dateFri 8 May 2020, 14:48 (6 years ago) parent6a650be
7 files changed+21−19
exe/Rules.hs+14−10 ghcide.cabal+1−1 src/Development/IDE/GHC/Util.hs+2−2 stack-ghc-lib.yaml+1−1 stack.yaml+1−1 stack84.yaml+1−2 stack88.yaml+1−2
exe/Rules.hs+14−10
@@ -15,7 +15,6 @@ import Data.ByteString.Base16 (encode)
1515import qualified Data.ByteString.Char8 as B
1616import Data.Functor ((<&>))
1717import Data.Text (Text, pack)
18−import Data.Version (Version)
1918import Development.IDE.Core.Rules (defineNoFile)
2019import Development.IDE.Core.Service (getIdeOptions)
2120import Development.IDE.Core.Shake (actionLogger, sendEvent, define, useNoFile_)
@@ -24,7 +23,7 @@ import Development.IDE.Types.Location (fromNormalizedFilePath)
2423import Development.IDE.Types.Options (IdeOptions(IdeOptions, optTesting))
2524import Development.Shake
2625import GHC
27−import GHC.Check (runTimeVersion, compileTimeVersionFromLibdir)
26+import GHC.Check (VersionCheck(..), makeGhcVersionChecker)
2827import HIE.Bios
2928import HIE.Bios.Cradle
3029import HIE.Bios.Environment (addCmdOpts)
@@ -102,15 +101,20 @@ getComponentOptions cradle = do
102101 -- That will require some more changes.
103102 CradleNone -> fail "'none' cradle is not yet supported"
104103
105−compileTimeGhcVersion :: Version
106−compileTimeGhcVersion = $$(compileTimeVersionFromLibdir getLibdir)
104+ghcVersionChecker :: IO VersionCheck
105+ghcVersionChecker = $$(makeGhcVersionChecker (pure <$> getLibdir))
107106
108−checkGhcVersion :: Ghc (Maybe HscEnvEq)
107+checkGhcVersion :: IO (Maybe HscEnvEq)
109108checkGhcVersion = do
110− v <- runTimeVersion
111− return $ if v == Just compileTimeGhcVersion
112− then Nothing
113− else Just GhcVersionMismatch {compileTime = compileTimeGhcVersion, runTime = v}
109+ res <- ghcVersionChecker
110+ case res of
111+ Failure err -> do
112+ putStrLn $ "Error while checking GHC version: " ++ show err
113+ return Nothing
114+ Mismatch {..} ->
115+ return $ Just GhcVersionMismatch {..}
116+ _ ->
117+ return Nothing
114118
115119createSession :: ComponentOptions -> IO HscEnvEq
116120createSession (ComponentOptions theOpts _) = do
@@ -122,7 +126,7 @@ createSession (ComponentOptions theOpts _) = do
122126 dflags <- getSessionDynFlags
123127 (dflags', _targets) <- addCmdOpts theOpts dflags
124128 setupDynFlags cacheDir dflags'
125− versionMismatch <- checkGhcVersion
129+ versionMismatch <- liftIO checkGhcVersion
126130 case versionMismatch of
127131 Just mismatch -> return mismatch
128132 Nothing -> do
ghcide.cabal+1−1
@@ -192,7 +192,7 @@ executable ghcide
192192 directory,
193193 extra,
194194 filepath,
195− ghc-check >= 0.1.0.3,
195+ ghc-check >= 0.3.0.1,
196196 ghc-paths,
197197 ghc,
198198 gitrev,
src/Development/IDE/GHC/Util.hs+2−2
@@ -167,7 +167,7 @@ moduleImportPath (takeDirectory . fromNormalizedFilePath -> pathDir) mn
167167data HscEnvEq
168168 = HscEnvEq !Unique !HscEnv
169169 | GhcVersionMismatch { compileTime :: !Version
170− , runTime :: !(Maybe Version)
170+ , runTime :: !Version
171171 }
172172
173173-- | Unwrap an 'HsEnvEq'.
@@ -181,7 +181,7 @@ hscEnv' GhcVersionMismatch{..} = Left $
181181 ["ghcide compiled against GHC"
182182 ,showVersion compileTime
183183 ,"but currently using"
184− ,maybe "an unknown version of GHC" (\v -> "GHC " <> showVersion v) runTime
184+ ,showVersion runTime
185185 ,". This is unsupported, ghcide must be compiled with the same GHC version as the project."
186186 ]
187187
stack-ghc-lib.yaml+1−1
@@ -13,7 +13,7 @@ extra-deps:
1313- regex-base-0.94.0.0
1414- regex-tdfa-1.3.1.0
1515- haddock-library-1.8.0
16−- ghc-check-0.1.0.3
16+- ghc-check-0.3.0.1
1717nix:
1818 packages: [zlib]
1919flags:
stack.yaml+1−1
@@ -14,6 +14,6 @@ extra-deps:
1414- parser-combinators-1.2.1
1515- haddock-library-1.8.0
1616- tasty-rerun-1.1.17
17−- ghc-check-0.1.0.3
17+- ghc-check-0.3.0.1
1818nix:
1919 packages: [zlib]
stack84.yaml+1−2
@@ -22,8 +22,7 @@ extra-deps:
2222- unordered-containers-0.2.10.0
2323- file-embed-0.0.11.2
2424- heaps-0.3.6.1
25−- ghc-check-0.1.0.3
26−
25+- ghc-check-0.3.0.1
2726# For tasty-retun
2827- ansi-terminal-0.10.3
2928- ansi-wl-pprint-0.6.9
stack88.yaml+1−2
@@ -5,7 +5,6 @@ extra-deps:
55- haskell-lsp-0.21.0.0
66- haskell-lsp-types-0.21.0.0
77- lsp-test-0.10.2.0
8−- ghc-check-0.1.0.3
9−
8+- ghc-check-0.3.0.1
109nix:
1110 packages: [zlib]