Skip to content

Commit

Permalink
Fix '--allow-newer' bugs caught by tests.
Browse files Browse the repository at this point in the history
* Fix parsing of '--allow-newer=foo --allow-newer=bar'.
* Fix './Setup configure --allow-newer --enable-{tests, benchmarks}'.
  • Loading branch information
23Skidoo committed Feb 19, 2016
1 parent 7b8d844 commit 57c415e
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 32 deletions.
19 changes: 9 additions & 10 deletions Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,13 @@ findDistPrefOrDefault = findDistPref defaultDistPref
-- Returns the @.setup-config@ file.
configure :: (GenericPackageDescription, HookedBuildInfo)
-> ConfigFlags -> IO LocalBuildInfo
configure (pkg_descr0, pbi) cfg = do
configure (pkg_descr0', pbi) cfg = do
let pkg_descr0 =
-- Ignore '--allow-newer' when we're given '--exact-configuration'.
if fromFlagOrDefault False (configExactConfiguration cfg)
then pkg_descr0'
else relaxPackageDeps (configAllowNewer cfg) pkg_descr0'

setupMessage verbosity "Configuring" (packageId pkg_descr0)

checkDeprecatedFlags verbosity cfg
Expand Down Expand Up @@ -827,15 +833,8 @@ configureFinalizedPackage verbosity cfg
flaggedBenchmarks = map (\(n, bm) ->
(n, mapTreeData enableBenchmark bm))
(condBenchmarks pkg_descr0)
pkg_descr0''' =
-- Ignore '--allow-newer' when we're given '--exact-configuration'.
if fromFlagOrDefault False (configExactConfiguration cfg)
then pkg_descr0
else relaxPackageDeps
(fromFlagOrDefault AllowNewerNone $ configAllowNewer cfg)
pkg_descr0
pkg_descr0'' = pkg_descr0''' { condTestSuites = flaggedTests
, condBenchmarks = flaggedBenchmarks }
pkg_descr0'' = pkg_descr0 { condTestSuites = flaggedTests
, condBenchmarks = flaggedBenchmarks }

(pkg_descr0', flags) <-
case finalizePackageDescription
Expand Down
23 changes: 9 additions & 14 deletions Cabal/Distribution/Simple/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,11 @@ allowNewerParser = ReadE $ \s ->
where
pkgsParser = Parse.sepBy1 parse (Parse.char ',')

allowNewerPrinter :: Flag AllowNewer -> [Maybe String]
allowNewerPrinter (Flag AllowNewerNone) = [Just "False"]
allowNewerPrinter (Flag AllowNewerAll) = [Just "True"]
allowNewerPrinter (Flag (AllowNewerSome pkgs)) =
allowNewerPrinter :: AllowNewer -> [Maybe String]
allowNewerPrinter AllowNewerNone = []
allowNewerPrinter AllowNewerAll = [Nothing]
allowNewerPrinter (AllowNewerSome pkgs) =
[Just . intercalate "," . map display $ pkgs]
allowNewerPrinter NoFlag = []

-- | Flags to @configure@ command.
--
Expand Down Expand Up @@ -374,7 +373,8 @@ 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 :: Flag AllowNewer -- ^
configAllowNewer :: AllowNewer -- ^ Ignore upper bounds on all or some
-- dependencies.
}
deriving (Generic, Read, Show)

Expand Down Expand Up @@ -421,7 +421,7 @@ defaultConfigFlags progConf = emptyConfigFlags {
configFlagError = NoFlag,
configRelocatable = Flag False,
configDebugInfo = Flag NoDebugInfo,
configAllowNewer = NoFlag
configAllowNewer = AllowNewerNone
}

configureCommand :: ProgramConfiguration -> CommandUI ConfigFlags
Expand Down Expand Up @@ -661,9 +661,7 @@ configureOptions showOrParseArgs =
,option [] ["allow-newer"]
("Ignore upper bounds in all dependencies or DEPS")
configAllowNewer (\v flags -> flags { configAllowNewer = v})
(optArg "DEPS"
(fmap Flag allowNewerParser) (Flag AllowNewerAll)
allowNewerPrinter)
(optArg "DEPS" allowNewerParser AllowNewerAll allowNewerPrinter)

,option "" ["exact-configuration"]
"All direct dependencies and flags are provided on the command line."
Expand Down Expand Up @@ -882,12 +880,9 @@ instance Semigroup ConfigFlags where
configFlagError = combine configFlagError,
configRelocatable = combine configRelocatable,
configDebugInfo = combine configDebugInfo,
configAllowNewer = combineAllowNewer (configAllowNewer a)
(configAllowNewer b)
configAllowNewer = combine configAllowNewer
}
where combine field = field a `mappend` field b
combineAllowNewer (Flag fa) (Flag fb) = (Flag $ fa `mappend` fb)
combineAllowNewer fa fb = fa `mappend` fb

