Skip to content

Commit 8d48078

Browse files
committed
Implement --allow-older (dual to --allow-newer)
This implements the flag `--allow-older` which is the analogous to `--allow-newer` acting on lower bounds.
1 parent 8376f7f commit 8d48078

File tree

20 files changed

+194
-48
lines changed

20 files changed

+194
-48
lines changed

Cabal/Distribution/Simple/Configure.hs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ configure :: (GenericPackageDescription, HookedBuildInfo)
320320
-> ConfigFlags -> IO LocalBuildInfo
321321
configure (pkg_descr0', pbi) cfg = do
322322
let pkg_descr0 =
323-
-- Ignore '--allow-newer' when we're given '--exact-configuration'.
323+
-- Ignore '--allow-{older,newer}' when we're given '--exact-configuration'.
324324
if fromFlagOrDefault False (configExactConfiguration cfg)
325325
then pkg_descr0'
326-
else relaxPackageDeps
326+
else relaxPackageDeps removeLowerBound
327+
(maybe RelaxDepsNone unAllowOlder $ configAllowOlder cfg) $
328+
relaxPackageDeps removeUpperBound
327329
(maybe RelaxDepsNone unAllowNewer $ configAllowNewer cfg)
328330
pkg_descr0'
329331

@@ -871,26 +873,27 @@ dependencySatisfiable
871873
$ PackageIndex.lookupDependency internalPackageSet d
872874

873875
-- | Relax the dependencies of this package if needed.
874-
relaxPackageDeps :: RelaxDeps -> GenericPackageDescription
875-
-> GenericPackageDescription
876-
relaxPackageDeps RelaxDepsNone gpd = gpd
877-
relaxPackageDeps RelaxDepsAll gpd = transformAllBuildDepends relaxAll gpd
876+
relaxPackageDeps :: (VersionRange -> VersionRange)
877+
-> RelaxDeps
878+
-> GenericPackageDescription -> GenericPackageDescription
879+
relaxPackageDeps _ RelaxDepsNone gpd = gpd
880+
relaxPackageDeps vrtrans RelaxDepsAll gpd = transformAllBuildDepends relaxAll gpd
878881
where
879882
relaxAll = \(Dependency pkgName verRange) ->
880-
Dependency pkgName (removeUpperBound verRange)
881-
relaxPackageDeps (RelaxDepsSome allowNewerDeps') gpd =
883+
Dependency pkgName (vrtrans verRange)
884+
relaxPackageDeps vrtrans (RelaxDepsSome allowNewerDeps') gpd =
882885
transformAllBuildDepends relaxSome gpd
883886
where
884887
thisPkgName = packageName gpd
885888
allowNewerDeps = mapMaybe f allowNewerDeps'
886889

887890
f (Setup.RelaxedDep p) = Just p
888891
f (Setup.RelaxedDepScoped scope p) | scope == thisPkgName = Just p
889-
| otherwise = Nothing
892+
| otherwise = Nothing
890893

891894
relaxSome = \d@(Dependency depName verRange) ->
892895
if depName `elem` allowNewerDeps
893-
then Dependency depName (removeUpperBound verRange)
896+
then Dependency depName (vrtrans verRange)
894897
else d
895898

896899
-- | Finalize a generic package description. The workhorse is

Cabal/Distribution/Simple/Setup.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ data ConfigFlags = ConfigFlags {
416416
-- ^Halt and show an error message indicating an error in flag assignment
417417
configRelocatable :: Flag Bool, -- ^ Enable relocatable package built
418418
configDebugInfo :: Flag DebugInfoLevel, -- ^ Emit debug info.
419+
configAllowOlder :: Maybe AllowOlder, -- ^ dual to 'configAllowNewer'
419420
configAllowNewer :: Maybe AllowNewer
420421
-- ^ Ignore upper bounds on all or some dependencies. Wrapped in 'Maybe' to
421422
-- distinguish between "default" and "explicitly disabled".
@@ -713,6 +714,14 @@ configureOptions showOrParseArgs =
713714
configLibCoverage (\v flags -> flags { configLibCoverage = v })
714715
(boolOpt [] [])
715716

717+
,option [] ["allow-older"]
718+
("Ignore upper bounds in all dependencies or DEPS")
719+
(fmap unAllowOlder . configAllowOlder)
720+
(\v flags -> flags { configAllowOlder = fmap AllowOlder v})
721+
(optArg "DEPS"
722+
(readP_to_E ("Cannot parse the list of packages: " ++) relaxDepsParser)
723+
(Just RelaxDepsAll) relaxDepsPrinter)
724+
716725
,option [] ["allow-newer"]
717726
("Ignore upper bounds in all dependencies or DEPS")
718727
(fmap unAllowNewer . configAllowNewer)

Cabal/Distribution/Version.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module Distribution.Version (
7373

7474
-- ** Modification
7575
removeUpperBound,
76+
removeLowerBound,
7677

7778
-- * Version intervals view
7879
asVersionIntervals,
@@ -301,6 +302,18 @@ removeUpperBound = fromVersionIntervals . relaxLastInterval . toVersionIntervals
301302
relaxLastInterval' [(l,_)] = [(l, NoUpperBound)]
302303
relaxLastInterval' (i:is) = i : relaxLastInterval' is
303304

305+
-- | Given a version range, remove the lowest lower bound.
306+
-- Example: @(>= 1 && < 3) || (>= 4 && < 5)@ is converted to
307+
-- @(>= 0 && < 3) || (>= 4 && < 5)@.
308+
removeLowerBound :: VersionRange -> VersionRange
309+
removeLowerBound = fromVersionIntervals . relaxHeadInterval . toVersionIntervals
310+
where
311+
relaxHeadInterval (VersionIntervals intervals) =
312+
VersionIntervals (relaxHeadInterval' intervals)
313+
314+
relaxHeadInterval' [] = []
315+
relaxHeadInterval' ((_,u):is) = (minLowerBound,u) : is
316+
304317
-- | Fold over the basic syntactic structure of a 'VersionRange'.
305318
--
306319
-- This provides a syntactic view of the expression defining the version range.

Cabal/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
If you only need to test if a component is buildable
4444
(i.e., it is marked buildable in the Cabal file)
4545
use the new function 'componentBuildable'.
46+
* Add support for `--allow-older` (dual to `--allow-newer`) (#3466)
4647
* Improved an error message for process output decoding errors
4748
(#3408).
4849

Cabal/doc/installing-packages.markdown

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,14 @@ be controlled with the following command line options.
954954
for libraries it is also saved in the package registration
955955
information and used when compiling modules that use the library.
956956

957-
`--allow-newer`[=_pkgs_]
958-
: Selectively relax upper bounds in dependencies without editing the
959-
package description.
957+
`--allow-newer`[=_pkgs_], `--allow-older`[=_pkgs_]
958+
: Selectively relax upper or lower bounds in dependencies without
959+
editing the package description respectively.
960+
961+
The following description focuses on upper bounds and the
962+
`--allow-newer` flag, but applies analogously to `--allow-older`
963+
and lower bounds. `--allow-newer` and `--allow-older` can be used
964+
at the same time.
960965

961966
If you want to install a package A that depends on B >= 1.0 && < 2.0, but
962967
you have the version 2.0 of B installed, you can compile A against B 2.0 by
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: AllowOlder
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Foo Bar
5+
maintainer: cabal-dev@haskell.org
6+
build-type: Simple
7+
cabal-version: >=1.10
8+
9+
library
10+
exposed-modules: Foo
11+
hs-source-dirs: src
12+
build-depends: base > 42
13+
default-language: Haskell2010
14+
15+
test-suite foo-test
16+
type: exitcode-stdio-1.0
17+
main-is: Test.hs
18+
hs-source-dirs: tests
19+
build-depends: base > 42
20+
21+
benchmark foo-bench
22+
type: exitcode-stdio-1.0
23+
main-is: Bench.hs
24+
hs-source-dirs: benchmarks
25+
build-depends: base > 42
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main :: IO ()
4+
main = return ()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main :: IO ()
4+
main = return ()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main :: IO ()
4+
main = return ()

Cabal/tests/PackageTests/Tests.hs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,31 @@ tests config = do
261261
,"--allow-newer=Foo:base"
262262
,"--enable-tests", "--enable-benchmarks"]
263263

264+
-- Test that '--allow-older' works via the 'Setup.hs configure' interface.
265+
tc "AllowOlder" $ do
266+
shouldFail $ cabal "configure" []
267+
cabal "configure" ["--allow-older"]
268+
shouldFail $ cabal "configure" ["--allow-older=baz,quux"]
269+
cabal "configure" ["--allow-older=base", "--allow-older=baz,quux"]
270+
cabal "configure" ["--allow-older=bar", "--allow-older=base,baz"
271+
,"--allow-older=quux"]
272+
shouldFail $ cabal "configure" ["--enable-tests"]
273+
cabal "configure" ["--enable-tests", "--allow-older"]
274+
shouldFail $ cabal "configure" ["--enable-benchmarks"]
275+
cabal "configure" ["--enable-benchmarks", "--allow-older"]
276+
shouldFail $ cabal "configure" ["--enable-benchmarks", "--enable-tests"]
277+
cabal "configure" ["--enable-benchmarks", "--enable-tests"
278+
,"--allow-older"]
279+
shouldFail $ cabal "configure" ["--allow-older=Foo:base"]
280+
shouldFail $ cabal "configure" ["--allow-older=Foo:base"
281+
,"--enable-tests", "--enable-benchmarks"]
282+
cabal "configure" ["--allow-older=AllowOlder:base"]
283+
cabal "configure" ["--allow-older=AllowOlder:base"
284+
,"--allow-older=Foo:base"]
285+
cabal "configure" ["--allow-older=AllowOlder:base"
286+
,"--allow-older=Foo:base"
287+
,"--enable-tests", "--enable-benchmarks"]
288+
264289
-- Test that Cabal can choose flags to disable building a component when that
265290
-- component's dependencies are unavailable. The build should succeed without
266291
-- requiring the component's dependencies or imports.

0 commit comments

Comments
 (0)