diff --git a/cabal-install/src/Distribution/Client/Check.hs b/cabal-install/src/Distribution/Client/Check.hs index 91fd6c7b448..41f5d4599d7 100644 --- a/cabal-install/src/Distribution/Client/Check.hs +++ b/cabal-install/src/Distribution/Client/Check.hs @@ -29,7 +29,7 @@ import Distribution.PackageDescription.Parsec , runParseResult ) import Distribution.Parsec (PWarning (..), showPError) -import Distribution.Simple.Utils (defaultPackageDesc, dieWithException, notice, warn, warnError) +import Distribution.Simple.Utils (dieWithException, findPackageDesc, notice, warn, warnError) import System.IO (hPutStr, stderr) import qualified Control.Monad as CM @@ -59,13 +59,16 @@ readGenericPackageDescriptionCheck verbosity fpath = do -- 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 -> [CheckExplanationIDString] -> IO Bool -check verbosity ignores = do - pdfile <- defaultPackageDesc verbosity +check :: Verbosity -> [CheckExplanationIDString] -> FilePath -> IO Bool +check verbosity ignores checkDir = do + epdf <- findPackageDesc checkDir + pdfile <- case epdf of + Right cf -> return cf + Left e -> dieWithException verbosity e (ws, ppd) <- readGenericPackageDescriptionCheck verbosity pdfile -- convert parse warnings into PackageChecks let ws' = map (wrapParseWarning pdfile) ws - ioChecks <- checkPackageFilesGPD verbosity ppd "." + ioChecks <- checkPackageFilesGPD verbosity ppd checkDir let packageChecksPrim = ioChecks ++ checkPackage ppd ++ ws' (packageChecks, unrecs) = filterPackageChecksByIdString packageChecksPrim ignores diff --git a/cabal-install/src/Distribution/Client/Errors.hs b/cabal-install/src/Distribution/Client/Errors.hs index ada3eca5268..7e250ba5127 100644 --- a/cabal-install/src/Distribution/Client/Errors.hs +++ b/cabal-install/src/Distribution/Client/Errors.hs @@ -405,7 +405,7 @@ exceptionMessageCabalInstall e = case e of "the 'upload' command expects only .tar.gz archives: " ++ intercalate ", " otherFiles FileNotFound tarfile -> "file not found: " ++ tarfile - CheckAction extraArgs -> "'check' doesn't take any extra arguments: " ++ unwords extraArgs + CheckAction extraArgs -> "'check' only takes one (optional) directory path argument: " ++ unwords extraArgs ReportAction extraArgs -> "'report' doesn't take any extra arguments: " ++ unwords extraArgs InitAction -> "'init' only takes a single, optional, extra " diff --git a/cabal-install/src/Distribution/Client/Main.hs b/cabal-install/src/Distribution/Client/Main.hs index d7cf0ea49b4..af94067e3ce 100644 --- a/cabal-install/src/Distribution/Client/Main.hs +++ b/cabal-install/src/Distribution/Client/Main.hs @@ -1230,10 +1230,13 @@ checkAction :: CheckFlags -> [String] -> Action checkAction checkFlags extraArgs _globalFlags = do let verbosityFlag = checkVerbosity checkFlags verbosity = fromFlag verbosityFlag - unless (null extraArgs) $ - dieWithException verbosity $ - CheckAction extraArgs - allOk <- Check.check (fromFlag verbosityFlag) (checkIgnore checkFlags) + path <- case extraArgs of + [] -> return "." + [dp] -> return dp + (_:es) -> + dieWithException verbosity $ + CheckAction es + allOk <- Check.check (fromFlag verbosityFlag) (checkIgnore checkFlags) path unless allOk exitFailure formatAction :: Flag Verbosity -> [String] -> Action diff --git a/cabal-testsuite/PackageTests/Check/CheckTarget/cabal.out b/cabal-testsuite/PackageTests/Check/CheckTarget/cabal.out new file mode 100644 index 00000000000..7ef1e41bdce --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/CheckTarget/cabal.out @@ -0,0 +1,3 @@ +# cabal check +These warnings may cause trouble when distributing the package: +Warning: [no-docs] Please consider including the file './CHANGELOG.TXT' in the 'extra-doc-files' section of the .cabal file if it contains useful information for users of the package. diff --git a/cabal-testsuite/PackageTests/Check/CheckTarget/cabal.test.hs b/cabal-testsuite/PackageTests/Check/CheckTarget/cabal.test.hs new file mode 100644 index 00000000000..cff804a5808 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/CheckTarget/cabal.test.hs @@ -0,0 +1,5 @@ +import Test.Cabal.Prelude + +-- `cabal check` works when passing a directory to check. +main = cabalTest $ do + cabal "check" ["target/"] diff --git a/cabal-testsuite/PackageTests/Check/CheckTarget/target/CHANGELOG.TXT b/cabal-testsuite/PackageTests/Check/CheckTarget/target/CHANGELOG.TXT new file mode 100644 index 00000000000..e69de29bb2d diff --git a/cabal-testsuite/PackageTests/Check/CheckTarget/target/pkg.cabal b/cabal-testsuite/PackageTests/Check/CheckTarget/target/pkg.cabal new file mode 100644 index 00000000000..c1d907fbe37 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/CheckTarget/target/pkg.cabal @@ -0,0 +1,12 @@ +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 diff --git a/doc/cabal-commands.rst b/doc/cabal-commands.rst index 229a5b7a616..c959fd3d8ba 100644 --- a/doc/cabal-commands.rst +++ b/doc/cabal-commands.rst @@ -1166,11 +1166,12 @@ Sanity checks and shipping cabal check ^^^^^^^^^^^ -``cabal check [FLAGS]`` checks the package for common mistakes (e.g.: if -it is missing important fields like ``synopsis``, if it is using +``cabal check [FLAGS] [TARGET]`` checks the package for common mistakes +(e.g.: if it is missing important fields like ``synopsis``, if it is using tricky GHC options, etc.). -Run ``cabal check`` in the folder where your ``.cabal`` package file is. +Specify a ``TARGET`` folder or run ``cabal check`` in the folder where +your ``.cabal`` package file is. .. option:: -i, --ignore=WARNING