From b428a2ef5a447d6df9f2485531e2e5742d71e8c0 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Fri, 19 Feb 2016 22:41:43 +0100 Subject: [PATCH] Tweak how 'allow-newer' looks like in the default config file. Before: allow-newer: False After: -- allow-newer: False --- Cabal/Distribution/Simple/Configure.hs | 4 +++- Cabal/Distribution/Simple/Setup.hs | 23 ++++++++++--------- cabal-install/Distribution/Client/Config.hs | 22 ++++++++++++------ .../Distribution/Client/Configure.hs | 9 +++++--- cabal-install/Distribution/Client/Install.hs | 3 ++- cabal-install/Distribution/Client/Setup.hs | 2 +- 6 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Cabal/Distribution/Simple/Configure.hs b/Cabal/Distribution/Simple/Configure.hs index 9432b1e9289..ae4ae4e97b5 100644 --- a/Cabal/Distribution/Simple/Configure.hs +++ b/Cabal/Distribution/Simple/Configure.hs @@ -315,7 +315,9 @@ configure (pkg_descr0', pbi) cfg = do -- Ignore '--allow-newer' when we're given '--exact-configuration'. if fromFlagOrDefault False (configExactConfiguration cfg) then pkg_descr0' - else relaxPackageDeps (configAllowNewer cfg) pkg_descr0' + else relaxPackageDeps + (fromMaybe AllowNewerNone $ configAllowNewer cfg) + pkg_descr0' setupMessage verbosity "Configuring" (packageId pkg_descr0) diff --git a/Cabal/Distribution/Simple/Setup.hs b/Cabal/Distribution/Simple/Setup.hs index 1ecf601e451..0556a708318 100644 --- a/Cabal/Distribution/Simple/Setup.hs +++ b/Cabal/Distribution/Simple/Setup.hs @@ -308,19 +308,19 @@ isAllowNewer AllowNewerNone = False isAllowNewer (AllowNewerSome _) = True isAllowNewer AllowNewerAll = True -allowNewerParser :: ReadE AllowNewer +allowNewerParser :: ReadE (Maybe AllowNewer) allowNewerParser = ReadE $ \s -> case readPToMaybe pkgsParser s of - Just pkgs -> Right . AllowNewerSome $ pkgs + Just pkgs -> Right . Just . AllowNewerSome $ pkgs Nothing -> Left ("Cannot parse the list of packages: " ++ s) where pkgsParser = Parse.sepBy1 parse (Parse.char ',') -allowNewerPrinter :: AllowNewer -> [Maybe String] -allowNewerPrinter AllowNewerNone = [] -allowNewerPrinter AllowNewerAll = [Nothing] -allowNewerPrinter (AllowNewerSome pkgs) = - [Just . intercalate "," . map display $ pkgs] +allowNewerPrinter :: (Maybe AllowNewer) -> [Maybe String] +allowNewerPrinter Nothing = [] +allowNewerPrinter (Just AllowNewerNone) = [] +allowNewerPrinter (Just AllowNewerAll) = [Nothing] +allowNewerPrinter (Just (AllowNewerSome pkgs)) = map (Just . display) $ pkgs -- | Flags to @configure@ command. -- @@ -392,8 +392,9 @@ data ConfigFlags = ConfigFlags { -- ^Halt and show an error message indicating an error in flag assignment configRelocatable :: Flag Bool, -- ^ Enable relocatable package built configDebugInfo :: Flag DebugInfoLevel, -- ^ Emit debug info. - configAllowNewer :: AllowNewer -- ^ Ignore upper bounds on all or some - -- dependencies. + configAllowNewer :: Maybe AllowNewer + -- ^ Ignore upper bounds on all or some dependencies. Wrapped in 'Maybe' to + -- distinguish between "default" and "explicitly disabled". } deriving (Generic, Read, Show) @@ -440,7 +441,7 @@ defaultConfigFlags progConf = emptyConfigFlags { configFlagError = NoFlag, configRelocatable = Flag False, configDebugInfo = Flag NoDebugInfo, - configAllowNewer = AllowNewerNone + configAllowNewer = Nothing } configureCommand :: ProgramConfiguration -> CommandUI ConfigFlags @@ -686,7 +687,7 @@ configureOptions showOrParseArgs = ,option [] ["allow-newer"] ("Ignore upper bounds in all dependencies or DEPS") configAllowNewer (\v flags -> flags { configAllowNewer = v}) - (optArg "DEPS" allowNewerParser AllowNewerAll allowNewerPrinter) + (optArg "DEPS" allowNewerParser (Just AllowNewerAll) allowNewerPrinter) ,option "" ["exact-configuration"] "All direct dependencies and flags are provided on the command line." diff --git a/cabal-install/Distribution/Client/Config.hs b/cabal-install/Distribution/Client/Config.hs index 96cc0445bf7..76dade22be1 100644 --- a/cabal-install/Distribution/Client/Config.hs +++ b/cabal-install/Distribution/Client/Config.hs @@ -62,7 +62,7 @@ import Distribution.Simple.Compiler ( DebugInfoLevel(..), OptimisationLevel(..) ) import Distribution.Simple.Setup ( ConfigFlags(..), configureOptions, defaultConfigFlags - , AllowNewer(..), isAllowNewer + , AllowNewer(..) , HaddockFlags(..), haddockOptions, defaultHaddockFlags , installDirsOptions, optionDistPref , programConfigurationPaths', programConfigurationOptions @@ -75,7 +75,7 @@ import Distribution.ParseUtils , ParseResult(..), PError(..), PWarning(..) , locatedErrorMsg, showPWarning , readFields, warning, lineNo - , simpleField, boolField, listField, spaceListField + , simpleField, listField, spaceListField , parseFilePathQ, parseTokenQ ) import Distribution.Client.ParseUtils ( parseFields, ppFields, ppSection ) @@ -640,7 +640,8 @@ commentSavedConfig = do savedInstallFlags = defaultInstallFlags, savedConfigureExFlags = defaultConfigExFlags, savedConfigureFlags = (defaultConfigFlags defaultProgramConfiguration) { - configUserInstall = toFlag defaultUserInstall + configUserInstall = toFlag defaultUserInstall, + configAllowNewer = Just AllowNewerNone }, savedUserInstallDirs = fmap toFlag userInstallDirs, savedGlobalInstallDirs = fmap toFlag globalInstallDirs, @@ -669,10 +670,17 @@ configFieldDescriptions src = [simpleField "compiler" (fromFlagOrDefault Disp.empty . fmap Text.disp) (optional Text.parse) configHcFlavor (\v flags -> flags { configHcFlavor = v }) - ,let toAllowNewer True = AllowNewerAll - toAllowNewer False = AllowNewerNone in - boolField "allow-newer" (isAllowNewer . configAllowNewer) - (\v flags -> flags { configAllowNewer = toAllowNewer v }) + ,let showAllowNewer Nothing = mempty + showAllowNewer (Just AllowNewerNone) = Disp.text "False" + showAllowNewer (Just _) = Disp.text "True" + + toAllowNewer True = Just AllowNewerAll + toAllowNewer False = Just AllowNewerNone + + parseAllowNewer = toAllowNewer `fmap` Text.parse in + simpleField "allow-newer" + showAllowNewer parseAllowNewer + configAllowNewer (\v flags -> flags { configAllowNewer = v }) -- TODO: The following is a temporary fix. The "optimization" -- and "debug-info" fields are OptArg, and viewAsFieldDescr -- fails on that. Instead of a hand-written hackaged parser diff --git a/cabal-install/Distribution/Client/Configure.hs b/cabal-install/Distribution/Client/Configure.hs index c8e717959ac..908284893e6 100644 --- a/cabal-install/Distribution/Client/Configure.hs +++ b/cabal-install/Distribution/Client/Configure.hs @@ -43,7 +43,8 @@ import Distribution.Simple.Compiler ( Compiler, CompilerInfo, compilerInfo, PackageDB(..), PackageDBStack ) import Distribution.Simple.Program (ProgramConfiguration ) import Distribution.Simple.Setup - ( ConfigFlags(..), fromFlag, toFlag, flagToMaybe, fromFlagOrDefault ) + ( ConfigFlags(..), AllowNewer(..) + , fromFlag, toFlag, flagToMaybe, fromFlagOrDefault ) import Distribution.Simple.PackageIndex ( InstalledPackageIndex, lookupPackageName ) import Distribution.Simple.Utils @@ -86,7 +87,8 @@ chooseCabalVersion configFlags maybeVersion = where -- Cabal < 1.19.2 doesn't support '--exact-configuration' which is needed -- for '--allow-newer' to work. - allowNewer = isAllowNewer (configAllowNewer configFlags) + allowNewer = isAllowNewer + (fromMaybe AllowNewerNone $ configAllowNewer configFlags) defaultVersionRange = if allowNewer then orLaterVersion (Version [1,19,2] []) @@ -288,7 +290,8 @@ planLocalPackage verbosity comp platform configFlags configExFlags fromFlagOrDefault False $ configBenchmarks configFlags resolverParams = - removeUpperBounds (configAllowNewer configFlags) + removeUpperBounds + (fromMaybe AllowNewerNone $ configAllowNewer configFlags) . addPreferences -- preferences from the config file or command line diff --git a/cabal-install/Distribution/Client/Install.hs b/cabal-install/Distribution/Client/Install.hs index 7dc5225d561..260349b4367 100644 --- a/cabal-install/Distribution/Client/Install.hs +++ b/cabal-install/Distribution/Client/Install.hs @@ -124,6 +124,7 @@ import qualified Distribution.Simple.Configure as Configure import Distribution.Simple.Setup ( haddockCommand, HaddockFlags(..) , buildCommand, BuildFlags(..), emptyBuildFlags + , AllowNewer(..) , toFlag, fromFlag, fromFlagOrDefault, flagToMaybe, defaultDistPref ) import qualified Distribution.Simple.Setup as Cabal ( Flag(..) @@ -417,7 +418,7 @@ planPackages comp platform mSandboxPkgInfo solver maxBackjumps = fromFlag (installMaxBackjumps installFlags) upgradeDeps = fromFlag (installUpgradeDeps installFlags) onlyDeps = fromFlag (installOnlyDeps installFlags) - allowNewer = (configAllowNewer configFlags) + allowNewer = fromMaybe AllowNewerNone (configAllowNewer configFlags) -- | Remove the provided targets from the install plan. pruneInstallPlan :: Package targetpkg diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index 3611482c644..ec106bdc2f2 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -370,7 +370,7 @@ filterConfigureFlags flags cabalLibVersion configConstraints = [], -- Passing '--allow-newer' to Setup.hs is unnecessary, we use -- '--exact-configuration' instead. - configAllowNewer = Cabal.AllowNewerNone + configAllowNewer = Just Cabal.AllowNewerNone } -- Cabal < 1.23 doesn't know about '--profiling-detail'.