Remove Cabal version sanity check from Setup.hs

This commit is contained in:
Daniel Gröber 2015-03-05 19:47:40 +01:00
parent 2151363dd6
commit ca35e99254

View File

@ -31,7 +31,7 @@ main = defaultMainWithHooks $ simpleUserHooks {
, instHook = \pd lbi uh ifl -> , instHook = \pd lbi uh ifl ->
(instHook simpleUserHooks) pd lbi uh ifl (instHook simpleUserHooks) pd lbi uh ifl
, postConf = sanityCheckCabalVersions -- , postConf = sanityCheckCabalVersions
} }
xBuildDependsLike :: LocalBuildInfo -> LocalBuildInfo xBuildDependsLike :: LocalBuildInfo -> LocalBuildInfo
@ -118,59 +118,58 @@ parseVer str =
[(ver, _)] -> ver [(ver, _)] -> ver
_ -> error $ "No parse (Ver) :(\n" ++ str ++ "\n" _ -> error $ "No parse (Ver) :(\n" ++ str ++ "\n"
sanityCheckCabalVersions args cf desc lbi = do -- sanityCheckCabalVersions args cf desc lbi = do
(cabalInstallVer, cabalVer) <- getCabalExecVer -- (cabalInstallVer, cabalVer) <- getCabalExecVer
let -- let
ghcVer = compilerVersion (compiler lbi) -- ghcVer = compilerVersion (compiler lbi)
-- ghc >= 7.10? -- -- ghc >= 7.10?
minGhc710 = ghcVer `withinRange` orLaterVersion (parseVer "7.10") -- minGhc710 = ghcVer `withinRange` orLaterVersion (parseVer "7.10")
when minGhc710 $ do -- when minGhc710 $ do
let cabalHelperCabalVer = compCabalVer (CExeName "cabal-helper") -- let cabalHelperCabalVer = compCabalVer (CExeName "cabal-helper")
when (not $ cabalVer `sameMajorVersionAs` cabalHelperCabalVer) $ -- when (not $ cabalVer `sameMajorVersionAs` cabalHelperCabalVer) $
failCabalVersionDifferent cabalVer cabalHelperCabalVer -- failCabalVersionDifferent cabalVer cabalHelperCabalVer
-- carry on as usual -- -- carry on as usual
(postConf simpleUserHooks) args cf desc lbi -- (postConf simpleUserHooks) args cf desc lbi
where -- where
earlierVersionThan ver ver' = -- earlierVersionThan ver ver' =
ver `withinRange` earlierVersion ver' -- ver `withinRange` earlierVersion ver'
sameMajorVersionAs ver ver' = -- sameMajorVersionAs ver ver' =
ver `withinRange` withinVersion (Version (take 2 $ versionBranch ver') []) -- ver `withinRange` withinVersion (Version (take 2 $ versionBranch ver') [])
compCabalVer comp = let -- compCabalVer comp = let
clbi = getComponentLocalBuildInfo lbi comp -- clbi = getComponentLocalBuildInfo lbi comp
[cabalVer] = -- [cabalVer] =
[ ver | (_, PackageIdentifier pkg ver) <- componentPackageDeps clbi -- [ ver | (_, PackageIdentifier pkg ver) <- componentPackageDeps clbi
, pkg == PackageName "Cabal" ] -- , pkg == PackageName "Cabal" ]
in cabalVer -- in cabalVer
-- getCabalExecVer = do
-- ["cabal-install", "version", cabalInstallVer, "using", "version", cabalVer, "of", "the", "Cabal", "library"] <- words <$> readProcess "cabal" ["--version"] ""
-- return (parseVer cabalInstallVer, parseVer cabalVer)
getCabalExecVer = do -- failCabalVersionDifferent cabalVer libCabalVer =
["cabal-install", "version", cabalInstallVer, "using", "version", cabalVer, "of", "the", "Cabal", "library"] <- words <$> readProcess "cabal" ["--version"] "" -- putStrLn rerr >> exitFailure
return (parseVer cabalInstallVer, parseVer cabalVer) -- where
-- replace :: String -> String -> String -> String
-- replace _ _ [] = []
-- replace n r h@(h':hs)
-- | map snd (n `zip` h ) == n = r ++ replace n r (drop (length n) h)
-- | otherwise = h':replace n r hs
failCabalVersionDifferent cabalVer libCabalVer = -- rerr = replace "X.XX.X.X" (showVersion libCabalVer) $
putStrLn rerr >> exitFailure -- replace "Y.YY.Y.Y" (showVersion cabalVer) err
where -- err = "\
replace :: String -> String -> String -> String -- \Error: Cabal seems to have decided ghc-mod should be built using Cabal\n\
replace _ _ [] = [] -- \X.XX.X.X while the `cabal' executable in your PATH was built with Cabal\n\
replace n r h@(h':hs) -- \Y.YY.Y.Y. This will lead to conflicts when running ghc-mod in any project\n\
| map snd (n `zip` h ) == n = r ++ replace n r (drop (length n) h) -- \where you use this `cabal' executable. Please compile ghc-mod using the same\n\
| otherwise = h':replace n r hs -- \Cabal version as your `cabal' executable or recompile cabal-install using\n\
-- \this version of the Cabal library.\n\
rerr = replace "X.XX.X.X" (showVersion libCabalVer) $ -- \\n\
replace "Y.YY.Y.Y" (showVersion cabalVer) err -- \See: https://github.com/kazu-yamamoto/ghc-mod/wiki/InconsistentCabalVersions\n"
err = "\
\Error: Cabal seems to have decided ghc-mod should be built using Cabal\n\
\X.XX.X.X while the `cabal' executable in your PATH was built with Cabal\n\
\Y.YY.Y.Y. This will lead to conflicts when running ghc-mod in any project\n\
\where you use this `cabal' executable. Please compile ghc-mod using the same\n\
\Cabal version as your `cabal' executable or recompile cabal-install using\n\
\this version of the Cabal library.\n\
\\n\
\See: https://github.com/kazu-yamamoto/ghc-mod/wiki/InconsistentCabalVersions\n"