Skip to content

Commit d19f0ed

Browse files
authored
Merge pull request #5190 from phadej/forward-ports
Forward ports
2 parents 5bcde6a + 2b0ef7e commit d19f0ed

File tree

19 files changed

+235
-20
lines changed

19 files changed

+235
-20
lines changed

Cabal/Cabal.cabal

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ extra-source-files:
5050
tests/ParserTests/errors/issue-5055.errors
5151
tests/ParserTests/errors/leading-comma.cabal
5252
tests/ParserTests/errors/leading-comma.errors
53+
tests/ParserTests/errors/noVersion.cabal
54+
tests/ParserTests/errors/noVersion.errors
55+
tests/ParserTests/errors/noVersion2.cabal
56+
tests/ParserTests/errors/noVersion2.errors
5357
tests/ParserTests/errors/range-ge-wild.cabal
5458
tests/ParserTests/errors/range-ge-wild.errors
5559
tests/ParserTests/ipi/Includes2.cabal
@@ -101,6 +105,9 @@ extra-source-files:
101105
tests/ParserTests/regressions/leading-comma.cabal
102106
tests/ParserTests/regressions/leading-comma.expr
103107
tests/ParserTests/regressions/leading-comma.format
108+
tests/ParserTests/regressions/noVersion.cabal
109+
tests/ParserTests/regressions/noVersion.expr
110+
tests/ParserTests/regressions/noVersion.format
104111
tests/ParserTests/regressions/nothing-unicode.cabal
105112
tests/ParserTests/regressions/nothing-unicode.check
106113
tests/ParserTests/regressions/nothing-unicode.expr

Cabal/Distribution/CabalSpecVersion.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import qualified Data.Set as Set
1212
--
1313
data CabalSpecVersion
1414
= CabalSpecOld
15+
| CabalSpecV1_22
1516
| CabalSpecV1_24
1617
| CabalSpecV2_0
1718
| CabalSpecV2_2
@@ -22,6 +23,7 @@ cabalSpecLatest = CabalSpecV2_2
2223

2324
cabalSpecFeatures :: CabalSpecVersion -> Set.Set CabalFeature
2425
cabalSpecFeatures CabalSpecOld = Set.empty
26+
cabalSpecFeatures CabalSpecV1_22 = Set.empty
2527
cabalSpecFeatures CabalSpecV1_24 = Set.empty
2628
cabalSpecFeatures CabalSpecV2_0 = Set.empty
2729
cabalSpecFeatures CabalSpecV2_2 = Set.fromList
@@ -30,7 +32,8 @@ cabalSpecFeatures CabalSpecV2_2 = Set.fromList
3032
]
3133

3234
cabalSpecSupports :: CabalSpecVersion -> [Int] -> Bool
33-
cabalSpecSupports CabalSpecOld v = v < [1,23]
35+
cabalSpecSupports CabalSpecOld v = v < [1,21]
36+
cabalSpecSupports CabalSpecV1_22 v = v < [1,23]
3437
cabalSpecSupports CabalSpecV1_24 v = v < [1,25]
3538
cabalSpecSupports CabalSpecV2_0 v = v < [2,1]
3639
cabalSpecSupports CabalSpecV2_2 _ = True

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ checkLibrary pkg lib =
261261
, checkVersion [1,25] (not (null (signatures lib))) $
262262
PackageDistInexcusable $
263263
"To use the 'signatures' field the package needs to specify "
264-
++ "at least 'cabal-version: >= 1.25'."
264+
++ "at least 'cabal-version: 2.0'."
265265

266266
-- check that all autogen-modules appear on other-modules or exposed-modules
267267
, check
@@ -1164,20 +1164,20 @@ checkCabalVersion pkg =
11641164
(any (not.null.reexportedModules) (allLibraries pkg)) $
11651165
PackageDistInexcusable $
11661166
"To use the 'reexported-module' field the package needs to specify "
1167-
++ "at least 'cabal-version: >= 1.21'."
1167+
++ "at least 'cabal-version: >= 1.22'."
11681168

