Skip to content

Commit

Permalink
Add TARGET option to cabal check
Browse files Browse the repository at this point in the history
e.g. `cabal check ~/my-projects/reactive-strawberry/`
  • Loading branch information
ffaf1 committed Jan 2, 2024
1 parent 5569146 commit 32a4d0c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 13 deletions.
13 changes: 8 additions & 5 deletions cabal-install/src/Distribution/Client/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
11 changes: 7 additions & 4 deletions cabal-install/src/Distribution/Client/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions cabal-testsuite/PackageTests/Check/CheckTarget/cabal.out
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions cabal-testsuite/PackageTests/Check/CheckTarget/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.Cabal.Prelude

-- `cabal check` works when passing a directory to check.
main = cabalTest $ do
cabal "check" ["target/"]
Empty file.
12 changes: 12 additions & 0 deletions cabal-testsuite/PackageTests/Check/CheckTarget/target/pkg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cabal-version: 3.0
name: pkg
synopsis: synopsis
description: description
version: 0
category: example
maintainer: [email protected]
license: GPL-3.0-or-later

library
exposed-modules: Foo
default-language: Haskell2010
7 changes: 4 additions & 3 deletions doc/cabal-commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 32a4d0c

Please sign in to comment.