Skip to content

Commit

Permalink
Consistently use the Cabal version picked by the dependency solver.
Browse files Browse the repository at this point in the history
Previously, cabal always chose a Cabal library version to use for a package's
setup script that didn't take setup-depends into account (cabalLibVersion).
cabalLibVersion depended on the cabal-version field, the installed versions of
Cabal, etc., and it was used when setup dependencies were not chosen by the
dependency solver. When a package had a setup-depends, cabalLibVersion was later
ignored in favor of the version chosen by the dependency solver. However,
calculating the variable caused an error when the only suitable Cabal version
was installed during the same install command (issue haskell#3436). cabalLibVersion was
also used to filter the configure flags (issue haskell#3433).

This commit sets cabalLibVersion to the version chosen by the dependency solver,
when possible.
  • Loading branch information
grayjay committed Aug 28, 2016
1 parent c4fc3bd commit 77fb0b9
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions cabal-install/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ import Control.Applicative ( (<$>), (<*>) )
import Data.Monoid ( mempty )
#endif
import Control.Monad ( when, unless )
import Data.List ( foldl1' )
import Data.List ( find, foldl1' )
import Data.Maybe ( fromMaybe, isJust )
import Data.Char ( isSpace )
import Distribution.Client.Compat.ExecutablePath ( getExecutablePath )
Expand Down Expand Up @@ -389,26 +389,33 @@ externalSetupMethod verbosity options pkg bt mkargs = do
Nothing -> getInstalledPackages verbosity
comp (usePackageDB options') conf

cabalLibVersionToUse :: IO (Version, (Maybe ComponentId)
cabalLibVersionToUse :: IO (Version, Maybe ComponentId
,SetupScriptOptions)
cabalLibVersionToUse =
case useCabalSpecVersion options of
Just version -> do
case find (hasCabal . snd) (useDependencies options) of
Just (unitId, pkgId) -> do
let version = pkgVersion pkgId
updateSetupScript version bt
writeFile setupVersionFile (show version ++ "\n")
return (version, Nothing, options)
Nothing -> do
savedVer <- savedVersion
case savedVer of
Just version | version `withinRange` useCabalVersion options
-> do updateSetupScript version bt
-- Does the previously compiled setup executable still exist
-- and is it up-to date?
useExisting <- canUseExistingSetup version
if useExisting
then return (version, Nothing, options)
else installedVersion
_ -> installedVersion
writeSetupVersionFile version
return (version, Just unitId, options)
Nothing ->
case useCabalSpecVersion options of
Just version -> do
updateSetupScript version bt
writeSetupVersionFile version
return (version, Nothing, options)
Nothing -> do
savedVer <- savedVersion
case savedVer of
Just version | version `withinRange` useCabalVersion options
-> do updateSetupScript version bt
-- Does the previously compiled setup executable still exist
-- and is it up-to date?
useExisting <- canUseExistingSetup version
if useExisting
then return (version, Nothing, options)
else installedVersion
_ -> installedVersion
where
-- This check duplicates the checks in 'getCachedSetupExecutable' /
-- 'compileSetupExecutable'. Unfortunately, we have to perform it twice
Expand All @@ -424,13 +431,20 @@ externalSetupMethod verbosity options pkg bt mkargs = do
(&&) <$> setupProgFile `existsAndIsMoreRecentThan` setupHs
<*> setupProgFile `existsAndIsMoreRecentThan` setupVersionFile

writeSetupVersionFile :: Version -> IO ()
writeSetupVersionFile version =
writeFile setupVersionFile (show version ++ "\n")

hasCabal (PackageIdentifier (PackageName "Cabal") _) = True
hasCabal _ = False

installedVersion :: IO (Version, Maybe InstalledPackageId
,SetupScriptOptions)
installedVersion = do
(comp, conf, options') <- configureCompiler options
(version, mipkgid, options'') <- installedCabalVersion options' comp conf
updateSetupScript version bt
writeFile setupVersionFile (show version ++ "\n")
writeSetupVersionFile version
return (version, mipkgid, options'')

savedVersion :: IO (Maybe Version)
Expand Down

0 comments on commit 77fb0b9

Please sign in to comment.