From 2dc4bf8d457427db06fec2f91303789e323dc4fb Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 18 Nov 2024 08:57:59 -0500 Subject: [PATCH 01/24] Add package bounds breaking checks - Check for LEQ upper bounds - Check for GT lower bounds - Check for trailing zero upper bounds - Add missing gtLowerBound to checks - Handle ^>= versions with its IntersectVersionRangesF - Set baseline for cabal init generated bounds - Use recursive functions for checking bounds - Handle union version ranges --- .../Distribution/PackageDescription/Check.hs | 16 +++- .../PackageDescription/Check/Common.hs | 79 ++++++++++++++++--- .../PackageDescription/Check/Target.hs | 19 ++++- .../PackageDescription/Check/Warning.hs | 42 ++++++++++ .../Distribution/Solver/Modular/DSL.hs | 22 +++++- .../PackageFiles/VersionBounds/cabal.out | 18 +++++ .../PackageFiles/VersionBounds/cabal.test.hs | 4 + .../PackageFiles/VersionBounds/pkg.cabal | 25 ++++++ 8 files changed, 207 insertions(+), 18 deletions(-) create mode 100644 cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out create mode 100644 cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/pkg.cabal diff --git a/Cabal/src/Distribution/PackageDescription/Check.hs b/Cabal/src/Distribution/PackageDescription/Check.hs index 8bab6ec961a..7cf30744263 100644 --- a/Cabal/src/Distribution/PackageDescription/Check.hs +++ b/Cabal/src/Distribution/PackageDescription/Check.hs @@ -568,8 +568,20 @@ checkSetupBuildInfo (Just (SetupBuildInfo ds _)) = do rck = PackageDistSuspiciousWarn . MissingUpperBounds CETSetup - checkPVP ick is - checkPVPs rck rs + lequck = + PackageDistSuspiciousWarn + . LEQUpperBounds CETSetup + tzuck = + PackageDistSuspiciousWarn + . TrailingZeroUpperBounds CETSetup + gtlck = + PackageDistSuspiciousWarn + . GTLowerBounds CETSetup + checkPVP withoutUpperBound ick is + checkPVPs withoutUpperBound rck rs + checkPVPs leqUpperBound lequck ds + checkPVPs trailingZeroUpperBound tzuck ds + checkPVPs gtLowerBound gtlck ds checkPackageId :: Monad m => PackageIdentifier -> CheckM m () checkPackageId (PackageIdentifier pkgName_ _pkgVersion_) = do diff --git a/Cabal/src/Distribution/PackageDescription/Check/Common.hs b/Cabal/src/Distribution/PackageDescription/Check/Common.hs index 5bdf5c33fe7..80cd14de791 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Common.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Common.hs @@ -1,3 +1,6 @@ +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE ViewPatterns #-} + -- | -- Module : Distribution.PackageDescription.Check.Common -- Copyright : Francesco Ariis 2022 @@ -16,6 +19,10 @@ module Distribution.PackageDescription.Check.Common , partitionDeps , checkPVP , checkPVPs + , withoutUpperBound + , leqUpperBound + , trailingZeroUpperBound + , gtLowerBound ) where import Distribution.Compat.Prelude @@ -116,34 +123,82 @@ partitionDeps ads ns ds = do -- for important dependencies like base). checkPVP :: Monad m - => (String -> PackageCheck) -- Warn message depends on name + => (Dependency -> Bool) + -> (String -> PackageCheck) -- Warn message depends 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 - where - withoutUpper :: Dependency -> Bool - withoutUpper (Dependency _ ver _) = not . hasUpperBound $ ver +-- | 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 _) = isLEQUpperBound ver + +-- | Does the upper bound version range have a trailing zero? +trailingZeroUpperBound :: Dependency -> Bool +trailingZeroUpperBound (Dependency _ ver _) = isTrailingZeroUpperBound ver + +-- | Is the lower bound version range GT (greater than, >)? +gtLowerBound :: Dependency -> Bool +gtLowerBound (Dependency _ ver _) = isGTLowerBound ver + +pattern IsLEQUpperBound, IsGTLowerBound, IsTrailingZeroUpperBound :: VersionRangeF a +pattern IsLEQUpperBound <- OrEarlierVersionF _ +pattern IsGTLowerBound <- LaterVersionF _ +pattern IsTrailingZeroUpperBound <- (upperTrailingZero -> True) + +upperTrailingZero :: VersionRangeF a -> Bool +upperTrailingZero (OrEarlierVersionF x) = trailingZero x +upperTrailingZero (EarlierVersionF x) = trailingZero x +upperTrailingZero _ = False + +trailingZero :: Version -> Bool +trailingZero (versionNumbers -> vs) + | [0] <- vs = False + | 0 : _ <- reverse vs = True + | otherwise = False + +isLEQUpperBound :: VersionRange -> Bool +isLEQUpperBound (projectVersionRange -> v) + | IsLEQUpperBound <- v = True + | IntersectVersionRangesF x y <- v = isLEQUpperBound x || isLEQUpperBound y + | UnionVersionRangesF x y <- v = isLEQUpperBound x || isLEQUpperBound y + | otherwise = False + +isGTLowerBound :: VersionRange -> Bool +isGTLowerBound (projectVersionRange -> v) + | IsGTLowerBound <- v = True + | IntersectVersionRangesF x y <- v = isGTLowerBound x || isGTLowerBound y + | UnionVersionRangesF x y <- v = isGTLowerBound x || isGTLowerBound y + | otherwise = False + +isTrailingZeroUpperBound :: VersionRange -> Bool +isTrailingZeroUpperBound (projectVersionRange -> v) + | IsTrailingZeroUpperBound <- v = True + | IntersectVersionRangesF x y <- v = isTrailingZeroUpperBound x || isTrailingZeroUpperBound y + | UnionVersionRangesF x y <- v = isTrailingZeroUpperBound x || isTrailingZeroUpperBound y + | otherwise = False diff --git a/Cabal/src/Distribution/PackageDescription/Check/Target.hs b/Cabal/src/Distribution/PackageDescription/Check/Target.hs index c40fc0ef09a..4451a94b73c 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Target.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Target.hs @@ -331,17 +331,30 @@ checkBuildInfo cet ams ads bi = do checkAutogenModules ams bi -- PVP: we check for base and all other deps. + let ds = mergeDependencies $ targetBuildDepends bi (ids, rds) <- partitionDeps ads [mkUnqualComponentName "base"] - (mergeDependencies $ targetBuildDepends bi) + ds let ick = const (PackageDistInexcusable BaseNoUpperBounds) rck = PackageDistSuspiciousWarn . MissingUpperBounds cet - checkPVP ick ids + lequck = PackageDistSuspiciousWarn . LEQUpperBounds cet + tzuck = PackageDistSuspiciousWarn . TrailingZeroUpperBounds cet + gtlck = PackageDistSuspiciousWarn . GTLowerBounds cet + checkPVP withoutUpperBound ick ids unless (isInternalTarget cet) - (checkPVPs rck rds) + (checkPVPs withoutUpperBound rck rds) + unless + (isInternalTarget cet) + (checkPVPs leqUpperBound lequck ds) + unless + (isInternalTarget cet) + (checkPVPs trailingZeroUpperBound tzuck ds) + unless + (isInternalTarget cet) + (checkPVPs gtLowerBound gtlck ds) -- Custom fields well-formedness (ASCII). mapM_ checkCustomField (customFieldsBI bi) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index 8f388635342..cb0d4ff1d7b 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -255,6 +255,9 @@ data CheckExplanation | UnknownCompiler [String] | BaseNoUpperBounds | MissingUpperBounds CEType [String] + | LEQUpperBounds CEType [String] + | TrailingZeroUpperBounds CEType [String] + | GTLowerBounds CEType [String] | SuspiciousFlagName [String] | DeclaredUsedFlags (Set.Set FlagName) (Set.Set FlagName) | NonASCIICustomField [String] @@ -418,6 +421,9 @@ data CheckExplanationID | CIUnknownCompiler | CIBaseNoUpperBounds | CIMissingUpperBounds + | CILEQUpperBounds + | CITrailingZeroUpperBounds + | CIGTLowerBounds | CISuspiciousFlagName | CIDeclaredUsedFlags | CINonASCIICustomField @@ -560,6 +566,9 @@ checkExplanationId (UnknownArch{}) = CIUnknownArch checkExplanationId (UnknownCompiler{}) = CIUnknownCompiler checkExplanationId (BaseNoUpperBounds{}) = CIBaseNoUpperBounds checkExplanationId (MissingUpperBounds{}) = CIMissingUpperBounds +checkExplanationId (LEQUpperBounds{}) = CILEQUpperBounds +checkExplanationId (TrailingZeroUpperBounds{}) = CITrailingZeroUpperBounds +checkExplanationId (GTLowerBounds{}) = CIGTLowerBounds checkExplanationId (SuspiciousFlagName{}) = CISuspiciousFlagName checkExplanationId (DeclaredUsedFlags{}) = CIDeclaredUsedFlags checkExplanationId (NonASCIICustomField{}) = CINonASCIICustomField @@ -707,6 +716,9 @@ ppCheckExplanationId CIUnknownArch = "unknown-arch" ppCheckExplanationId CIUnknownCompiler = "unknown-compiler" ppCheckExplanationId CIBaseNoUpperBounds = "missing-bounds-important" ppCheckExplanationId CIMissingUpperBounds = "missing-upper-bounds" +ppCheckExplanationId CILEQUpperBounds = "less-than-equals-upper-bounds" +ppCheckExplanationId CITrailingZeroUpperBounds = "trailing-zero-upper-bounds" +ppCheckExplanationId CIGTLowerBounds = "greater-than-lower-bounds" ppCheckExplanationId CISuspiciousFlagName = "suspicious-flag" ppCheckExplanationId CIDeclaredUsedFlags = "unused-flag" ppCheckExplanationId CINonASCIICustomField = "non-ascii" @@ -1309,6 +1321,36 @@ ppExplanation (MissingUpperBounds ct names) = ++ List.intercalate separator names ++ "\n" ++ "Please add them. There is more information at https://pvp.haskell.org/" +ppExplanation (LEQUpperBounds ct names) = + let separator = "\n - " + in "On " + ++ ppCET ct + ++ ", " + ++ "these packages have less than or equals (<=) upper bounds:" + ++ separator + ++ List.intercalate separator names + ++ "\n" + ++ "Please use less than (<) for upper bounds. There is more information at https://pvp.haskell.org/" +ppExplanation (TrailingZeroUpperBounds ct names) = + let separator = "\n - " + in "On " + ++ ppCET ct + ++ ", " + ++ "these packages have upper bounds with trailing zeros:" + ++ separator + ++ List.intercalate separator names + ++ "\n" + ++ "Please avoid trailing zeros for upper bounds. There is more information at https://pvp.haskell.org/" +ppExplanation (GTLowerBounds ct names) = + let separator = "\n - " + in "On " + ++ ppCET ct + ++ ", " + ++ "these packages have greater than (>) lower bounds:" + ++ separator + ++ List.intercalate separator names + ++ "\n" + ++ "Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/" ppExplanation (SuspiciousFlagName invalidFlagNames) = "Suspicious flag names: " ++ unwords invalidFlagNames diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs index d1d70f59348..bb62f56968e 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs @@ -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 + isgtLowerBound pc = case C.explanation pc of + C.GTLowerBounds{} -> True + _ -> False mkSimpleVersion :: ExamplePkgVersion -> C.Version mkSimpleVersion n = C.mkVersion [n, 0, 0] diff --git a/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out new file mode 100644 index 00000000000..95831ae0af7 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out @@ -0,0 +1,18 @@ +# cabal check +These warnings may cause trouble when distributing the package: +Warning: [missing-upper-bounds] On library, these packages miss upper bounds: + - missing-upper + - exclusive-minimums-missing-upper + - or-exclusive-minimums-missing-upper + - or-inclusive-maximums-missing-upper +Please add them. There is more information at https://pvp.haskell.org/ +Warning: [less-than-equals-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: + - inclusive-maximums + - and-inclusive-maximums + - or-inclusive-maximums-missing-upper +Please use less than (<) 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: + - exclusive-minimums-missing-upper + - and-exclusive-minimums + - or-exclusive-minimums-missing-upper +Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ diff --git a/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.test.hs b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.test.hs new file mode 100644 index 00000000000..60a32cb7374 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.test.hs @@ -0,0 +1,4 @@ +import Test.Cabal.Prelude + +main = cabalTest $ + cabal "check" [] diff --git a/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/pkg.cabal b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/pkg.cabal new file mode 100644 index 00000000000..f8fc673e14c --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/pkg.cabal @@ -0,0 +1,25 @@ +cabal-version: 3.0 +name: pkg +synopsis: synopsis +description: description +version: 0 +category: example +maintainer: none@example.com +license: GPL-3.0-or-later + +library + exposed-modules: Foo + default-language: Haskell2010 + build-depends: + , base ^>= 4.20.0.0 + + , missing-upper >= 0 + , missing-lower < 1 + + , exclusive-minimums-missing-upper > 0 + , and-exclusive-minimums > 0 && < 1 + , or-exclusive-minimums-missing-upper > 0 || < 1 + + , inclusive-maximums <= 1 + , and-inclusive-maximums >= 0 && <= 1 + , or-inclusive-maximums-missing-upper >= 0 || <= 1 From 235757f64b65c726c2b39b06048d58df230f17ff Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Tue, 19 Nov 2024 15:47:46 -0500 Subject: [PATCH 02/24] Update test expectations with --accept in other tests --- .../Fields/ImpossibleVersionRangeLib/cabal.out | 7 +++++++ .../Check/NonConfCheck/PackageVersionsInternal/cabal.out | 5 ++++- .../NonConfCheck/PackageVersionsInternalSimple/cabal.out | 3 +++ .../Check/NonConfCheck/PackageVersionsLibInt/cabal.out | 6 ++++++ .../Check/NonConfCheck/PackageVersionsStraddle/cabal.out | 8 +++++++- .../PackageTests/Check/NonConfCheck/SetupBounds/cabal.out | 4 ++++ 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out index c037b09c0f5..9176ef50885 100644 --- a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out @@ -1,4 +1,11 @@ # cabal check The package will not build sanely due to these errors: Error: [impossible-dep] The package has an impossible version range for a dependency on an internal library: pkg:internal >1.0 && <2.0. This version range does not include the current package, and must be removed as the current package's library will always be used. +These warnings may cause trouble when distributing the package: +Warning: [trailing-zero-upper-bounds] On library, these packages have upper bounds with trailing zeros: + - pkg +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: + - pkg +Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ Error: Hackage would reject this package. diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out index 37aa169b416..8e4746f0641 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out @@ -1,2 +1,5 @@ # cabal check -No errors or warnings could be found in the package. +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/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out index 2c1d8a72480..d9c4158226b 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out @@ -3,3 +3,6 @@ These warnings may cause trouble when distributing the package: Warning: [missing-upper-bounds] On executable 'prova', these packages miss upper bounds: - acme-box Please add them. There is more information at https://pvp.haskell.org/ +Warning: [trailing-zero-upper-bounds] On library, these packages have upper bounds with trailing zeros: + - text +Please avoid trailing zeros for upper bounds. There is more information at https://pvp.haskell.org/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out index c9f531cbd6e..d5a6767b30d 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out @@ -3,3 +3,9 @@ These warnings may cause trouble when distributing the package: Warning: [missing-upper-bounds] On library 'int-lib', these packages miss upper bounds: - text Please add them. There is more information at https://pvp.haskell.org/ +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: [greater-than-lower-bounds] On library 'int-lib', these packages have greater than (>) lower bounds: + - text +Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out index 37aa169b416..464c0933ab8 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out @@ -1,2 +1,8 @@ # cabal check -No errors or warnings could be found in the package. +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: [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/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out index 895d3a63943..6ca7b6d2e4f 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out @@ -1,4 +1,8 @@ # cabal check +These warnings may cause trouble when distributing the package: +Warning: [greater-than-lower-bounds] On custom-setup, 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/ The following errors will cause portability problems on other environments: Error: [missing-bounds-setup] The dependency 'setup-depends: 'base' does not specify an upper bound on the version number. Each major release of the 'base' package changes the API in various ways and most packages will need some changes to compile with it. If you are not sure what upper bound to use then use the next major version. Error: Hackage would reject this package. From 5ed03ce6cb67bad300d06b864b5beea327216e84 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Wed, 20 Nov 2024 08:51:37 -0500 Subject: [PATCH 03/24] Use inclusive lower bound for issue-8646.cabal --- Cabal-tests/tests/ParserTests/regressions/issue-8646.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cabal-tests/tests/ParserTests/regressions/issue-8646.cabal b/Cabal-tests/tests/ParserTests/regressions/issue-8646.cabal index d631357925f..c7576037132 100644 --- a/Cabal-tests/tests/ParserTests/regressions/issue-8646.cabal +++ b/Cabal-tests/tests/ParserTests/regressions/issue-8646.cabal @@ -11,6 +11,6 @@ license: BSD-3-Clause executable test main-is: ExeMain.hs - build-depends: base > 4 && < 5 + build-depends: base >= 4 && < 5 default-language: Haskell2010 ghc-options: -main-is ExeMain From 275156f7c3417245316d72e7f25ac4baf52f406f Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Wed, 20 Nov 2024 09:16:09 -0500 Subject: [PATCH 04/24] Satisfy the parsimonious test for messages --- .../src/Distribution/PackageDescription/Check/Warning.hs | 9 ++++++--- .../Fields/ImpossibleVersionRangeLib/cabal.out | 4 ++-- .../Check/NonConfCheck/PackageVersionsInternal/cabal.out | 2 +- .../NonConfCheck/PackageVersionsInternalSimple/cabal.out | 2 +- .../Check/NonConfCheck/PackageVersionsLibInt/cabal.out | 4 ++-- .../Check/NonConfCheck/PackageVersionsStraddle/cabal.out | 4 ++-- .../Check/NonConfCheck/SetupBounds/cabal.out | 2 +- .../Check/PackageFiles/VersionBounds/cabal.out | 4 ++-- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index cb0d4ff1d7b..79b13f2f3bf 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -716,9 +716,12 @@ ppCheckExplanationId CIUnknownArch = "unknown-arch" ppCheckExplanationId CIUnknownCompiler = "unknown-compiler" ppCheckExplanationId CIBaseNoUpperBounds = "missing-bounds-important" ppCheckExplanationId CIMissingUpperBounds = "missing-upper-bounds" -ppCheckExplanationId CILEQUpperBounds = "less-than-equals-upper-bounds" -ppCheckExplanationId CITrailingZeroUpperBounds = "trailing-zero-upper-bounds" -ppCheckExplanationId CIGTLowerBounds = "greater-than-lower-bounds" +-- NOTE: Satisfy the Parsimonious test, a test that checks that these messages +-- don't have too many dashes: +-- $ cabal run Cabal-tests:unit-tests -- --pattern=Parsimonious +ppCheckExplanationId CILEQUpperBounds = "less.than.equals(<=)-upper-bounds" +ppCheckExplanationId CITrailingZeroUpperBounds = "trailing.zero(*.0)-upper-bounds" +ppCheckExplanationId CIGTLowerBounds = "greater.than(>)-lower-bounds" ppCheckExplanationId CISuspiciousFlagName = "suspicious-flag" ppCheckExplanationId CIDeclaredUsedFlags = "unused-flag" ppCheckExplanationId CINonASCIICustomField = "non-ascii" diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out index 9176ef50885..59f7435722b 100644 --- a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out @@ -2,10 +2,10 @@ The package will not build sanely due to these errors: Error: [impossible-dep] The package has an impossible version range for a dependency on an internal library: pkg:internal >1.0 && <2.0. This version range does not include the current package, and must be removed as the current package's library will always be used. These warnings may cause trouble when distributing the package: -Warning: [trailing-zero-upper-bounds] On library, these packages have upper bounds with trailing zeros: +Warning: [trailing.zero(*.0)-upper-bounds] On library, these packages have upper bounds with trailing zeros: - pkg 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: +Warning: [greater.than(>)-lower-bounds] On library, these packages have greater than (>) lower bounds: - pkg Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ Error: Hackage would reject this package. diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out index 8e4746f0641..be4c499fac0 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out @@ -1,5 +1,5 @@ # 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: +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/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out index d9c4158226b..baf3b85f40f 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out @@ -3,6 +3,6 @@ These warnings may cause trouble when distributing the package: Warning: [missing-upper-bounds] On executable 'prova', these packages miss upper bounds: - acme-box Please add them. There is more information at https://pvp.haskell.org/ -Warning: [trailing-zero-upper-bounds] On library, these packages have upper bounds with trailing zeros: +Warning: [trailing.zero(*.0)-upper-bounds] On library, these packages have upper bounds with trailing zeros: - text Please avoid trailing zeros for upper bounds. There is more information at https://pvp.haskell.org/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out index d5a6767b30d..304dc862f76 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out @@ -3,9 +3,9 @@ These warnings may cause trouble when distributing the package: Warning: [missing-upper-bounds] On library 'int-lib', these packages miss upper bounds: - text Please add them. There is more information at https://pvp.haskell.org/ -Warning: [less-than-equals-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: +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: [greater-than-lower-bounds] On library 'int-lib', these packages have greater than (>) lower bounds: +Warning: [greater.than(>)-lower-bounds] On library 'int-lib', these packages have greater than (>) lower bounds: - text Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out index 464c0933ab8..ff081197a29 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out @@ -1,8 +1,8 @@ # 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: +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: [greater-than-lower-bounds] On library, these packages have greater than (>) lower bounds: +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/ diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out index 6ca7b6d2e4f..1732b3fccd9 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out @@ -1,6 +1,6 @@ # cabal check These warnings may cause trouble when distributing the package: -Warning: [greater-than-lower-bounds] On custom-setup, these packages have greater than (>) lower bounds: +Warning: [greater.than(>)-lower-bounds] On custom-setup, 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/ The following errors will cause portability problems on other environments: diff --git a/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out index 95831ae0af7..4352ab832e7 100644 --- a/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out +++ b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out @@ -6,12 +6,12 @@ Warning: [missing-upper-bounds] On library, these packages miss upper bounds: - or-exclusive-minimums-missing-upper - or-inclusive-maximums-missing-upper Please add them. There is more information at https://pvp.haskell.org/ -Warning: [less-than-equals-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: +Warning: [less.than.equals(<=)-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: - inclusive-maximums - and-inclusive-maximums - or-inclusive-maximums-missing-upper Please use less than (<) 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: +Warning: [greater.than(>)-lower-bounds] On library, these packages have greater than (>) lower bounds: - exclusive-minimums-missing-upper - and-exclusive-minimums - or-exclusive-minimums-missing-upper From f4cb6080ea18caa23c24f00e8561bbd0b41080ca Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Wed, 20 Nov 2024 12:16:17 -0500 Subject: [PATCH 05/24] Allow exceptions to 25 char limit explain ids --- .../UnitTests/Distribution/PackageDescription/Check.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs b/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs index 662a0684cda..e167e4de07d 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs @@ -18,7 +18,11 @@ import Test.QuickCheck.Instances.Cabal () tests :: [TestTree] tests = [ testCase "Unique ignore strings" (uniqueNames @?= True) - , testCase "Short ignore identifiers" (longerThan @?= []) + , testCase "Short ignore identifiers" (longerThan @?= + [ "less.than.equals(<=)-upper-bounds" + , "trailing.zero(*.0)-upper-bounds" + , "greater.than(>)-lower-bounds" + ]) , testCase "Parsimonious '-' use" (usingTooManyDashes @?= []) ] where From 6468def9388140fa42a95ae721a0a2f8a1c31bed Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Wed, 20 Nov 2024 14:48:14 -0500 Subject: [PATCH 06/24] Rename Is* to Has* to match previous predicates --- .../PackageDescription/Check/Common.hs | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Common.hs b/Cabal/src/Distribution/PackageDescription/Check/Common.hs index 80cd14de791..9b222990560 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Common.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Common.hs @@ -156,20 +156,20 @@ withoutUpperBound (Dependency _ ver _) = not . hasUpperBound $ ver -- | Is the upper bound version range LEQ (less or equal, <=)? leqUpperBound :: Dependency -> Bool -leqUpperBound (Dependency _ ver _) = isLEQUpperBound ver +leqUpperBound (Dependency _ ver _) = hasLEQUpperBound ver -- | Does the upper bound version range have a trailing zero? trailingZeroUpperBound :: Dependency -> Bool -trailingZeroUpperBound (Dependency _ ver _) = isTrailingZeroUpperBound ver +trailingZeroUpperBound (Dependency _ ver _) = hasTrailingZeroUpperBound ver -- | Is the lower bound version range GT (greater than, >)? gtLowerBound :: Dependency -> Bool -gtLowerBound (Dependency _ ver _) = isGTLowerBound ver +gtLowerBound (Dependency _ ver _) = hasGTLowerBound ver -pattern IsLEQUpperBound, IsGTLowerBound, IsTrailingZeroUpperBound :: VersionRangeF a -pattern IsLEQUpperBound <- OrEarlierVersionF _ -pattern IsGTLowerBound <- LaterVersionF _ -pattern IsTrailingZeroUpperBound <- (upperTrailingZero -> True) +pattern HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound :: VersionRangeF a +pattern HasLEQUpperBound <- OrEarlierVersionF _ +pattern HasGTLowerBound <- LaterVersionF _ +pattern HasTrailingZeroUpperBound <- (upperTrailingZero -> True) upperTrailingZero :: VersionRangeF a -> Bool upperTrailingZero (OrEarlierVersionF x) = trailingZero x @@ -182,23 +182,23 @@ trailingZero (versionNumbers -> vs) | 0 : _ <- reverse vs = True | otherwise = False -isLEQUpperBound :: VersionRange -> Bool -isLEQUpperBound (projectVersionRange -> v) - | IsLEQUpperBound <- v = True - | IntersectVersionRangesF x y <- v = isLEQUpperBound x || isLEQUpperBound y - | UnionVersionRangesF x y <- v = isLEQUpperBound x || isLEQUpperBound y +hasLEQUpperBound :: VersionRange -> Bool +hasLEQUpperBound (projectVersionRange -> v) + | HasLEQUpperBound <- v = True + | IntersectVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y + | UnionVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y | otherwise = False -isGTLowerBound :: VersionRange -> Bool -isGTLowerBound (projectVersionRange -> v) - | IsGTLowerBound <- v = True - | IntersectVersionRangesF x y <- v = isGTLowerBound x || isGTLowerBound y - | UnionVersionRangesF x y <- v = isGTLowerBound x || isGTLowerBound y +hasGTLowerBound :: VersionRange -> Bool +hasGTLowerBound (projectVersionRange -> v) + | HasGTLowerBound <- v = True + | IntersectVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y + | UnionVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y | otherwise = False -isTrailingZeroUpperBound :: VersionRange -> Bool -isTrailingZeroUpperBound (projectVersionRange -> v) - | IsTrailingZeroUpperBound <- v = True - | IntersectVersionRangesF x y <- v = isTrailingZeroUpperBound x || isTrailingZeroUpperBound y - | UnionVersionRangesF x y <- v = isTrailingZeroUpperBound x || isTrailingZeroUpperBound y +hasTrailingZeroUpperBound :: VersionRange -> Bool +hasTrailingZeroUpperBound (projectVersionRange -> v) + | HasTrailingZeroUpperBound <- v = True + | IntersectVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y + | UnionVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y | otherwise = False From 5cdd62bf6433575ee0d4a85f06739475e149b5bb Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Wed, 20 Nov 2024 15:56:29 -0500 Subject: [PATCH 07/24] Move predicates to VersionRange module --- .../src/Distribution/Types/VersionRange.hs | 46 +++++++++++++++ Cabal-syntax/src/Distribution/Version.hs | 3 + .../Distribution/PackageDescription/Check.hs | 10 ++-- .../PackageDescription/Check/Common.hs | 59 +------------------ .../PackageDescription/Check/Target.hs | 10 ++-- 5 files changed, 62 insertions(+), 66 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange.hs b/Cabal-syntax/src/Distribution/Types/VersionRange.hs index c470b93c0d2..2f72f084bdc 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange.hs @@ -1,3 +1,6 @@ +{-# LANGUAGE PatternSynonyms #-} +{-# LANGUAGE ViewPatterns #-} + module Distribution.Types.VersionRange ( -- * Version ranges VersionRange @@ -26,6 +29,9 @@ module Distribution.Types.VersionRange , stripParensVersionRange , hasUpperBound , hasLowerBound + , hasLEQUpperBound + , hasTrailingZeroUpperBound + , hasGTLowerBound -- ** Cata & ana , VersionRangeF (..) @@ -197,3 +203,43 @@ hasLowerBound = (const False) (&&) (||) + +pattern HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound :: VersionRangeF a +pattern HasLEQUpperBound <- OrEarlierVersionF _ +pattern HasGTLowerBound <- LaterVersionF _ +pattern HasTrailingZeroUpperBound <- (upperTrailingZero -> True) + +upperTrailingZero :: VersionRangeF a -> Bool +upperTrailingZero (OrEarlierVersionF x) = trailingZero x +upperTrailingZero (EarlierVersionF x) = trailingZero x +upperTrailingZero _ = False + +trailingZero :: Version -> Bool +trailingZero (versionNumbers -> vs) + | [0] <- vs = False + | 0 : _ <- reverse vs = True + | otherwise = False + +-- | Is the upper bound version range LEQ (less or equal, <=)? +hasLEQUpperBound :: VersionRange -> Bool +hasLEQUpperBound (projectVersionRange -> v) + | HasLEQUpperBound <- v = True + | IntersectVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y + | UnionVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y + | otherwise = False + +-- | Is the lower bound version range GT (greater than, >)? +hasGTLowerBound :: VersionRange -> Bool +hasGTLowerBound (projectVersionRange -> v) + | HasGTLowerBound <- v = True + | IntersectVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y + | UnionVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y + | otherwise = False + +-- | Does the upper bound version range have a trailing zero? +hasTrailingZeroUpperBound :: VersionRange -> Bool +hasTrailingZeroUpperBound (projectVersionRange -> v) + | HasTrailingZeroUpperBound <- v = True + | IntersectVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y + | UnionVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y + | otherwise = False diff --git a/Cabal-syntax/src/Distribution/Version.hs b/Cabal-syntax/src/Distribution/Version.hs index 80383358037..f460da2648b 100644 --- a/Cabal-syntax/src/Distribution/Version.hs +++ b/Cabal-syntax/src/Distribution/Version.hs @@ -50,6 +50,9 @@ module Distribution.Version , stripParensVersionRange , hasUpperBound , hasLowerBound + , hasLEQUpperBound + , hasTrailingZeroUpperBound + , hasGTLowerBound -- ** Cata & ana , VersionRangeF (..) diff --git a/Cabal/src/Distribution/PackageDescription/Check.hs b/Cabal/src/Distribution/PackageDescription/Check.hs index 7cf30744263..3f9879b99f3 100644 --- a/Cabal/src/Distribution/PackageDescription/Check.hs +++ b/Cabal/src/Distribution/PackageDescription/Check.hs @@ -577,11 +577,11 @@ checkSetupBuildInfo (Just (SetupBuildInfo ds _)) = do gtlck = PackageDistSuspiciousWarn . GTLowerBounds CETSetup - checkPVP withoutUpperBound ick is - checkPVPs withoutUpperBound rck rs - checkPVPs leqUpperBound lequck ds - checkPVPs trailingZeroUpperBound tzuck ds - checkPVPs gtLowerBound gtlck ds + checkPVP (checkDependencyVersionRange $ not . hasUpperBound) ick is + checkPVPs (checkDependencyVersionRange $ not . hasUpperBound) rck rs + checkPVPs (checkDependencyVersionRange hasLEQUpperBound) lequck ds + checkPVPs (checkDependencyVersionRange hasTrailingZeroUpperBound) tzuck ds + checkPVPs (checkDependencyVersionRange hasGTLowerBound) gtlck ds checkPackageId :: Monad m => PackageIdentifier -> CheckM m () checkPackageId (PackageIdentifier pkgName_ _pkgVersion_) = do diff --git a/Cabal/src/Distribution/PackageDescription/Check/Common.hs b/Cabal/src/Distribution/PackageDescription/Check/Common.hs index 9b222990560..81069ef0bbb 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Common.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Common.hs @@ -19,10 +19,7 @@ module Distribution.PackageDescription.Check.Common , partitionDeps , checkPVP , checkPVPs - , withoutUpperBound - , leqUpperBound - , trailingZeroUpperBound - , gtLowerBound + , checkDependencyVersionRange ) where import Distribution.Compat.Prelude @@ -150,55 +147,5 @@ checkPVPs p cf ds ods = filter p ds ns = map (unPackageName . depPkgName) ods --- | 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 _) = hasLEQUpperBound ver - --- | Does the upper bound version range have a trailing zero? -trailingZeroUpperBound :: Dependency -> Bool -trailingZeroUpperBound (Dependency _ ver _) = hasTrailingZeroUpperBound ver - --- | Is the lower bound version range GT (greater than, >)? -gtLowerBound :: Dependency -> Bool -gtLowerBound (Dependency _ ver _) = hasGTLowerBound ver - -pattern HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound :: VersionRangeF a -pattern HasLEQUpperBound <- OrEarlierVersionF _ -pattern HasGTLowerBound <- LaterVersionF _ -pattern HasTrailingZeroUpperBound <- (upperTrailingZero -> True) - -upperTrailingZero :: VersionRangeF a -> Bool -upperTrailingZero (OrEarlierVersionF x) = trailingZero x -upperTrailingZero (EarlierVersionF x) = trailingZero x -upperTrailingZero _ = False - -trailingZero :: Version -> Bool -trailingZero (versionNumbers -> vs) - | [0] <- vs = False - | 0 : _ <- reverse vs = True - | otherwise = False - -hasLEQUpperBound :: VersionRange -> Bool -hasLEQUpperBound (projectVersionRange -> v) - | HasLEQUpperBound <- v = True - | IntersectVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y - | UnionVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y - | otherwise = False - -hasGTLowerBound :: VersionRange -> Bool -hasGTLowerBound (projectVersionRange -> v) - | HasGTLowerBound <- v = True - | IntersectVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y - | UnionVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y - | otherwise = False - -hasTrailingZeroUpperBound :: VersionRange -> Bool -hasTrailingZeroUpperBound (projectVersionRange -> v) - | HasTrailingZeroUpperBound <- v = True - | IntersectVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y - | UnionVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y - | otherwise = False +checkDependencyVersionRange :: (VersionRange -> Bool) -> Dependency -> Bool +checkDependencyVersionRange p (Dependency _ ver _) = p ver diff --git a/Cabal/src/Distribution/PackageDescription/Check/Target.hs b/Cabal/src/Distribution/PackageDescription/Check/Target.hs index 4451a94b73c..dd692efbfe9 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Target.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Target.hs @@ -342,19 +342,19 @@ checkBuildInfo cet ams ads bi = do lequck = PackageDistSuspiciousWarn . LEQUpperBounds cet tzuck = PackageDistSuspiciousWarn . TrailingZeroUpperBounds cet gtlck = PackageDistSuspiciousWarn . GTLowerBounds cet - checkPVP withoutUpperBound ick ids + checkPVP (checkDependencyVersionRange $ not . hasUpperBound) ick ids unless (isInternalTarget cet) - (checkPVPs withoutUpperBound rck rds) + (checkPVPs (checkDependencyVersionRange $ not . hasUpperBound) rck rds) unless (isInternalTarget cet) - (checkPVPs leqUpperBound lequck ds) + (checkPVPs (checkDependencyVersionRange hasLEQUpperBound) lequck ds) unless (isInternalTarget cet) - (checkPVPs trailingZeroUpperBound tzuck ds) + (checkPVPs (checkDependencyVersionRange hasTrailingZeroUpperBound) tzuck ds) unless (isInternalTarget cet) - (checkPVPs gtLowerBound gtlck ds) + (checkPVPs (checkDependencyVersionRange hasGTLowerBound) gtlck ds) -- Custom fields well-formedness (ASCII). mapM_ checkCustomField (customFieldsBI bi) From 612660b237616b11663f4576c1d5bf2406ba6a60 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Thu, 21 Nov 2024 09:42:48 -0500 Subject: [PATCH 08/24] Add changelog --- changelog.d/pr-10554 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 changelog.d/pr-10554 diff --git a/changelog.d/pr-10554 b/changelog.d/pr-10554 new file mode 100644 index 00000000000..e55de4d38d7 --- /dev/null +++ b/changelog.d/pr-10554 @@ -0,0 +1,12 @@ +--- +synopsis: Adds more version range checks to `cabal check`. +packages: [Cabal-syntax, Cabal] +prs: 10554 +issues: 9806 +--- + +For dependencies, warns about and checks that version range bounds for: + +- lower bounds are inclusive, don't use (>) +- upper bounds are exclusive, don't use (<=) +- upper bounds don't have trailing zeros, don't end with (*.0) From 80ba4efc74864176c2f5a68b35fdf61110e65b11 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Thu, 21 Nov 2024 09:57:57 -0500 Subject: [PATCH 09/24] Remove unit-test guards that aren't needed --- .../Distribution/Solver/Modular/DSL.hs | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs index bb62f56968e..d1d70f59348 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL.hs @@ -492,15 +492,7 @@ 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 (isgtLowerBound x) - && not (isLeqUpperBound x) - && not (isTrailingZeroUpperBound x) - && not (isMissingUpperBound x) - && not (isUnknownLangExt x) - ) - checks + in filter (\x -> not (isMissingUpperBound x) && not (isUnknownLangExt x)) checks in if null pkgCheckErrors then package else @@ -723,18 +715,6 @@ 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 - isgtLowerBound pc = case C.explanation pc of - C.GTLowerBounds{} -> True - _ -> False mkSimpleVersion :: ExamplePkgVersion -> C.Version mkSimpleVersion n = C.mkVersion [n, 0, 0] From 043b111def890f988d21b78da2533fbb2b88e1ec Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 10:03:04 -0500 Subject: [PATCH 10/24] Shorten check IDs --- .../UnitTests/Distribution/PackageDescription/Check.hs | 6 +----- Cabal/src/Distribution/PackageDescription/Check/Warning.hs | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs b/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs index e167e4de07d..662a0684cda 100644 --- a/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs +++ b/Cabal-tests/tests/UnitTests/Distribution/PackageDescription/Check.hs @@ -18,11 +18,7 @@ import Test.QuickCheck.Instances.Cabal () tests :: [TestTree] tests = [ testCase "Unique ignore strings" (uniqueNames @?= True) - , testCase "Short ignore identifiers" (longerThan @?= - [ "less.than.equals(<=)-upper-bounds" - , "trailing.zero(*.0)-upper-bounds" - , "greater.than(>)-lower-bounds" - ]) + , testCase "Short ignore identifiers" (longerThan @?= []) , testCase "Parsimonious '-' use" (usingTooManyDashes @?= []) ] where diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index 79b13f2f3bf..8beeb43767d 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -719,9 +719,9 @@ ppCheckExplanationId CIMissingUpperBounds = "missing-upper-bounds" -- NOTE: Satisfy the Parsimonious test, a test that checks that these messages -- don't have too many dashes: -- $ cabal run Cabal-tests:unit-tests -- --pattern=Parsimonious -ppCheckExplanationId CILEQUpperBounds = "less.than.equals(<=)-upper-bounds" -ppCheckExplanationId CITrailingZeroUpperBounds = "trailing.zero(*.0)-upper-bounds" -ppCheckExplanationId CIGTLowerBounds = "greater.than(>)-lower-bounds" +ppCheckExplanationId CILEQUpperBounds = "lte-upper-bounds" +ppCheckExplanationId CITrailingZeroUpperBounds = "tz-upper-bounds" +ppCheckExplanationId CIGTLowerBounds = "gt-lower-bounds" ppCheckExplanationId CISuspiciousFlagName = "suspicious-flag" ppCheckExplanationId CIDeclaredUsedFlags = "unused-flag" ppCheckExplanationId CINonASCIICustomField = "non-ascii" From 548028a0a853344240d30c4b6f2142d878baf9d0 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 10:22:44 -0500 Subject: [PATCH 11/24] Add warnings to cabal check section of user guide --- doc/cabal-commands.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index ed088d14b8d..455d4953269 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -1390,7 +1390,10 @@ A list of all warnings with their constructor: - ``unknown-arch``: unknown architecture in condition. - ``unknown-compiler``: unknown compiler in condition. - ``missing-bounds-important``: missing upper bounds for important dependencies (``base``, and for ``custom-setup`` ``Cabal`` too). -- ``missing-upper-bounds``: missing upper bound in dependency (excluding test-suites and benchmarks). +- ``missing-upper-bounds``: missing upper bound in dependency [#dep-excl]_. +- ``lte-upper-bounds``: less than or equals (<=) constraint on upper bound in dependency [#dep-excl]_. +- ``tz-upper-bounds``: trailing zero (\*.0) upper bound in dependency [#dep-excl]_. +- ``gt-lower-bounds``: greater than (>) constraint on lower bound in dependency [#dep-excl]_. - ``suspicious-flag``: troublesome flag name (e.g. starting with a dash). - ``unused-flag``: unused user flags. - ``non-ascii``: non-ASCII characters in custom field. @@ -1419,6 +1422,8 @@ A list of all warnings with their constructor: file is not present in the :pkg-field:`extra-doc-files` field, warns about it. - ``doc-place``: documentation files listed in ``extra-source-files`` instead of ``extra-doc-files``. +.. [#dep-excl] In dependencies excluding test-suites and benchmarks. + .. _cabal-sdist: cabal sdist From 176560a05ac834e1b59061c06f922848119dc9b8 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 10:35:18 -0500 Subject: [PATCH 12/24] Terminate bulleted list with full stop --- changelog.d/pr-10554 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/pr-10554 b/changelog.d/pr-10554 index e55de4d38d7..569bba5e0d8 100644 --- a/changelog.d/pr-10554 +++ b/changelog.d/pr-10554 @@ -9,4 +9,4 @@ For dependencies, warns about and checks that version range bounds for: - lower bounds are inclusive, don't use (>) - upper bounds are exclusive, don't use (<=) -- upper bounds don't have trailing zeros, don't end with (*.0) +- upper bounds don't have trailing zeros, don't end with (*.0). From 8356af50afa52ee2adf8d1aaa2b3df9bfc6d0bf9 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 10:38:44 -0500 Subject: [PATCH 13/24] Remove links to pvp.haskell.org --- Cabal/src/Distribution/PackageDescription/Check/Warning.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index 8beeb43767d..b782babe9b6 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -1333,7 +1333,7 @@ ppExplanation (LEQUpperBounds ct names) = ++ separator ++ List.intercalate separator names ++ "\n" - ++ "Please use less than (<) for upper bounds. There is more information at https://pvp.haskell.org/" + ++ "Please use less than (<) for upper bounds." ppExplanation (TrailingZeroUpperBounds ct names) = let separator = "\n - " in "On " @@ -1343,7 +1343,7 @@ ppExplanation (TrailingZeroUpperBounds ct names) = ++ separator ++ List.intercalate separator names ++ "\n" - ++ "Please avoid trailing zeros for upper bounds. There is more information at https://pvp.haskell.org/" + ++ "Please avoid trailing zeros for upper bounds." ppExplanation (GTLowerBounds ct names) = let separator = "\n - " in "On " @@ -1353,7 +1353,7 @@ ppExplanation (GTLowerBounds ct names) = ++ separator ++ List.intercalate separator names ++ "\n" - ++ "Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/" + ++ "Please use greater than or equals (>=) for lower bounds." ppExplanation (SuspiciousFlagName invalidFlagNames) = "Suspicious flag names: " ++ unwords invalidFlagNames From 2ee428d096a93908937d3b1bf0a177a8cc4368cc Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 11:15:03 -0500 Subject: [PATCH 14/24] Note version constraint guidelines and mistakes --- doc/cabal-commands.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index 455d4953269..46bed47ee91 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -1424,6 +1424,34 @@ A list of all warnings with their constructor: .. [#dep-excl] In dependencies excluding test-suites and benchmarks. +.. note:: + + ``cabal check`` warns on subexpressions (individual version constraints) of + a version range that are of the form, ``> version``, ``<= version``, ``<= + version.0[...0]``. These are considered suspicious because they are likely + to be mistakes. Guidelines for individual version constraints within + version ranges and examples of mistakes when not following these are: + + "A lower bound should be inclusive." + + Asking for ``base > 4.11`` when you actually want ``base >= 4.12`` is an + example of making this mistake. Versions make a dense space, so there + are infinitely many versions that are ``> 4.11`` and ``< 4.12``. + + "An upper bound should be exclusive." + + Asking for ``base <= 4.19.1.0`` when the last published version is + ``base-4.19.1.0`` is an example of making this mistake. This blocks + patch releases that should always be fine according to the PVP. The + correct minor bound is ``base < 4.19.2``. + + "An upper bound should not have trailing zeros." + + Asking for ``base < 4.20.0.0`` when you meant allow any ``base-4.19.*`` + version is an example of making this mistake. In fact, ``base-4.20`` and + ``base-4.20.0`` are not excluded by the bound. The correct bound is ``< + 4.20``. + .. _cabal-sdist: cabal sdist From 0d8c95ea19128477535633118816c41aea4c07e7 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 11:25:21 -0500 Subject: [PATCH 15/24] Add listSep --- .../PackageDescription/Check/Warning.hs | 65 +++++++++---------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index b782babe9b6..df32e7c527b 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -1315,45 +1315,33 @@ ppExplanation BaseNoUpperBounds = ++ "version. For example if you have tested your package with 'base' " ++ "version 4.5 and 4.6 then use 'build-depends: base >= 4.5 && < 4.7'." ppExplanation (MissingUpperBounds ct names) = - let separator = "\n - " - in "On " - ++ ppCET ct - ++ ", " - ++ "these packages miss upper bounds:" - ++ separator - ++ List.intercalate separator names - ++ "\n" - ++ "Please add them. There is more information at https://pvp.haskell.org/" + "On " + ++ ppCET ct + ++ ", " + ++ "these packages miss upper bounds:" + ++ listSep names + ++ "Please add them. There is more information at https://pvp.haskell.org/" ppExplanation (LEQUpperBounds ct names) = - let separator = "\n - " - in "On " - ++ ppCET ct - ++ ", " - ++ "these packages have less than or equals (<=) upper bounds:" - ++ separator - ++ List.intercalate separator names - ++ "\n" - ++ "Please use less than (<) for upper bounds." + "On " + ++ ppCET ct + ++ ", " + ++ "these packages have less than or equals (<=) upper bounds:" + ++ listSep names + ++ "Please use less than (<) for upper bounds." ppExplanation (TrailingZeroUpperBounds ct names) = - let separator = "\n - " - in "On " - ++ ppCET ct - ++ ", " - ++ "these packages have upper bounds with trailing zeros:" - ++ separator - ++ List.intercalate separator names - ++ "\n" - ++ "Please avoid trailing zeros for upper bounds." + "On " + ++ ppCET ct + ++ ", " + ++ "these packages have upper bounds with trailing zeros:" + ++ listSep names + ++ "Please avoid trailing zeros for upper bounds." ppExplanation (GTLowerBounds ct names) = - let separator = "\n - " - in "On " - ++ ppCET ct - ++ ", " - ++ "these packages have greater than (>) lower bounds:" - ++ separator - ++ List.intercalate separator names - ++ "\n" - ++ "Please use greater than or equals (>=) for lower bounds." + "On " + ++ ppCET ct + ++ ", " + ++ "these packages have greater than (>) lower bounds:" + ++ listSep names + ++ "Please use greater than or equals (>=) for lower bounds." ppExplanation (SuspiciousFlagName invalidFlagNames) = "Suspicious flag names: " ++ unwords invalidFlagNames @@ -1515,6 +1503,11 @@ ppExplanation (WrongFieldForExpectedDocFiles extraDocFileSupport field paths) = -- * Formatting utilities +listSep :: [String] -> String +listSep names = + let separator = "\n - " + in separator ++ List.intercalate separator names ++ "\n" + commaSep :: [String] -> String commaSep = List.intercalate ", " From 590b3987904852dc6b3c13dbe7de58951df1d3b3 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Sat, 23 Nov 2024 10:03:24 -0500 Subject: [PATCH 16/24] Reuse queryVersionRange --- .../src/Distribution/Types/VersionRange.hs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange.hs b/Cabal-syntax/src/Distribution/Types/VersionRange.hs index 2f72f084bdc..bd507085d33 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} @@ -222,24 +223,19 @@ trailingZero (versionNumbers -> vs) -- | Is the upper bound version range LEQ (less or equal, <=)? hasLEQUpperBound :: VersionRange -> Bool -hasLEQUpperBound (projectVersionRange -> v) - | HasLEQUpperBound <- v = True - | IntersectVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y - | UnionVersionRangesF x y <- v = hasLEQUpperBound x || hasLEQUpperBound y - | otherwise = False +hasLEQUpperBound = queryVersionRange (\case HasLEQUpperBound -> True; _ -> False) hasLEQUpperBound -- | Is the lower bound version range GT (greater than, >)? hasGTLowerBound :: VersionRange -> Bool -hasGTLowerBound (projectVersionRange -> v) - | HasGTLowerBound <- v = True - | IntersectVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y - | UnionVersionRangesF x y <- v = hasGTLowerBound x || hasGTLowerBound y - | otherwise = False +hasGTLowerBound = queryVersionRange (\case HasGTLowerBound -> True; _ -> False) hasGTLowerBound -- | Does the upper bound version range have a trailing zero? hasTrailingZeroUpperBound :: VersionRange -> Bool -hasTrailingZeroUpperBound (projectVersionRange -> v) - | HasTrailingZeroUpperBound <- v = True - | IntersectVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y - | UnionVersionRangesF x y <- v = hasTrailingZeroUpperBound x || hasTrailingZeroUpperBound y - | otherwise = False +hasTrailingZeroUpperBound = queryVersionRange (\case HasTrailingZeroUpperBound -> True; _ -> False) hasTrailingZeroUpperBound + +queryVersionRange :: (VersionRangeF VersionRange -> Bool) -> (VersionRange -> Bool) -> VersionRange -> Bool +queryVersionRange pf p (projectVersionRange -> v) = let f = queryVersionRange pf p in + pf v || case v of + IntersectVersionRangesF x y -> f x || f y + UnionVersionRangesF x y -> f x || f y + _ -> False From 91c94432bb773e43e9f53f9795e205425ede4f20 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Sat, 23 Nov 2024 11:14:02 -0500 Subject: [PATCH 17/24] Bundle pattern synonyms with VersionRangeF --- .../src/Distribution/Types/VersionRange.hs | 16 --------------- .../Types/VersionRange/Internal.hs | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange.hs b/Cabal-syntax/src/Distribution/Types/VersionRange.hs index bd507085d33..043bc6c0d2c 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange.hs @@ -205,22 +205,6 @@ hasLowerBound = (&&) (||) -pattern HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound :: VersionRangeF a -pattern HasLEQUpperBound <- OrEarlierVersionF _ -pattern HasGTLowerBound <- LaterVersionF _ -pattern HasTrailingZeroUpperBound <- (upperTrailingZero -> True) - -upperTrailingZero :: VersionRangeF a -> Bool -upperTrailingZero (OrEarlierVersionF x) = trailingZero x -upperTrailingZero (EarlierVersionF x) = trailingZero x -upperTrailingZero _ = False - -trailingZero :: Version -> Bool -trailingZero (versionNumbers -> vs) - | [0] <- vs = False - | 0 : _ <- reverse vs = True - | otherwise = False - -- | Is the upper bound version range LEQ (less or equal, <=)? hasLEQUpperBound :: VersionRange -> Bool hasLEQUpperBound = queryVersionRange (\case HasLEQUpperBound -> True; _ -> False) hasLEQUpperBound diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs b/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs index ef82ae86045..17c74958229 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs @@ -3,7 +3,9 @@ {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE ViewPatterns #-} -- | The only purpose of this module is to prevent the export of -- 'VersionRange' constructors from @@ -23,7 +25,7 @@ module Distribution.Types.VersionRange.Internal , intersectVersionRanges , withinVersion , majorBoundVersion - , VersionRangeF (..) + , VersionRangeF (.., HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound) , projectVersionRange , embedVersionRange , cataVersionRange @@ -185,6 +187,22 @@ data VersionRangeF a , Traversable ) +pattern HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound :: VersionRangeF a +pattern HasLEQUpperBound <- OrEarlierVersionF _ +pattern HasGTLowerBound <- LaterVersionF _ +pattern HasTrailingZeroUpperBound <- (upperTrailingZero -> True) + +upperTrailingZero :: VersionRangeF a -> Bool +upperTrailingZero (OrEarlierVersionF x) = trailingZero x +upperTrailingZero (EarlierVersionF x) = trailingZero x +upperTrailingZero _ = False + +trailingZero :: Version -> Bool +trailingZero (versionNumbers -> vs) + | [0] <- vs = False + | 0 : _ <- reverse vs = True + | otherwise = False + -- | Generic destructor for 'VersionRange'. -- -- @since 2.2 From 77e3bc77b6119465a86b543eb59f3fddd03953cc Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Sat, 23 Nov 2024 16:25:43 -0500 Subject: [PATCH 18/24] Add doctest docs for version range predicates - Used named chunk for predicate examples - Add predicate subsections for types of bounds --- .../src/Distribution/Types/VersionRange.hs | 78 ++++++++++++++----- 1 file changed, 60 insertions(+), 18 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange.hs b/Cabal-syntax/src/Distribution/Types/VersionRange.hs index 043bc6c0d2c..043d8b9a61f 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange.hs @@ -3,9 +3,23 @@ {-# LANGUAGE ViewPatterns #-} module Distribution.Types.VersionRange - ( -- * Version ranges + ( -- * Version Range VersionRange + -- ** Predicates + -- $predicate-examples + + -- *** Lower Bound + , hasLowerBound + , hasGTLowerBound + -- *** Upper Bound + , hasUpperBound + , hasLEQUpperBound + , hasTrailingZeroUpperBound + -- *** Any Version + , isAnyVersion + , isAnyVersionLight + -- ** Constructing , anyVersion , noVersion @@ -20,35 +34,30 @@ module Distribution.Types.VersionRange , withinVersion , majorBoundVersion - -- ** Inspection + -- ** Modification + , normaliseVersionRange + , stripParensVersionRange - -- - -- See "Distribution.Version" for more utilities. + -- ** Inspection , withinRange , foldVersionRange - , normaliseVersionRange - , stripParensVersionRange - , hasUpperBound - , hasLowerBound - , hasLEQUpperBound - , hasTrailingZeroUpperBound - , hasGTLowerBound - -- ** Cata & ana + -- ** Parser + , versionRangeParser + + -- * Version F-Algebra , VersionRangeF (..) + , projectVersionRange + , embedVersionRange , cataVersionRange , anaVersionRange , hyloVersionRange - , projectVersionRange - , embedVersionRange - -- ** Utilities - , isAnyVersion - , isAnyVersionLight + -- * Version Utilities + -- See "Distribution.Version" for more utilities. , wildcardUpperBound , majorUpperBound , isWildcardRange - , versionRangeParser ) where import Distribution.Compat.Prelude @@ -179,6 +188,9 @@ isWildcardRange ver1 ver2 = check (versionNumbers ver1) (versionNumbers ver2) -- | Does the version range have an upper bound? -- -- @since 1.24.0.0 +-- +-- >>> forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "^>= 4.20.0.0"] (fmap hasUpperBound . simpleParsec) +-- Just [True,True,False,True] hasUpperBound :: VersionRange -> Bool hasUpperBound = foldVersionRange @@ -195,6 +207,9 @@ hasUpperBound = -- the implicit >=0 lower bound. -- -- @since 1.24.0.0 +-- +-- >>> forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "^>= 4.20.0.0"] (fmap hasLowerBound . simpleParsec) +-- Just [False,True,False,True] hasLowerBound :: VersionRange -> Bool hasLowerBound = foldVersionRange @@ -206,14 +221,23 @@ hasLowerBound = (||) -- | Is the upper bound version range LEQ (less or equal, <=)? +-- +-- >>> forM ["< 1", "<= 1", ">= 0 && < 1", ">= 0 || < 1", ">= 0 && <= 1", ">= 0 || <= 1", "^>= 4.20.0.0"] (fmap hasLEQUpperBound . simpleParsec) +-- Just [False,True,False,False,True,True,False] hasLEQUpperBound :: VersionRange -> Bool hasLEQUpperBound = queryVersionRange (\case HasLEQUpperBound -> True; _ -> False) hasLEQUpperBound -- | Is the lower bound version range GT (greater than, >)? +-- +-- >>> forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "> 0 && < 1", "> 0 || < 1", "^>= 4.20.0.0"] (fmap hasGTLowerBound . simpleParsec) +-- Just [False,False,False,True,True,False] hasGTLowerBound :: VersionRange -> Bool hasGTLowerBound = queryVersionRange (\case HasGTLowerBound -> True; _ -> False) hasGTLowerBound -- | Does the upper bound version range have a trailing zero? +-- +-- >>> forM ["< 1", "< 1.1", "< 1.0", "< 1.1.0", "^>= 4.20.0.0"] (fmap hasTrailingZeroUpperBound . simpleParsec) +-- Just [False,False,True,True,False] hasTrailingZeroUpperBound :: VersionRange -> Bool hasTrailingZeroUpperBound = queryVersionRange (\case HasTrailingZeroUpperBound -> True; _ -> False) hasTrailingZeroUpperBound @@ -223,3 +247,21 @@ queryVersionRange pf p (projectVersionRange -> v) = let f = queryVersionRange pf IntersectVersionRangesF x y -> f x || f y UnionVersionRangesF x y -> f x || f y _ -> False + +-- $setup +-- >>> import Distribution.Parsec +-- >>> import Data.Traversable + +-- $predicate-examples +-- +-- The parsed 'VersionRange' of each version constraint used in the examples for +-- 'hasUpperBound' and 'hasLowerBound' are: +-- +-- >>> simpleParsec "< 1" :: Maybe VersionRange +-- Just (EarlierVersion (mkVersion [1])) +-- >>> simpleParsec ">= 0 && < 1" :: Maybe VersionRange +-- Just (IntersectVersionRanges (OrLaterVersion (mkVersion [0])) (EarlierVersion (mkVersion [1]))) +-- >>> simpleParsec ">= 0 || < 1" :: Maybe VersionRange +-- Just (UnionVersionRanges (OrLaterVersion (mkVersion [0])) (EarlierVersion (mkVersion [1]))) +-- >>> simpleParsec "^>= 4.20.0.0" :: Maybe VersionRange +-- Just (MajorBoundVersion (mkVersion [4,20,0,0])) From e046244bfa7208d08effc610a5d641a75041ec92 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 11:59:43 -0500 Subject: [PATCH 19/24] Change lte- to le- prefix --- Cabal/src/Distribution/PackageDescription/Check/Warning.hs | 2 +- doc/cabal-commands.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index df32e7c527b..b775df15b95 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -719,7 +719,7 @@ ppCheckExplanationId CIMissingUpperBounds = "missing-upper-bounds" -- NOTE: Satisfy the Parsimonious test, a test that checks that these messages -- don't have too many dashes: -- $ cabal run Cabal-tests:unit-tests -- --pattern=Parsimonious -ppCheckExplanationId CILEQUpperBounds = "lte-upper-bounds" +ppCheckExplanationId CILEQUpperBounds = "le-upper-bounds" ppCheckExplanationId CITrailingZeroUpperBounds = "tz-upper-bounds" ppCheckExplanationId CIGTLowerBounds = "gt-lower-bounds" ppCheckExplanationId CISuspiciousFlagName = "suspicious-flag" diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index 46bed47ee91..7fde877ce5c 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -1391,7 +1391,7 @@ A list of all warnings with their constructor: - ``unknown-compiler``: unknown compiler in condition. - ``missing-bounds-important``: missing upper bounds for important dependencies (``base``, and for ``custom-setup`` ``Cabal`` too). - ``missing-upper-bounds``: missing upper bound in dependency [#dep-excl]_. -- ``lte-upper-bounds``: less than or equals (<=) constraint on upper bound in dependency [#dep-excl]_. +- ``le-upper-bounds``: less than or equals (<=) constraint on upper bound in dependency [#dep-excl]_. - ``tz-upper-bounds``: trailing zero (\*.0) upper bound in dependency [#dep-excl]_. - ``gt-lower-bounds``: greater than (>) constraint on lower bound in dependency [#dep-excl]_. - ``suspicious-flag``: troublesome flag name (e.g. starting with a dash). From fe7ed3b3692ea2dc2868764db8ff4f37e1299b11 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 12:13:44 -0500 Subject: [PATCH 20/24] Satisfy fourmolu --- .../src/Distribution/Types/VersionRange.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange.hs b/Cabal-syntax/src/Distribution/Types/VersionRange.hs index 043d8b9a61f..e2a5c12bf59 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange.hs @@ -12,10 +12,12 @@ module Distribution.Types.VersionRange -- *** Lower Bound , hasLowerBound , hasGTLowerBound + -- *** Upper Bound , hasUpperBound , hasLEQUpperBound , hasTrailingZeroUpperBound + -- *** Any Version , isAnyVersion , isAnyVersionLight @@ -54,7 +56,8 @@ module Distribution.Types.VersionRange , hyloVersionRange -- * Version Utilities - -- See "Distribution.Version" for more utilities. + + -- See "Distribution.Version" for more utilities. , wildcardUpperBound , majorUpperBound , isWildcardRange @@ -242,11 +245,12 @@ hasTrailingZeroUpperBound :: VersionRange -> Bool hasTrailingZeroUpperBound = queryVersionRange (\case HasTrailingZeroUpperBound -> True; _ -> False) hasTrailingZeroUpperBound queryVersionRange :: (VersionRangeF VersionRange -> Bool) -> (VersionRange -> Bool) -> VersionRange -> Bool -queryVersionRange pf p (projectVersionRange -> v) = let f = queryVersionRange pf p in - pf v || case v of - IntersectVersionRangesF x y -> f x || f y - UnionVersionRangesF x y -> f x || f y - _ -> False +queryVersionRange pf p (projectVersionRange -> v) = + let f = queryVersionRange pf p + in pf v || case v of + IntersectVersionRangesF x y -> f x || f y + UnionVersionRangesF x y -> f x || f y + _ -> False -- $setup -- >>> import Distribution.Parsec From 7c3346356eda82361b97bd1810b18efc6605243a Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 12:16:14 -0500 Subject: [PATCH 21/24] Flip sense of LE and GT haddocks --- Cabal-syntax/src/Distribution/Types/VersionRange.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange.hs b/Cabal-syntax/src/Distribution/Types/VersionRange.hs index e2a5c12bf59..c3cfe770658 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange.hs @@ -223,14 +223,14 @@ hasLowerBound = (&&) (||) --- | Is the upper bound version range LEQ (less or equal, <=)? +-- | Is the upper bound version range (less than or equal (LE, <=)? -- -- >>> forM ["< 1", "<= 1", ">= 0 && < 1", ">= 0 || < 1", ">= 0 && <= 1", ">= 0 || <= 1", "^>= 4.20.0.0"] (fmap hasLEQUpperBound . simpleParsec) -- Just [False,True,False,False,True,True,False] hasLEQUpperBound :: VersionRange -> Bool hasLEQUpperBound = queryVersionRange (\case HasLEQUpperBound -> True; _ -> False) hasLEQUpperBound --- | Is the lower bound version range GT (greater than, >)? +-- | Is the lower bound version range greater than (GT, >)? -- -- >>> forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "> 0 && < 1", "> 0 || < 1", "^>= 4.20.0.0"] (fmap hasGTLowerBound . simpleParsec) -- Just [False,False,False,True,True,False] From 5b15a257b33d897f85273552b8a3fdb5e7889fe7 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 12:29:41 -0500 Subject: [PATCH 22/24] Drop Has prefix on patterns, use LE not LEQ - avoid name clash with has*Bound (VersionRange -> Bool) predicates - use TZ not TrailingZero, a two-letter prefix like the other two --- Cabal-syntax/src/Distribution/Types/VersionRange.hs | 12 ++++++------ .../src/Distribution/Types/VersionRange/Internal.hs | 10 +++++----- Cabal-syntax/src/Distribution/Version.hs | 2 +- Cabal/src/Distribution/PackageDescription/Check.hs | 6 +++--- .../Distribution/PackageDescription/Check/Target.hs | 4 ++-- .../Distribution/PackageDescription/Check/Warning.hs | 10 +++++----- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange.hs b/Cabal-syntax/src/Distribution/Types/VersionRange.hs index c3cfe770658..80b0373df9c 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange.hs @@ -15,7 +15,7 @@ module Distribution.Types.VersionRange -- *** Upper Bound , hasUpperBound - , hasLEQUpperBound + , hasLEUpperBound , hasTrailingZeroUpperBound -- *** Any Version @@ -225,24 +225,24 @@ hasLowerBound = -- | Is the upper bound version range (less than or equal (LE, <=)? -- --- >>> forM ["< 1", "<= 1", ">= 0 && < 1", ">= 0 || < 1", ">= 0 && <= 1", ">= 0 || <= 1", "^>= 4.20.0.0"] (fmap hasLEQUpperBound . simpleParsec) +-- >>> forM ["< 1", "<= 1", ">= 0 && < 1", ">= 0 || < 1", ">= 0 && <= 1", ">= 0 || <= 1", "^>= 4.20.0.0"] (fmap hasLEUpperBound . simpleParsec) -- Just [False,True,False,False,True,True,False] -hasLEQUpperBound :: VersionRange -> Bool -hasLEQUpperBound = queryVersionRange (\case HasLEQUpperBound -> True; _ -> False) hasLEQUpperBound +hasLEUpperBound :: VersionRange -> Bool +hasLEUpperBound = queryVersionRange (\case LEUpperBound -> True; _ -> False) hasLEUpperBound -- | Is the lower bound version range greater than (GT, >)? -- -- >>> forM ["< 1", ">= 0 && < 1", ">= 0 || < 1", "> 0 && < 1", "> 0 || < 1", "^>= 4.20.0.0"] (fmap hasGTLowerBound . simpleParsec) -- Just [False,False,False,True,True,False] hasGTLowerBound :: VersionRange -> Bool -hasGTLowerBound = queryVersionRange (\case HasGTLowerBound -> True; _ -> False) hasGTLowerBound +hasGTLowerBound = queryVersionRange (\case GTLowerBound -> True; _ -> False) hasGTLowerBound -- | Does the upper bound version range have a trailing zero? -- -- >>> forM ["< 1", "< 1.1", "< 1.0", "< 1.1.0", "^>= 4.20.0.0"] (fmap hasTrailingZeroUpperBound . simpleParsec) -- Just [False,False,True,True,False] hasTrailingZeroUpperBound :: VersionRange -> Bool -hasTrailingZeroUpperBound = queryVersionRange (\case HasTrailingZeroUpperBound -> True; _ -> False) hasTrailingZeroUpperBound +hasTrailingZeroUpperBound = queryVersionRange (\case TZUpperBound -> True; _ -> False) hasTrailingZeroUpperBound queryVersionRange :: (VersionRangeF VersionRange -> Bool) -> (VersionRange -> Bool) -> VersionRange -> Bool queryVersionRange pf p (projectVersionRange -> v) = diff --git a/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs b/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs index 17c74958229..8669bf8f072 100644 --- a/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs +++ b/Cabal-syntax/src/Distribution/Types/VersionRange/Internal.hs @@ -25,7 +25,7 @@ module Distribution.Types.VersionRange.Internal , intersectVersionRanges , withinVersion , majorBoundVersion - , VersionRangeF (.., HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound) + , VersionRangeF (.., LEUpperBound, GTLowerBound, TZUpperBound) , projectVersionRange , embedVersionRange , cataVersionRange @@ -187,10 +187,10 @@ data VersionRangeF a , Traversable ) -pattern HasLEQUpperBound, HasGTLowerBound, HasTrailingZeroUpperBound :: VersionRangeF a -pattern HasLEQUpperBound <- OrEarlierVersionF _ -pattern HasGTLowerBound <- LaterVersionF _ -pattern HasTrailingZeroUpperBound <- (upperTrailingZero -> True) +pattern LEUpperBound, GTLowerBound, TZUpperBound :: VersionRangeF a +pattern LEUpperBound <- OrEarlierVersionF _ +pattern GTLowerBound <- LaterVersionF _ +pattern TZUpperBound <- (upperTrailingZero -> True) upperTrailingZero :: VersionRangeF a -> Bool upperTrailingZero (OrEarlierVersionF x) = trailingZero x diff --git a/Cabal-syntax/src/Distribution/Version.hs b/Cabal-syntax/src/Distribution/Version.hs index f460da2648b..76aed461228 100644 --- a/Cabal-syntax/src/Distribution/Version.hs +++ b/Cabal-syntax/src/Distribution/Version.hs @@ -50,7 +50,7 @@ module Distribution.Version , stripParensVersionRange , hasUpperBound , hasLowerBound - , hasLEQUpperBound + , hasLEUpperBound , hasTrailingZeroUpperBound , hasGTLowerBound diff --git a/Cabal/src/Distribution/PackageDescription/Check.hs b/Cabal/src/Distribution/PackageDescription/Check.hs index 3f9879b99f3..2d9750de77d 100644 --- a/Cabal/src/Distribution/PackageDescription/Check.hs +++ b/Cabal/src/Distribution/PackageDescription/Check.hs @@ -568,9 +568,9 @@ checkSetupBuildInfo (Just (SetupBuildInfo ds _)) = do rck = PackageDistSuspiciousWarn . MissingUpperBounds CETSetup - lequck = + leuck = PackageDistSuspiciousWarn - . LEQUpperBounds CETSetup + . LEUpperBounds CETSetup tzuck = PackageDistSuspiciousWarn . TrailingZeroUpperBounds CETSetup @@ -579,7 +579,7 @@ checkSetupBuildInfo (Just (SetupBuildInfo ds _)) = do . GTLowerBounds CETSetup checkPVP (checkDependencyVersionRange $ not . hasUpperBound) ick is checkPVPs (checkDependencyVersionRange $ not . hasUpperBound) rck rs - checkPVPs (checkDependencyVersionRange hasLEQUpperBound) lequck ds + checkPVPs (checkDependencyVersionRange hasLEUpperBound) leuck ds checkPVPs (checkDependencyVersionRange hasTrailingZeroUpperBound) tzuck ds checkPVPs (checkDependencyVersionRange hasGTLowerBound) gtlck ds diff --git a/Cabal/src/Distribution/PackageDescription/Check/Target.hs b/Cabal/src/Distribution/PackageDescription/Check/Target.hs index dd692efbfe9..0bf173cb980 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Target.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Target.hs @@ -339,7 +339,7 @@ checkBuildInfo cet ams ads bi = do ds let ick = const (PackageDistInexcusable BaseNoUpperBounds) rck = PackageDistSuspiciousWarn . MissingUpperBounds cet - lequck = PackageDistSuspiciousWarn . LEQUpperBounds cet + leuck = PackageDistSuspiciousWarn . LEUpperBounds cet tzuck = PackageDistSuspiciousWarn . TrailingZeroUpperBounds cet gtlck = PackageDistSuspiciousWarn . GTLowerBounds cet checkPVP (checkDependencyVersionRange $ not . hasUpperBound) ick ids @@ -348,7 +348,7 @@ checkBuildInfo cet ams ads bi = do (checkPVPs (checkDependencyVersionRange $ not . hasUpperBound) rck rds) unless (isInternalTarget cet) - (checkPVPs (checkDependencyVersionRange hasLEQUpperBound) lequck ds) + (checkPVPs (checkDependencyVersionRange hasLEUpperBound) leuck ds) unless (isInternalTarget cet) (checkPVPs (checkDependencyVersionRange hasTrailingZeroUpperBound) tzuck ds) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs index b775df15b95..54e0a2687ca 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Warning.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Warning.hs @@ -255,7 +255,7 @@ data CheckExplanation | UnknownCompiler [String] | BaseNoUpperBounds | MissingUpperBounds CEType [String] - | LEQUpperBounds CEType [String] + | LEUpperBounds CEType [String] | TrailingZeroUpperBounds CEType [String] | GTLowerBounds CEType [String] | SuspiciousFlagName [String] @@ -421,7 +421,7 @@ data CheckExplanationID | CIUnknownCompiler | CIBaseNoUpperBounds | CIMissingUpperBounds - | CILEQUpperBounds + | CILEUpperBounds | CITrailingZeroUpperBounds | CIGTLowerBounds | CISuspiciousFlagName @@ -566,7 +566,7 @@ checkExplanationId (UnknownArch{}) = CIUnknownArch checkExplanationId (UnknownCompiler{}) = CIUnknownCompiler checkExplanationId (BaseNoUpperBounds{}) = CIBaseNoUpperBounds checkExplanationId (MissingUpperBounds{}) = CIMissingUpperBounds -checkExplanationId (LEQUpperBounds{}) = CILEQUpperBounds +checkExplanationId (LEUpperBounds{}) = CILEUpperBounds checkExplanationId (TrailingZeroUpperBounds{}) = CITrailingZeroUpperBounds checkExplanationId (GTLowerBounds{}) = CIGTLowerBounds checkExplanationId (SuspiciousFlagName{}) = CISuspiciousFlagName @@ -719,7 +719,7 @@ ppCheckExplanationId CIMissingUpperBounds = "missing-upper-bounds" -- NOTE: Satisfy the Parsimonious test, a test that checks that these messages -- don't have too many dashes: -- $ cabal run Cabal-tests:unit-tests -- --pattern=Parsimonious -ppCheckExplanationId CILEQUpperBounds = "le-upper-bounds" +ppCheckExplanationId CILEUpperBounds = "le-upper-bounds" ppCheckExplanationId CITrailingZeroUpperBounds = "tz-upper-bounds" ppCheckExplanationId CIGTLowerBounds = "gt-lower-bounds" ppCheckExplanationId CISuspiciousFlagName = "suspicious-flag" @@ -1321,7 +1321,7 @@ ppExplanation (MissingUpperBounds ct names) = ++ "these packages miss upper bounds:" ++ listSep names ++ "Please add them. There is more information at https://pvp.haskell.org/" -ppExplanation (LEQUpperBounds ct names) = +ppExplanation (LEUpperBounds ct names) = "On " ++ ppCET ct ++ ", " From a0fe500916a1bae4e17a6d6d617c224f0aaf5c8d Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 25 Nov 2024 12:04:17 -0500 Subject: [PATCH 23/24] Test expectations with shorter check messages --- .../Fields/ImpossibleVersionRangeLib/cabal.out | 8 ++++---- .../Check/NonConfCheck/PackageVersionsInternal/cabal.out | 4 ++-- .../NonConfCheck/PackageVersionsInternalSimple/cabal.out | 4 ++-- .../Check/NonConfCheck/PackageVersionsLibInt/cabal.out | 8 ++++---- .../Check/NonConfCheck/PackageVersionsStraddle/cabal.out | 8 ++++---- .../PackageTests/Check/NonConfCheck/SetupBounds/cabal.out | 4 ++-- .../Check/PackageFiles/VersionBounds/cabal.out | 8 ++++---- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out index 59f7435722b..833cb9c0fe9 100644 --- a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Fields/ImpossibleVersionRangeLib/cabal.out @@ -2,10 +2,10 @@ The package will not build sanely due to these errors: Error: [impossible-dep] The package has an impossible version range for a dependency on an internal library: pkg:internal >1.0 && <2.0. This version range does not include the current package, and must be removed as the current package's library will always be used. These warnings may cause trouble when distributing the package: -Warning: [trailing.zero(*.0)-upper-bounds] On library, these packages have upper bounds with trailing zeros: +Warning: [tz-upper-bounds] On library, these packages have upper bounds with trailing zeros: - pkg -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: +Please avoid trailing zeros for upper bounds. +Warning: [gt-lower-bounds] On library, these packages have greater than (>) lower bounds: - pkg -Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ +Please use greater than or equals (>=) for lower bounds. Error: Hackage would reject this package. diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out index be4c499fac0..52680032f6d 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternal/cabal.out @@ -1,5 +1,5 @@ # 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: +Warning: [le-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/ +Please use less than (<) for upper bounds. diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out index baf3b85f40f..7ba9b6f27d4 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsInternalSimple/cabal.out @@ -3,6 +3,6 @@ These warnings may cause trouble when distributing the package: Warning: [missing-upper-bounds] On executable 'prova', these packages miss upper bounds: - acme-box Please add them. There is more information at https://pvp.haskell.org/ -Warning: [trailing.zero(*.0)-upper-bounds] On library, these packages have upper bounds with trailing zeros: +Warning: [tz-upper-bounds] On library, these packages have upper bounds with trailing zeros: - text -Please avoid trailing zeros for upper bounds. There is more information at https://pvp.haskell.org/ +Please avoid trailing zeros for upper bounds. diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out index 304dc862f76..603ff161043 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsLibInt/cabal.out @@ -3,9 +3,9 @@ These warnings may cause trouble when distributing the package: Warning: [missing-upper-bounds] On library 'int-lib', these packages miss upper bounds: - text Please add them. There is more information at https://pvp.haskell.org/ -Warning: [less.than.equals(<=)-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: +Warning: [le-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: [greater.than(>)-lower-bounds] On library 'int-lib', these packages have greater than (>) lower bounds: +Please use less than (<) for upper bounds. +Warning: [gt-lower-bounds] On library 'int-lib', these packages have greater than (>) lower bounds: - text -Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ +Please use greater than or equals (>=) for lower bounds. diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out index ff081197a29..a8e84640cdb 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PackageVersionsStraddle/cabal.out @@ -1,8 +1,8 @@ # 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: +Warning: [le-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: [greater.than(>)-lower-bounds] On library, these packages have greater than (>) lower bounds: +Please use less than (<) for upper bounds. +Warning: [gt-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/ +Please use greater than or equals (>=) for lower bounds. diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out index 1732b3fccd9..59e0cefd25c 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/SetupBounds/cabal.out @@ -1,8 +1,8 @@ # cabal check These warnings may cause trouble when distributing the package: -Warning: [greater.than(>)-lower-bounds] On custom-setup, these packages have greater than (>) lower bounds: +Warning: [gt-lower-bounds] On custom-setup, 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/ +Please use greater than or equals (>=) for lower bounds. The following errors will cause portability problems on other environments: Error: [missing-bounds-setup] The dependency 'setup-depends: 'base' does not specify an upper bound on the version number. Each major release of the 'base' package changes the API in various ways and most packages will need some changes to compile with it. If you are not sure what upper bound to use then use the next major version. Error: Hackage would reject this package. diff --git a/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out index 4352ab832e7..6368896bc4c 100644 --- a/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out +++ b/cabal-testsuite/PackageTests/Check/PackageFiles/VersionBounds/cabal.out @@ -6,13 +6,13 @@ Warning: [missing-upper-bounds] On library, these packages miss upper bounds: - or-exclusive-minimums-missing-upper - or-inclusive-maximums-missing-upper Please add them. There is more information at https://pvp.haskell.org/ -Warning: [less.than.equals(<=)-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: +Warning: [le-upper-bounds] On library, these packages have less than or equals (<=) upper bounds: - inclusive-maximums - and-inclusive-maximums - or-inclusive-maximums-missing-upper -Please use less than (<) 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: +Please use less than (<) for upper bounds. +Warning: [gt-lower-bounds] On library, these packages have greater than (>) lower bounds: - exclusive-minimums-missing-upper - and-exclusive-minimums - or-exclusive-minimums-missing-upper -Please use greater than or equals (>=) for lower bounds. There is more information at https://pvp.haskell.org/ +Please use greater than or equals (>=) for lower bounds. From 0d787e3512a2cbaee1a0096963ada7f760e2e5b0 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Thu, 12 Dec 2024 20:10:15 -0500 Subject: [PATCH 24/24] Remove unused LANGUAGE pragmas --- Cabal/src/Distribution/PackageDescription/Check/Common.hs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cabal/src/Distribution/PackageDescription/Check/Common.hs b/Cabal/src/Distribution/PackageDescription/Check/Common.hs index 81069ef0bbb..87ad55d7ade 100644 --- a/Cabal/src/Distribution/PackageDescription/Check/Common.hs +++ b/Cabal/src/Distribution/PackageDescription/Check/Common.hs @@ -1,6 +1,3 @@ -{-# LANGUAGE PatternSynonyms #-} -{-# LANGUAGE ViewPatterns #-} - -- | -- Module : Distribution.PackageDescription.Check.Common -- Copyright : Francesco Ariis 2022