11691169
-- check use of thinning and renaming
11701170
, checkVersion [1,25] usesBackpackIncludes $
11711171
PackageDistInexcusable $
11721172
"To use the 'mixins' field the package needs to specify "
1173-
++ "at least 'cabal-version: >= 1.25'."
1173+
++ "at least 'cabal-version: 2.0'."
11741174

11751175
-- check use of 'extra-framework-dirs' field
11761176
, checkVersion [1,23] (any (not . null) (buildInfoField extraFrameworkDirs)) $
11771177
-- Just a warning, because this won't break on old Cabal versions.
11781178
PackageDistSuspiciousWarn $
11791179
"To use the 'extra-framework-dirs' field the package needs to specify"
1180-
++ " at least 'cabal-version: >= 1.23'."
1180+
++ " at least 'cabal-version: >= 1.24'."
11811181

11821182
-- check use of default-extensions field
11831183
-- don't need to do the equivalent check for other-extensions
@@ -1225,7 +1225,7 @@ checkCabalVersion pkg =
12251225
++ "'build-depends' field: "
12261226
++ commaSep (map display depsUsingMajorBoundSyntax)
12271227
++ ". To use this new syntax the package need to specify at least "
1228-
++ "'cabal-version: >= 2.0'. Alternatively, if broader compatibility "
1228+
++ "'cabal-version: 2.0'. Alternatively, if broader compatibility "
12291229
++ "is important then use: " ++ commaSep
12301230
[ display (Dependency name (eliminateMajorBoundSyntax versionRange))
12311231
| Dependency name versionRange <- depsUsingMajorBoundSyntax ]
@@ -1316,7 +1316,7 @@ checkCabalVersion pkg =
13161316
&& isNothing (setupBuildInfo pkg)
13171317
&& buildType pkg == Custom) $
13181318
PackageBuildWarning $
1319-
"Packages using 'cabal-version: >= 1.23' with 'build-type: Custom' "
1319+
"Packages using 'cabal-version: >= 1.24' with 'build-type: Custom' "
13201320
++ "must use a 'custom-setup' section with a 'setup-depends' field "
13211321
++ "that specifies the dependencies of the Setup.hs script itself. "
13221322
++ "The 'setup-depends' field uses the same syntax as 'build-depends', "
@@ -1326,8 +1326,8 @@ checkCabalVersion pkg =
13261326
&& isNothing (setupBuildInfo pkg)
13271327
&& buildType pkg == Custom) $
13281328
PackageDistSuspiciousWarn $
1329-
"From version 1.23 cabal supports specifiying explicit dependencies "
1330-
++ "for Custom setup scripts. Consider using cabal-version >= 1.23 and "
1329+
"From version 1.24 cabal supports specifiying explicit dependencies "
1330+
++ "for Custom setup scripts. Consider using cabal-version >= 1.24 and "
13311331
++ "adding a 'custom-setup' section with a 'setup-depends' field "
13321332
++ "that specifies the dependencies of the Setup.hs script itself. "
13331333
++ "The 'setup-depends' field uses the same syntax as 'build-depends', "
@@ -1337,7 +1337,7 @@ checkCabalVersion pkg =
13371337
&& elem (autogenPathsModuleName pkg) allModuleNames
13381338
&& not (elem (autogenPathsModuleName pkg) allModuleNamesAutogen) ) $
13391339
PackageDistInexcusable $
1340-
"Packages using 'cabal-version: >= 1.25' and the autogenerated "
1340+
"Packages using 'cabal-version: 2.0' and the autogenerated "
13411341
++ "module Paths_* must include it also on the 'autogen-modules' field "
13421342
++ "besides 'exposed-modules' and 'other-modules'. This specifies that "
13431343
++ "the module does not come with the package and is generated on "