-- ------------------------------------------------------------
-- * Copy flags
Expand Down
2 changes: 2 additions & 0 deletions Cabal/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
work-around for #2398)
* Library support for multi-instance package DBs (#2948).
* Improved the './Setup configure' solver (#3082, #3076).
* The '--allow-newer' option can be now used with './Setup
configure' (#3163).

1.22.0.0 Johan Tibell <[email protected]> January 2015
* Support GHC 7.10.
Expand Down
8 changes: 7 additions & 1 deletion cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ instance Semigroup SavedConfig where
combine' field subfield =
(subfield . field $ a) `mappend` (subfield . field $ b)

combineMonoid :: Monoid mon => (SavedConfig -> flags) -> (flags -> mon)
-> mon
combineMonoid field subfield =
(subfield . field $ a) `mappend` (subfield . field $ b)

lastNonEmpty' :: (SavedConfig -> flags) -> (flags -> [a]) -> [a]
lastNonEmpty' field subfield =
let a' = subfield . field $ a
Expand Down Expand Up @@ -325,7 +330,8 @@ instance Semigroup SavedConfig where
configExactConfiguration = combine configExactConfiguration,
configFlagError = combine configFlagError,
configRelocatable = combine configRelocatable,
configAllowNewer = combine configAllowNewer
configAllowNewer = combineMonoid savedConfigureFlags
configAllowNewer
}
where
combine = combine' savedConfigureFlags
Expand Down
8 changes: 3 additions & 5 deletions cabal-install/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import Distribution.Version
import Distribution.Simple.Utils as Utils
( warn, notice, info, debug, die )
import Distribution.Simple.Setup
( AllowNewer(..), isAllowNewer )
( isAllowNewer )
import Distribution.System
( Platform )
import Distribution.Text ( display )
Expand All @@ -86,8 +86,7 @@ chooseCabalVersion configFlags maybeVersion =
where
-- Cabal < 1.19.2 doesn't support '--exact-configuration' which is needed
-- for '--allow-newer' to work.
allowNewer = fromFlagOrDefault False $
fmap isAllowNewer (configAllowNewer configFlags)
allowNewer = isAllowNewer (configAllowNewer configFlags)

defaultVersionRange = if allowNewer
then orLaterVersion (Version [1,19,2] [])
Expand Down Expand Up @@ -289,8 +288,7 @@ planLocalPackage verbosity comp platform configFlags configExFlags
fromFlagOrDefault False $ configBenchmarks configFlags

resolverParams =
removeUpperBounds (fromFlagOrDefault AllowNewerNone $
configAllowNewer configFlags)
removeUpperBounds (configAllowNewer configFlags)

. addPreferences
-- preferences from the config file or command line
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ planPackages comp platform mSandboxPkgInfo solver
maxBackjumps = fromFlag (installMaxBackjumps installFlags)
upgradeDeps = fromFlag (installUpgradeDeps installFlags)
onlyDeps = fromFlag (installOnlyDeps installFlags)
allowNewer = fromFlag (configAllowNewer configFlags)
allowNewer = (configAllowNewer configFlags)

-- | Remove the provided targets from the install plan.
pruneInstallPlan :: Package targetpkg
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ filterConfigureFlags flags cabalLibVersion
configConstraints = [],
-- Passing '--allow-newer' to Setup.hs is unnecessary, we use
-- '--exact-configuration' instead.
configAllowNewer = NoFlag
configAllowNewer = Cabal.AllowNewerNone
}

-- Cabal < 1.23 doesn't know about '--profiling-detail'.
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
default location or as specified by --config-file (#2553).
* The man page for 'cabal-install' is now automatically generated
(#2877).
* The '--allow-newer' option now works as expected when specified
multiple times (#2588).

1.22.0.0 Johan Tibell <[email protected]> January 2015
* New command: user-config (#2159).
Expand Down

0 comments on commit 57c415e

Please sign in to comment.