-
Notifications
You must be signed in to change notification settings - Fork 697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additional version bound checks #10554
base: master
Are you sure you want to change the base?
Changes from all commits
2c28f2e
73d07df
ace1393
56622c1
b451782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
{-# LANGUAGE ViewPatterns #-} | ||
|
||
-- | | ||
-- Module : Distribution.PackageDescription.Check.Common | ||
-- Copyright : Francesco Ariis 2022 | ||
|
@@ -16,6 +18,10 @@ module Distribution.PackageDescription.Check.Common | |
, partitionDeps | ||
, checkPVP | ||
, checkPVPs | ||
, withoutUpperBound | ||
, leqUpperBound | ||
, trailingZeroUpperBound | ||
, gtLowerBound | ||
) where | ||
|
||
import Distribution.Compat.Prelude | ||
|
@@ -116,34 +122,58 @@ partitionDeps ads ns ds = do | |
-- for important dependencies like base). | ||
checkPVP | ||
:: Monad m | ||
=> (String -> PackageCheck) -- Warn message dependend on name | ||
=> (Dependency -> Bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we passing a new function? |
||
-> (String -> PackageCheck) -- Warn message dependend on name | ||
-- (e.g. "base", "Cabal"). | ||
-> [Dependency] | ||
-> CheckM m () | ||
checkPVP ckf ds = do | ||
let ods = checkPVPPrim ds | ||
checkPVP p ckf ds = do | ||
let ods = filter p ds | ||
mapM_ (tellP . ckf . unPackageName . depPkgName) ods | ||
|
||
-- PVP dependency check for a list of dependencies. Some code duplication | ||
-- is sadly needed to provide more ergonimic error messages. | ||
checkPVPs | ||
:: Monad m | ||
=> ( [String] | ||
=> (Dependency -> Bool) | ||
-> ( [String] | ||
-> PackageCheck -- Grouped error message, depends on a | ||
-- set of names. | ||
) | ||
-> [Dependency] -- Deps to analyse. | ||
-> CheckM m () | ||
checkPVPs cf ds | ||
checkPVPs p cf ds | ||
| null ns = return () | ||
| otherwise = tellP (cf ns) | ||
where | ||
ods = checkPVPPrim ds | ||
ods = filter p ds | ||
ns = map (unPackageName . depPkgName) ods | ||
|
||
-- Returns dependencies without upper bounds. | ||
checkPVPPrim :: [Dependency] -> [Dependency] | ||
checkPVPPrim ds = filter withoutUpper ds | ||
-- | Is the version range without an upper bound? | ||
withoutUpperBound :: Dependency -> Bool | ||
withoutUpperBound (Dependency _ ver _) = not . hasUpperBound $ ver | ||
|
||
-- | Is the upper bound version range LEQ (less or equal, <=)? | ||
leqUpperBound :: Dependency -> Bool | ||
leqUpperBound (Dependency _ ver _) | ||
Comment on lines
+152
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you considered moving this to Not a request, just want to know what your thoughts about it are. |
||
| OrEarlierVersionF _ <- projectVersionRange ver = True | ||
| otherwise = False | ||
|
||
-- | Does the upper bound version range have a trailing zero? | ||
trailingZeroUpperBound :: Dependency -> Bool | ||
trailingZeroUpperBound (Dependency _ ver _) | ||
| OrEarlierVersionF v <- projectVersionRange ver = trailingZero v | ||
| EarlierVersionF v <- projectVersionRange ver = trailingZero v | ||
| otherwise = False | ||
where | ||
withoutUpper :: Dependency -> Bool | ||
withoutUpper (Dependency _ ver _) = not . hasUpperBound $ ver | ||
trailingZero :: Version -> Bool | ||
trailingZero (versionNumbers -> vs) | ||
| [0] <- vs = False | ||
| 0 : _ <- reverse vs = True | ||
| otherwise = False | ||
|
||
-- | Is the lower bound version range GT (greater than, >)? | ||
gtLowerBound :: Dependency -> Bool | ||
gtLowerBound (Dependency _ ver _) | ||
| LaterVersionF _ <- projectVersionRange ver = True | ||
| otherwise = False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -492,7 +492,15 @@ exAvSrcPkg ex = | |
-- they are not related to this test suite, and are tested | ||
-- with golden tests. | ||
let checks = C.checkPackage (srcpkgDescription package) | ||
in filter (\x -> not (isMissingUpperBound x) && not (isUnknownLangExt x)) checks | ||
in filter | ||
( \x -> | ||
not (isgtLowerBound x) | ||
&& not (isLeqUpperBound x) | ||
&& not (isTrailingZeroUpperBound x) | ||
&& not (isMissingUpperBound x) | ||
&& not (isUnknownLangExt x) | ||
) | ||
checks | ||
in if null pkgCheckErrors | ||
then package | ||
else | ||
|
@@ -715,6 +723,18 @@ exAvSrcPkg ex = | |
isMissingUpperBound pc = case C.explanation pc of | ||
C.MissingUpperBounds{} -> True | ||
_ -> False | ||
isTrailingZeroUpperBound :: C.PackageCheck -> Bool | ||
isTrailingZeroUpperBound pc = case C.explanation pc of | ||
C.TrailingZeroUpperBounds{} -> True | ||
_ -> False | ||
isLeqUpperBound :: C.PackageCheck -> Bool | ||
isLeqUpperBound pc = case C.explanation pc of | ||
C.LEQUpperBounds{} -> True | ||
_ -> False | ||
isgtLowerBound :: C.PackageCheck -> Bool | ||
Comment on lines
+726
to
+734
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to hav multiple functions instead of one? ( |
||
isgtLowerBound pc = case C.explanation pc of | ||
C.GTLowerBounds{} -> True | ||
_ -> False | ||
|
||
mkSimpleVersion :: ExamplePkgVersion -> C.Version | ||
mkSimpleVersion n = C.mkVersion [n, 0, 0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# cabal check | ||
These warnings may cause trouble when distributing the package: | ||
Warning: [less-than-equals-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: | ||
- base | ||
Please use less than (<) for upper bounds. There is more information at https://pvp.haskell.org/ | ||
Warning: [trailing-zero-upper-bounds] On library, these packages have upper bounds with trailing zeros: | ||
- base | ||
Please avoid trailing zeros for upper bounds. There is more information at https://pvp.haskell.org/ | ||
Warning: [greater-than-lower-bounds] On library, these packages have greater than (>) lower bounds: | ||
- base | ||
Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The message is very good, but does PVP actually explains clearly why we would need such and such bounds? Maybe it is/was/will be in the FVP FAQ? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Test.Cabal.Prelude | ||
|
||
main = cabalTest $ | ||
cabal "check" [] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cabal-version: 3.0 | ||
name: pkg | ||
synopsis: synopsis | ||
description: description | ||
version: 0 | ||
category: example | ||
maintainer: [email protected] | ||
license: GPL-3.0-or-later | ||
|
||
library | ||
exposed-modules: Foo | ||
default-language: Haskell2010 | ||
build-depends: | ||
base <= 9999999 | ||
, base <= 9999999.9.9.0 | ||
, base > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this needed? How verbose would this PR become without it?