Cabal/Distribution/PackageDescription/Parsec.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ parseGenericPackageDescription' cabalVerM lexWarnings utf8WarnPos fs = do
203203
| cabalVer >= mkVersion [2,1] = CabalSpecV2_2
204204
| cabalVer >= mkVersion [1,25] = CabalSpecV2_0
205205
| cabalVer >= mkVersion [1,23] = CabalSpecV1_24
206+
| cabalVer >= mkVersion [1,21] = CabalSpecV1_22
206207
| otherwise = CabalSpecOld
207208

208209
-- reset cabal version

Cabal/Distribution/Types/VersionRange.hs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import Distribution.Compat.Prelude
4545
import Distribution.Types.Version
4646
import Prelude ()
4747

48+
import Distribution.CabalSpecVersion
4849
import Distribution.Parsec.Class
4950
import Distribution.Pretty
5051
import Distribution.Text
@@ -417,7 +418,7 @@ instance Parsec VersionRange where
417418
prim = do
418419
op <- P.munch1 (`elem` "<>=^-") P.<?> "operator"
419420
case op of
420-
"-" -> anyVersion <$ P.string "any" <|> noVersion <$ P.string "none"
421+
"-" -> anyVersion <$ P.string "any" <|> P.string "none" *> noVersion'
421422

422423
"==" -> do
423424
P.spaces
@@ -432,11 +433,44 @@ instance Parsec VersionRange where
432433
case op of
433434
">=" -> pure $ orLaterVersion v
434435
"<" -> pure $ earlierVersion v
435-
"^>=" -> pure $ majorBoundVersion v
436+
"^>=" -> majorBoundVersion' v
436437
"<=" -> pure $ orEarlierVersion v
437438
">" -> pure $ laterVersion v
438439
_ -> fail $ "Unknown version operator " ++ show op
439440

441+
-- Note: There are other features:
442+
-- && and || since 1.8
443+
-- x.y.* (wildcard) since 1.6
444+
445+
-- -none version range is available since 1.22
446+
noVersion' = do
447+
csv <- askCabalSpecVersion
448+
if csv >= CabalSpecV1_22
449+
then pure noVersion
450+
else fail $ unwords
451+
[ "-none version range used."
452+
, "To use this syntax the package needs to specify at least 'cabal-version: 1.22'."
453+
, "Alternatively, if broader compatibility is important then use"
454+
, "<0 or other empty range."
455+
]
456+
457+
-- ^>= is available since 2.0
458+
majorBoundVersion' v = do
459+
csv <- askCabalSpecVersion
460+
if csv >= CabalSpecV2_0
461+
then pure $ majorBoundVersion v
462+
else fail $ unwords
463+
[ "major bounded version syntax (caret, ^>=) used."
464+
, "To use this syntax the package need to specify at least 'cabal-version: 2.0'."
465+
, "Alternatively, if broader compatibility is important then use:"
466+
, prettyShow $ eliminateMajorBoundSyntax $ majorBoundVersion v
467+
]
468+
where
469+
eliminateMajorBoundSyntax = hyloVersionRange embed projectVersionRange
470+
embed (MajorBoundVersionF u) = intersectVersionRanges
471+
(orLaterVersion u) (earlierVersion (majorUpperBound u))
472+
embed vr = embedVersionRange vr
473+
440474
-- either wildcard or normal version
441475
verOrWild :: CabalParsing m => m (Bool, Version)
442476
verOrWild = do

Cabal/doc/developing-packages.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ describe the package as a whole:
830830
type. This field is optional and when missing, its default value
831831
is inferred according to the following rules:
832832

833-
- When :pkg-field:`cabal-version` is set to ``2.1`` or higher,
833+
- When :pkg-field:`cabal-version` is set to ``2.2`` or higher,
834834
the default is ``Simple`` unless a :pkg-section:`custom-setup`
835835
exists, in which case the inferred default is ``Custom``.
836836

