Commit e4b5416c authored by Mikhail Glushenkov's avatar Mikhail Glushenkov
Browse files

Allow limiting the scope of '--allow-newer'.

Fixes #2756.
parent ac11c62d
......@@ -98,7 +98,7 @@ import qualified Data.ByteString.Lazy.Char8 as BLC8
import Data.List
( (\\), nub, partition, isPrefixOf, inits, stripPrefix )
import Data.Maybe
( isNothing, catMaybes, fromMaybe, isJust )
( isNothing, catMaybes, fromMaybe, mapMaybe, isJust )
import Data.Either
( partitionEithers )
import qualified Data.Set as Set
......@@ -794,18 +794,28 @@ dependencySatisfiable
isInternalDep = not . null
$ PackageIndex.lookupDependency internalPackageSet d
-- | Relax the dependencies of this package if needed
-- | Relax the dependencies of this package if needed.
relaxPackageDeps :: AllowNewer -> GenericPackageDescription
-> GenericPackageDescription
relaxPackageDeps AllowNewerNone = id
relaxPackageDeps AllowNewerAll =
transformAllBuildDepends $ \(Dependency pkgName verRange) ->
Dependency pkgName (removeUpperBound verRange)
relaxPackageDeps (AllowNewerSome pkgNames) =
transformAllBuildDepends $ \d@(Dependency pkgName verRange) ->
if pkgName `elem` pkgNames
then Dependency pkgName (removeUpperBound verRange)
else d
relaxPackageDeps AllowNewerNone gpd = gpd
relaxPackageDeps AllowNewerAll gpd = transformAllBuildDepends relaxAll gpd
where
relaxAll = \(Dependency pkgName verRange) ->
Dependency pkgName (removeUpperBound verRange)
relaxPackageDeps (AllowNewerSome allowNewerDeps') gpd =
transformAllBuildDepends relaxSome gpd
where
thisPkgName = packageName gpd
allowNewerDeps = mapMaybe f allowNewerDeps'
f (Setup.AllowNewerDep p) = Just p
f (Setup.AllowNewerDepScoped scope p) | scope == thisPkgName = Just p
| otherwise = Nothing
relaxSome = \d@(Dependency depName verRange) ->
if depName `elem` allowNewerDeps
then Dependency depName (removeUpperBound verRange)
else d
-- | Finalize a generic package description. The workhorse is
-- 'finalizePackageDescription' but there's a bit of other nattering
......
......@@ -34,7 +34,7 @@ module Distribution.Simple.Setup (
GlobalFlags(..), emptyGlobalFlags, defaultGlobalFlags, globalCommand,
ConfigFlags(..), emptyConfigFlags, defaultConfigFlags, configureCommand,
AllowNewer(..), isAllowNewer,
AllowNewer(..), AllowNewerDep(..), isAllowNewer,
configAbsolutePaths, readPackageDbList, showPackageDbList,
CopyFlags(..), emptyCopyFlags, defaultCopyFlags, copyCommand,
InstallFlags(..), emptyInstallFlags, defaultInstallFlags, installCommand,
......@@ -86,11 +86,12 @@ import Distribution.Utils.NubList
import Distribution.Compat.Binary (Binary)
import Distribution.Compat.Semigroup as Semi
import Control.Monad (liftM)
import Data.List ( sort )
import Data.Maybe ( listToMaybe )
import Data.Char ( isSpace, isAlpha )
import GHC.Generics (Generic)
import Control.Applicative as A ( Applicative(..), (<*) )
import Control.Monad ( liftM )
import Data.List ( sort )
import Data.Maybe ( listToMaybe )
import Data.Char ( isSpace, isAlpha )
import GHC.Generics ( Generic )
-- FIXME Not sure where this should live
defaultDistPref :: FilePath
......@@ -266,13 +267,29 @@ data AllowNewer =
AllowNewerNone
-- | Ignore upper bounds in dependencies on the given packages.
| AllowNewerSome [PackageName]
| AllowNewerSome [AllowNewerDep]
-- | Ignore upper bounds in dependencies on all packages.
| AllowNewerAll
deriving (Eq, Ord, Read, Show, Generic)
deriving (Read, Show, Generic)
-- | Dependencies can be relaxed either for all packages in the install plan, or
-- only for some packages.
data AllowNewerDep = AllowNewerDep PackageName
| AllowNewerDepScoped PackageName PackageName
deriving (Read, Show, Generic)
instance Text AllowNewerDep where
disp (AllowNewerDep p0) = disp p0
disp (AllowNewerDepScoped p0 p1) = disp p0 Disp.<> Disp.colon Disp.<> disp p1
parse = scopedP Parse.<++ normalP
where
scopedP = AllowNewerDepScoped `fmap` parse A.<* Parse.char ':' A.<*> parse
normalP = AllowNewerDep `fmap` parse
instance Binary AllowNewer
instance Binary AllowNewerDep
instance Semigroup AllowNewer where
AllowNewerNone <> r = r
......
......@@ -982,8 +982,25 @@ be controlled with the following command line options.
$ cabal install --allow-newer=bar --constraint="bar==2.1" foo
~~~~~~~~~~~~~~~~
It's also possible to enable `--allow-newer` permanently by setting
`allow-newer: True` in the `~/.cabal/config` file.
It's also possible to limit the scope of `--allow-newer` to single
packages with the `--allow-newer=scope:dep` syntax. This means that the
dependency on `dep` will be relaxed only for the package `scope`.
Example:
~~~~~~~~~~~~~~~~
# Relax upper bound in foo's dependency on base; also relax upper bound in
# every package's dependency on lens.
$ cabal install --allow-newer=foo:base,lens
# Relax upper bounds in foo's dependency on base and bar's dependency
# on time; also relax the upper bound in the dependency on lens specified by
# any package.
$ cabal install --allow-newer=foo:base,lens --allow-newer=bar:time
~~~~~~~~~~~~~~~~
Finally, one can enable `--allow-newer` permanently by setting `allow-newer:
True` in the `~/.cabal/config` file.
`--constraint=`_constraint_
: Restrict solutions involving a package to a given version range.
......
......@@ -236,6 +236,15 @@ nonSharedLibTests config =
shouldFail $ cabal "configure" ["--enable-benchmarks", "--enable-tests"]
cabal "configure" ["--enable-benchmarks", "--enable-tests"
,"--allow-newer"]
shouldFail $ cabal "configure" ["--allow-newer=Foo:base"]
shouldFail $ cabal "configure" ["--allow-newer=Foo:base"
,"--enable-tests", "--enable-benchmarks"]
cabal "configure" ["--allow-newer=AllowNewer:base"]
cabal "configure" ["--allow-newer=AllowNewer:base"
,"--allow-newer=Foo:base"]
cabal "configure" ["--allow-newer=AllowNewer:base"
,"--allow-newer=Foo:base"
,"--enable-tests", "--enable-benchmarks"]
-- Test that Cabal can choose flags to disable building a component when that
-- component's dependencies are unavailable. The build should succeed without
......
......@@ -47,6 +47,8 @@
* New config file field: 'extra-framework-dirs' (extra locations
to find OS X frameworks in). Can be also specified as an argument
for 'install' and 'configure' commands (#3158).
* It's now possible to limit the scope of '--allow-newer' to
single packages in the install plan (#2756).
1.22.0.0 Johan Tibell <johan.tibell@gmail.com> January 2015
* New command: user-config (#2159).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment