From b402dc87136700be1c231954366c42b67133eaa4 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Sat, 20 Feb 2016 17:31:07 +0100 Subject: [PATCH] Support full 'allow-newer' syntax in the config file. --- Cabal/Distribution/Simple/Setup.hs | 14 ++++++-------- Cabal/doc/installing-packages.markdown | 3 ++- cabal-install/Distribution/Client/Config.hs | 7 ++++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index 0556a708318..f9ef3244c67 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -308,13 +308,9 @@ isAllowNewer AllowNewerNone = False isAllowNewer (AllowNewerSome _) = True isAllowNewer AllowNewerAll = True -allowNewerParser :: ReadE (Maybe AllowNewer) -allowNewerParser = ReadE $ \s -> - case readPToMaybe pkgsParser s of - Just pkgs -> Right . Just . AllowNewerSome $ pkgs - Nothing -> Left ("Cannot parse the list of packages: " ++ s) - where - pkgsParser = Parse.sepBy1 parse (Parse.char ',') +allowNewerParser :: Parse.ReadP r (Maybe AllowNewer) +allowNewerParser = + (Just . AllowNewerSome) `fmap` Parse.sepBy1 parse (Parse.char ',') allowNewerPrinter :: (Maybe AllowNewer) -> [Maybe String] allowNewerPrinter Nothing = [] @@ -687,7 +683,9 @@ configureOptions showOrParseArgs = ,option [] ["allow-newer"] ("Ignore upper bounds in all dependencies or DEPS") configAllowNewer (\v flags -> flags { configAllowNewer = v}) - (optArg "DEPS" allowNewerParser (Just AllowNewerAll) allowNewerPrinter) + (optArg "DEPS" + (readP_to_E ("Cannot parse the list of packages: " ++) allowNewerParser) + (Just AllowNewerAll) allowNewerPrinter) ,option "" ["exact-configuration"] "All direct dependencies and flags are provided on the command line." diff --git a/Cabal/doc/installing-packages.markdown b/Cabal/doc/installing-packages.markdown index 75ee4a743c5..fbb995d31dc 100644 --- a/Cabal/doc/installing-packages.markdown +++ b/Cabal/doc/installing-packages.markdown @@ -1000,7 +1000,8 @@ be controlled with the following command line options. ~~~~~~~~~~~~~~~~ Finally, one can enable `--allow-newer` permanently by setting `allow-newer: - True` in the `~/.cabal/config` file. + True` in the `~/.cabal/config` file. Enabling 'allow-newer' selectively is + also supported in the config file (`allow-newer: foo, bar, baz:base`). `--constraint=`_constraint_ : Restrict solutions involving a package to a given version range. diff --git a/cabal-install/Distribution/Client/Config.hs b/cabal-install/Distribution/Client/Config.hs index 76dade22be1..ffbb18c34b0 100644 --- a/cabal-install/Distribution/Client/Config.hs +++ b/cabal-install/Distribution/Client/Config.hs @@ -76,7 +76,7 @@ import Distribution.ParseUtils , locatedErrorMsg, showPWarning , readFields, warning, lineNo , simpleField, listField, spaceListField - , parseFilePathQ, parseTokenQ ) + , parseFilePathQ, parseOptCommaList, parseTokenQ ) import Distribution.Client.ParseUtils ( parseFields, ppFields, ppSection ) import Distribution.Client.HttpUtils @@ -108,7 +108,7 @@ import Data.Monoid import Control.Monad ( when, unless, foldM, liftM, liftM2 ) import qualified Distribution.Compat.ReadP as Parse - ( option ) + ( (<++), option ) import Distribution.Compat.Semigroup ( Semigroup((<>)) ) import qualified Text.PrettyPrint as Disp @@ -677,7 +677,8 @@ configFieldDescriptions src = toAllowNewer True = Just AllowNewerAll toAllowNewer False = Just AllowNewerNone - parseAllowNewer = toAllowNewer `fmap` Text.parse in + pkgs = (Just . AllowNewerSome) `fmap` parseOptCommaList Text.parse + parseAllowNewer = (toAllowNewer `fmap` Text.parse) Parse.<++ pkgs in simpleField "allow-newer" showAllowNewer parseAllowNewer configAllowNewer (\v flags -> flags { configAllowNewer = v })