@@ -1102,7 +1102,7 @@ look something like this:
11021102
name: foo
11031103
version: 1.0
11041104
license: BSD3
1105-
cabal-version: >= 1.23
1105+
cabal-version: >= 1.24
11061106
build-type: Simple
11071107

11081108
library foo-internal

Cabal/tests/ParserTests.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ errorTests = testGroup "errors"
101101
, errorTest "forward-compat3.cabal"
102102
, errorTest "issue-5055.cabal"
103103
, errorTest "issue-5055-2.cabal"
104+
, errorTest "noVersion.cabal"
105+
, errorTest "noVersion2.cabal"
104106
]
105107

106108
errorTest :: FilePath -> TestTree
@@ -139,6 +141,7 @@ regressionTests = testGroup "regressions"
139141
, regressionTest "wl-pprint-indef.cabal"
140142
, regressionTest "th-lift-instances.cabal"
141143
, regressionTest "issue-5055.cabal"
144+
, regressionTest "noVersion.cabal"
142145
]
143146

144147
regressionTest :: FilePath -> TestTree
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: noVersion
2+
version: 0
3+
synopsis: -none in build-depends
4+
build-type: Simple
5+
cabal-version: 1.20
6+
7+
library
8+
default-language: Haskell2010
9+
exposed-modules: ElseIf
10+
build-depends: bad-package -none
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
VERSION: Just (mkVersion [1,20])
2+
noVersion.cabal:10:38:
3+
unexpected -none version range used. To use this syntax the package needs to specify at least 'cabal-version: 1.22'. Alternatively, if broader compatibility is important then use <0 or other empty range.
4+
5+
bad-package -none
6+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: noVersion
2+
version: 0
3+
synopsis: ^>= in build-depends
4+
build-type: Simple
5+
cabal-version: 1.20
6+
7+
library
8+
default-language: Haskell2010
9+
exposed-modules: ElseIf
10+
build-depends: bad-package ^>= 2.0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
VERSION: Just (mkVersion [1,20])
2+
noVersion2.cabal:10:40:
3+
unexpected major bounded version syntax (caret, ^>=) used. To use this syntax the package need to specify at least 'cabal-version: 2.0'. Alternatively, if broader compatibility is important then use: >=2.0 && <2.1
4+
expecting "." or "-"
5+
6+
bad-package ^>= 2.0
7+
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
'ghc-options: -O2' is rarely needed. Check that it is giving a real benefit and not just imposing longer compile times on your users.
2-
The package uses major bounded version syntax in the 'build-depends' field: base ^>=4.10.0, Cabal ^>=2.0.0, ghc ^>=8.2, ghc-paths ^>=0.1.0.9, xhtml ^>=3000.2.2, ghc ^>=8.2, hspec ^>=2.4.4, QuickCheck ^>=2.10. To use this new syntax the package need to specify at least 'cabal-version: >= 2.0'. Alternatively, if broader compatibility is important then use: base >=4.10.0 && <4.11, Cabal >=2.0.0 && <2.1, ghc >=8.2 && <8.3, ghc-paths >=0.1.0.9 && <0.2, xhtml >=3000.2.2 && <3000.3, ghc >=8.2 && <8.3, hspec >=2.4.4 && <2.5, QuickCheck >=2.10 && <2.11
1+
ERROR: haddock-api-2.18.1-check.cabal:41:44:
2+
unexpected major bounded version syntax (caret, ^>=) used. To use this syntax the package need to specify at least 'cabal-version: 2.0'. Alternatively, if broader compatibility is important then use: >=4.10.0 && <4.11
3+
expecting "." or "-"
4+
5+
base ^>= 4.10.0
6+
, Cabal ^>= 2.0.0
7+
, ghc ^>= 8.2
8+
, ghc-paths ^>= 0.1.0.9
9+
, haddock-library == 1.4.4.*
10+
, xhtml ^>= 3000.2.2
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: noVersion
2+
version: 0
3+
synopsis: -none in build-depends
4+
build-type: Simple
5+
cabal-version: 1.22
6+
7+
library
8+
default-language: Haskell2010
9+
exposed-modules: ElseIf
10+
11+
build-depends: bad-package -none
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
GenericPackageDescription
2+
{condBenchmarks = [],
3+
condExecutables = [],
4+
condForeignLibs = [],
5+
condLibrary = Just
6+
CondNode
7+
{condTreeComponents = [],
8+
condTreeConstraints = [Dependency
9+
`PackageName "bad-package"`
10+
(IntersectVersionRanges
11+
(LaterVersion `mkVersion [1]`)
12+
(EarlierVersion `mkVersion [1]`))],
13+
condTreeData = Library
14+
{exposedModules = [`ModuleName ["ElseIf"]`],
15+
libBuildInfo = BuildInfo
16+
{asmOptions = [],
17+
asmSources = [],
18+
autogenModules = [],
19+
buildToolDepends = [],
20+
buildTools = [],
21+
buildable = True,
22+
cSources = [],
23+
ccOptions = [],
24+
cmmOptions = [],
25+
cmmSources = [],
26+
cppOptions = [],
27+
customFieldsBI = [],
28+
cxxOptions = [],
29+
cxxSources = [],
30+
defaultExtensions = [],
31+
defaultLanguage = Just Haskell2010,
32+
extraBundledLibs = [],
33+
extraFrameworkDirs = [],
34+
extraGHCiLibs = [],
35+
extraLibDirs = [],
36+
extraLibFlavours = [],
37+
extraLibs = [],
38+
frameworks = [],
39+
hsSourceDirs = [],
40+
includeDirs = [],
41+
includes = [],
42+
installIncludes = [],
43+
jsSources = [],
44+
ldOptions = [],
45+
mixins = [],
46+
oldExtensions = [],
47+
options = [],
48+
otherExtensions = [],
49+
otherLanguages = [],
50+
otherModules = [],
51+
pkgconfigDepends = [],
52+
profOptions = [],
53+
sharedOptions = [],
54+
staticOptions = [],
55+
targetBuildDepends = [Dependency
56+
`PackageName "bad-package"`
57+
(IntersectVersionRanges
58+
(LaterVersion
59+
`mkVersion [1]`)
60+
(EarlierVersion
61+
`mkVersion [1]`))],
62+
virtualModules = []},
63+
libExposed = True,
64+
libName = Nothing,
65+
reexportedModules = [],
66+
signatures = []}},
67+
condSubLibraries = [],
68+
condTestSuites = [],
69+
genPackageFlags = [],
70+
packageDescription = PackageDescription
71+
{author = "",
72+
benchmarks = [],
73+
bugReports = "",
74+
buildTypeRaw = Just Simple,
75+
category = "",
76+
copyright = "",
77+
customFieldsPD = [],
78+
dataDir = "",
79+
dataFiles = [],
80+
description = "",
81+
executables = [],
82+
extraDocFiles = [],
83+
extraSrcFiles = [],
84+
extraTmpFiles = [],
85+
foreignLibs = [],
86+
homepage = "",
87+
library = Nothing,
88+
licenseFiles = [],
89+
licenseRaw = Left NONE,
90+
maintainer = "",
91+
package = PackageIdentifier
92+
{pkgName = `PackageName "noVersion"`,
93+
pkgVersion = `mkVersion [0]`},
94+
pkgUrl = "",
95+
setupBuildInfo = Nothing,
96+
sourceRepos = [],
97+
specVersionRaw = Left `mkVersion [1,22]`,
98+
stability = "",
99+
subLibraries = [],
100+
synopsis = "-none in build-depends",
101+
testSuites = [],
102+
testedWith = []}}

0 commit comments

Comments
 (0)