Skip to content

Make check comply with Hackage requirements #8897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cabal/src/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE LambdaCase #-}

-----------------------------------------------------------------------------
-- |
-- Module : Distribution.PackageDescription.Check
Expand Down Expand Up @@ -28,6 +30,7 @@ module Distribution.PackageDescription.Check (
checkConfiguredPackage,
wrapParseWarning,
ppPackageCheck,
isHackageDistError,

-- ** Checking package contents
checkPackageFiles,
Expand Down Expand Up @@ -846,6 +849,15 @@ data PackageCheck =
| PackageDistInexcusable { explanation :: CheckExplanation }
deriving (Eq, Ord)

-- | Would Hackage refuse a package because of this error?
isHackageDistError :: PackageCheck -> Bool
isHackageDistError = \case
(PackageBuildImpossible {}) -> True
(PackageBuildWarning {}) -> True
(PackageDistInexcusable {}) -> True
(PackageDistSuspicious {}) -> False
(PackageDistSuspiciousWarn {}) -> False

-- | Pretty printing 'PackageCheck'.
--
ppPackageCheck :: PackageCheck -> String
Expand Down
5 changes: 1 addition & 4 deletions Cabal/src/Distribution/Simple/SrcDist.hs
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,7 @@ printPackageProblems :: Verbosity -> PackageDescription -> IO ()
printPackageProblems verbosity pkg_descr = do
ioChecks <- checkPackageFiles verbosity pkg_descr "."
let pureChecks = checkConfiguredPackage pkg_descr
isDistError (PackageDistSuspicious _) = False
isDistError (PackageDistSuspiciousWarn _) = False
isDistError _ = True
(errors, warnings) = partition isDistError (pureChecks ++ ioChecks)
(errors, warnings) = partition isHackageDistError (pureChecks ++ ioChecks)
unless (null errors) $
notice verbosity $ "Distribution quality errors:\n"
++ unlines (map ppPackageCheck errors)
Expand Down
13 changes: 5 additions & 8 deletions cabal-install/src/Distribution/Client/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ readGenericPackageDescriptionCheck verbosity fpath = do
die' verbosity "parse error"
Right x -> return (warnings, x)

-- | Note: must be called with the CWD set to the directory containing
-- | Checks a packge for common errors. Returns @True@ if the package
-- is fit to upload to Hackage, @False@ otherwise.
-- Note: must be called with the CWD set to the directory containing
-- the '.cabal' file.
check :: Verbosity -> IO Bool
check verbosity = do
Expand Down Expand Up @@ -94,20 +96,15 @@ check verbosity = do
warn verbosity "The following errors will cause portability problems on other environments:"
printCheckMessages distInexusable

let isDistError (PackageDistSuspicious {}) = False
isDistError (PackageDistSuspiciousWarn {}) = False
isDistError _ = True
isCheckError (PackageDistSuspiciousWarn {}) = False
isCheckError _ = True
errors = filter isDistError packageChecks
let errors = filter isHackageDistError packageChecks

unless (null errors) $
warn verbosity "Hackage would reject this package."

when (null packageChecks) $
notice verbosity "No errors or warnings could be found in the package."

return (not . any isCheckError $ packageChecks)
return (null errors)

where
printCheckMessages :: [PackageCheck] -> IO ()
Expand Down
5 changes: 3 additions & 2 deletions cabal-install/src/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,9 @@ checkCommand = CommandUI {
"Expects a .cabal package file in the current directory.\n"
++ "\n"
++ "The checks correspond to the requirements to packages on Hackage. "
++ "If no errors and warnings are reported, Hackage will accept this "
++ "package.\n",
++ "If no errors and warnings are reported, Hackage should accept the "
++ "package. If errors are present, `check` exits with 1 and Hackage "
++ "will refuse the package.\n",
commandNotes = Nothing,
commandUsage = usageFlags "check",
commandDefaultFlags = toFlag normal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `cxx-options`, do not use `-O1`.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `default-extensions` need ≥1.10.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `default-language` need ≥1.10.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `extra-dynamic-library-flavour` need ≥3.0.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `mixins` need ≥2.0.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `cmm-sources` and friends need ≥3.0.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `virtual-modules` need ≥2.2.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Deprecated extension.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- No category.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- No description.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- No maintainer.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- No synopsis.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Description should be longer than synopsis.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Tricky option in `ghc-shared-options`.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `licence-file` missing.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Suspicious license BSD4.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Suspicious license version.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Dubious AllRightsReserved.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- `signatures` field used with cabal-version < 2.0
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Profiling flags unsuited for distribution.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Unused flag.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import Test.Cabal.Prelude

-- Missing VCS info.
main = cabalTest $
fails $ cabal "check" []
cabal "check" []
14 changes: 14 additions & 0 deletions changelog.d/pr-8897
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
synopsis: Make check comply with Hackage requirements
packages: Cabal cabal-install
prs: #8897

description: {

- `cabal check` will only return exitcode 1 when the package is not fit
for Hackage. E.g. it will not error anymore when your `synopsis:` is
larger than `description:`, just emit a warning.
- Cabal: Distribution.Client.Check now exports `isHackageDistError`, for
third-party tools to know if a specific error will preclude a package
from being uploaded to Hacakge.

}
3 changes: 2 additions & 1 deletion doc/cabal-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,8 @@ Run ``cabal check`` in the folder where your ``.cabal`` package file is.
Set verbosity level (0–3, default is 1).

``cabal check`` mimics Hackage's requirements: if no error or warning
is reported, Hackage should accept your package.
is reported, Hackage should accept your package. If errors are present
``cabal check`` exits with ``1`` and Hackage will refuse the package.

cabal sdist
^^^^^^^^^^^
Expand Down