Skip to content

Commit 12b3f7b

Browse files
committed
Add TARGET option to cabal check
e.g. `cabal check ~/my-projects/reactive-strawberry/`
1 parent df5e188 commit 12b3f7b

File tree

9 files changed

+52
-12
lines changed

9 files changed

+52
-12
lines changed

cabal-install/src/Distribution/Client/Check.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Distribution.PackageDescription.Parsec
2929
, runParseResult
3030
)
3131
import Distribution.Parsec (PWarning (..), showPError)
32-
import Distribution.Simple.Utils (defaultPackageDesc, dieWithException, notice, warn, warnError)
32+
import Distribution.Simple.Utils (dieWithException, findPackageDesc, notice, warn, warnError)
3333
import System.IO (hPutStr, stderr)
3434

3535
import qualified Control.Monad as CM
@@ -64,13 +64,18 @@ check
6464
-> [CheckExplanationIDString]
6565
-- ^ List of check-ids in String form
6666
-- (e.g. @invalid-path-win@) to ignore.
67+
-> FilePath
68+
-- ^ Folder to check (where `.cabal` file is).
6769
-> IO Bool
68-
check verbosity ignores = do
69-
pdfile <- defaultPackageDesc verbosity
70+
check verbosity ignores checkDir = do
71+
epdf <- findPackageDesc checkDir
72+
pdfile <- case epdf of
73+
Right cf -> return cf
74+
Left e -> dieWithException verbosity e
7075
(ws, ppd) <- readGenericPackageDescriptionCheck verbosity pdfile
7176
-- convert parse warnings into PackageChecks
7277
let ws' = map (wrapParseWarning pdfile) ws
73-
ioChecks <- checkPackageFilesGPD verbosity ppd "."
78+
ioChecks <- checkPackageFilesGPD verbosity ppd checkDir
7479
let packageChecksPrim = ioChecks ++ checkPackage ppd ++ ws'
7580
(packageChecks, unrecs) = filterPackageChecksByIdString packageChecksPrim ignores
7681

cabal-install/src/Distribution/Client/Errors.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ exceptionMessageCabalInstall e = case e of
405405
"the 'upload' command expects only .tar.gz archives: "
406406
++ intercalate ", " otherFiles
407407
FileNotFound tarfile -> "file not found: " ++ tarfile
408-
CheckAction extraArgs -> "'check' doesn't take any extra arguments: " ++ unwords extraArgs
408+
CheckAction extraArgs -> "'check' only takes one (optional) directory path argument: " ++ unwords extraArgs
409409
ReportAction extraArgs -> "'report' doesn't take any extra arguments: " ++ unwords extraArgs
410410
InitAction ->
411411
"'init' only takes a single, optional, extra "

cabal-install/src/Distribution/Client/Main.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,10 +1230,13 @@ checkAction :: CheckFlags -> [String] -> Action
12301230
checkAction checkFlags extraArgs _globalFlags = do
12311231
let verbosityFlag = checkVerbosity checkFlags
12321232
verbosity = fromFlag verbosityFlag
1233-
unless (null extraArgs) $
1234-
dieWithException verbosity $
1235-
CheckAction extraArgs
1236-
allOk <- Check.check (fromFlag verbosityFlag) (checkIgnore checkFlags)
1233+
path <- case extraArgs of
1234+
[] -> return "."
1235+
[dp] -> return dp
1236+
(_ : es) ->
1237+
dieWithException verbosity $
1238+
CheckAction es
1239+
allOk <- Check.check (fromFlag verbosityFlag) (checkIgnore checkFlags) path
12371240
unless allOk exitFailure
12381241

12391242
formatAction :: Flag Verbosity -> [String] -> Action
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# cabal check
2+
These warnings may cause trouble when distributing the package:
3+
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.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
3+
-- `cabal check` works when passing a directory to check.
4+
main = cabalTest $ do
5+
cabal "check" ["target/"]

cabal-testsuite/PackageTests/Check/CheckTarget/target/CHANGELOG.TXT

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cabal-version: 3.0
2+
name: pkg
3+
synopsis: synopsis
4+
description: description
5+
version: 0
6+
category: example
7+
maintainer: [email protected]
8+
license: GPL-3.0-or-later
9+
10+
library
11+
exposed-modules: Foo
12+
default-language: Haskell2010

changelog.d/pr-9605

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
synopsis: Add TARGET to `cabal check`
2+
packages: cabal-install
3+
prs: #9605
4+
issues: #6282
5+
6+
description: {
7+
8+
- `cabal check` now supports TARGET, e.g. `cabal check ~/my/folder`.
9+
10+
}
11+

doc/cabal-commands.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,11 +1166,12 @@ Sanity checks and shipping
11661166
cabal check
11671167
^^^^^^^^^^^
11681168

1169-
``cabal check [FLAGS]`` checks the package for common mistakes (e.g.: if
1170-
it is missing important fields like ``synopsis``, if it is using
1169+
``cabal check [FLAGS] [TARGET]`` checks the package for common mistakes
1170+
(e.g.: if it is missing important fields like ``synopsis``, if it is using
11711171
tricky GHC options, etc.).
11721172

1173-
Run ``cabal check`` in the folder where your ``.cabal`` package file is.
1173+
Specify a ``TARGET`` folder or run ``cabal check`` in the folder where
1174+
your ``.cabal`` package file is.
11741175

11751176
.. option:: -i, --ignore=WARNING
11761177

0 commit comments

Comments
 (0)