Skip to content

Commit 63ad1f6

Browse files
committed
Use cabal-helper's compilerVersion for GHC version check
1 parent de3ea90 commit 63ad1f6

File tree

1 file changed

+9
-45
lines changed

1 file changed

+9
-45
lines changed

src/HaskellCodeExplorer/PackageInfo.hs

+9-45
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,15 @@ createPackageInfo packageDirectoryPath mbDistDirRelativePath sourceCodePreproces
148148
Right distDir -> return distDir
149149
Left errorMessage ->
150150
logErrorN (T.pack errorMessage) >> liftIO exitFailure
151-
eitherPackageGhcVersion <- liftIO $ getPackageGhcVersion distDir
152-
case eitherPackageGhcVersion of
153-
Right packageGhcVersion ->
154-
if take 2 (versionBranch packageGhcVersion) == take 2 (versionBranch ghcVersion)
155-
then return ()
156-
else let message =
157-
"GHC version mismatch. haskell-code-indexer: " ++
158-
showVersion ghcVersion ++
159-
", package: " ++
160-
showVersion packageGhcVersion
161-
in logErrorN (T.pack message) >> liftIO exitFailure
162-
Left err -> logErrorN (T.pack err) >> liftIO exitFailure
151+
cabalHelperQueryEnv <- liftIO $ mkQueryEnv (ProjLocV1Dir packageDirectoryAbsPath) (DistDirV1 distDir)
152+
("ghc", packageGhcVersion) <- liftIO $ runQuery compilerVersion cabalHelperQueryEnv
153+
unless (take 2 (versionBranch packageGhcVersion) == take 2 (versionBranch ghcVersion)) $
154+
let message =
155+
"GHC version mismatch. haskell-code-indexer: " ++
156+
showVersion ghcVersion ++
157+
", package: " ++
158+
showVersion packageGhcVersion
159+
in logErrorN (T.pack message) >> liftIO exitFailure
163160
units <- liftIO $ flip runQuery cabalHelperQueryEnv $ allUnits Prelude.id
164161
let compInfo = concatMap (toList . uiComponents) units
165162
let (packageName, packageVersion) = uiPackageId (NE.head units)
@@ -266,39 +263,6 @@ createPackageInfo packageDirectoryPath mbDistDirRelativePath sourceCodePreproces
266263
HCE.ComponentId . T.append "bench-" . T.pack $ name
267264
chComponentNameToComponentId ChSetupHsName = HCE.ComponentId "setup"
268265

269-
-- | Parses the header of setup-config file.
270-
-- The header is generated by Cabal:
271-
-- https://github.com/haskell/cabal/blob/5be57c0d251be40a6263cd996d99703b8de1ed79/Cabal/Distribution/Simple/Configure.hs#L286-L295
272-
getPackageGhcVersion :: FilePath -> IO (Either String Version)
273-
getPackageGhcVersion distDir =
274-
withFile (distDir </> "setup-config") ReadMode $ \handle -> do
275-
header <- BSC.hGetLine handle
276-
let parseHeader :: BSC.ByteString -> Maybe BSC.ByteString
277-
parseHeader hdr =
278-
case BSC.words hdr of
279-
["Saved", "package", "config", "for", _package, "written", "by", _cabal, "using", compiler] ->
280-
Just compiler
281-
_ -> Nothing
282-
parseCompiler :: BSC.ByteString -> Maybe BSC.ByteString
283-
parseCompiler compiler =
284-
case BSC.split '-' compiler of
285-
["ghc", version] -> Just version
286-
_ -> Nothing
287-
parseGhcVersion :: BSC.ByteString -> Maybe Version
288-
parseGhcVersion version =
289-
case filter ((== "") . snd) $
290-
readP_to_S parseVersion $ BSC.unpack version of
291-
[(ver, "")] -> Just ver
292-
_ -> Nothing
293-
case parseHeader header >>= parseCompiler >>= parseGhcVersion of
294-
Just version -> return $ Right version
295-
_ ->
296-
return $
297-
Left $
298-
"Unexpected setup-config header: \"" ++
299-
BSC.unpack header ++
300-
"\"\nIt may mean that the version of Cabal used to build this package is not supported by haskell-code-indexer yet."
301-
302266
#if MIN_VERSION_GLASGOW_HASKELL(8,6,4,0)
303267
ghcVersion :: Version
304268
ghcVersion = makeVersion [8, 6, 4, 0]

0 commit comments

Comments
 (0)