Skip to content

Commit 15bb044

Browse files
authored
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
1 parent 6a650be commit 15bb044

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

exe/Rules.hs

+14-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Data.ByteString.Base16 (encode)
1515
import qualified Data.ByteString.Char8 as B
1616
import Data.Functor ((<&>))
1717
import Data.Text (Text, pack)
18-
import Data.Version (Version)
1918
import Development.IDE.Core.Rules (defineNoFile)
2019
import Development.IDE.Core.Service (getIdeOptions)
2120
import Development.IDE.Core.Shake (actionLogger, sendEvent, define, useNoFile_)
@@ -24,7 +23,7 @@ import Development.IDE.Types.Location (fromNormalizedFilePath)
2423
import Development.IDE.Types.Options (IdeOptions(IdeOptions, optTesting))
2524
import Development.Shake
2625
import GHC
27-
import GHC.Check (runTimeVersion, compileTimeVersionFromLibdir)
26+
import GHC.Check (VersionCheck(..), makeGhcVersionChecker)
2827
import HIE.Bios
2928
import HIE.Bios.Cradle
3029
import 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)
109108
checkGhcVersion = 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

115119
createSession :: ComponentOptions -> IO HscEnvEq
116120
createSession (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
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ moduleImportPath (takeDirectory . fromNormalizedFilePath -> pathDir) mn
167167
data 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
Original file line numberDiff line numberDiff line change
@@ -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
1717
nix:
1818
packages: [zlib]
1919
flags:

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -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
1818
nix:
1919
packages: [zlib]

stack84.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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
109
nix:
1110
packages: [zlib]

0 commit comments

Comments
 (0)