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 10, 2024
1 parent df5e188 commit 12b3f7b
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 12 deletions.
13 changes: 9 additions & 4 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 @@ -64,13 +64,18 @@ check
-> [CheckExplanationIDString]
-- ^ List of check-ids in String form
-- (e.g. @invalid-path-win@) to ignore.
-> FilePath
-- ^ Folder to check (where `.cabal` file is).
-> IO Bool
check verbosity ignores = do
pdfile <- defaultPackageDesc verbosity
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
11 changes: 11 additions & 0 deletions changelog.d/pr-9605
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Add TARGET to `cabal check`
packages: cabal-install
prs: #9605
issues: #6282

description: {

- `cabal check` now supports TARGET, e.g. `cabal check ~/my/folder`.

}

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 12b3f7b

Please sign in to comment.