Skip to content

Commit

Permalink
Make cabal check warn about globs that don't match anything
Browse files Browse the repository at this point in the history
These globs make `haddock`, `sdist` and `install` die, so they
definitely ought to be warned about!

Because of the dying behaviour, I made the checks dist-inexcusable;
starting from a clean slate I would probably have only made them
suspicious, but this isn't terrible.
  • Loading branch information
quasicomputational authored and typedrat committed Jul 9, 2018
1 parent 6c1342a commit 6a55a01
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cabal/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
accepts a `Verbosity` argument.
* `cabal check` now warns about globs that refer to missing
directories.
* `cabal check` now warns about globs that do not match any files.

----

Expand Down
18 changes: 17 additions & 1 deletion Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2167,14 +2167,30 @@ checkGlobFiles :: Verbosity
checkGlobFiles verbosity pkg root =
fmap concat $ for allGlobs $ \(field, dir, glob) -> do
results <- matchDirFileGlob' verbosity (specVersion pkg) (root </> dir) glob
return $ results >>= getWarning field glob
let individualWarnings = results >>= getWarning field glob
noMatchesWarning =
[ PackageDistInexcusable $
"In '" ++ field ++ "': the pattern '" ++ glob ++ "' does not"
++ " match any files."
| all (not . suppressesNoMatchesWarning) results
]
return (noMatchesWarning ++ individualWarnings)
where
adjustedDataDir = if null (dataDir pkg) then "." else dataDir pkg
allGlobs = concat
[ (,,) "extra-source-files" "." <$> extraSrcFiles pkg
, (,,) "extra-doc-files" "." <$> extraDocFiles pkg
, (,,) "data-files" adjustedDataDir <$> dataFiles pkg
]

-- If there's a missing directory in play, since our globs don't
-- (currently) support disjunction, that will always mean there are no
-- matches. The no matches error in this case is strictly less informative
-- than the missing directory error, so sit on it.
suppressesNoMatchesWarning (GlobMatch _) = True
suppressesNoMatchesWarning (GlobWarnMultiDot _) = False
suppressesNoMatchesWarning (GlobMissingDirectory _) = True

getWarning :: String -> FilePath -> GlobResult FilePath -> [PackageCheck]
getWarning _ _ (GlobMatch _) =
[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# cabal check
Warning: The package will not build sanely due to these errors:
Warning: This package description follows version 2.4 of the Cabal specification. This tool only supports up to version 2.3.0.0.
Warning: The following errors will cause portability problems on other environments:
Warning: In 'data-files': the pattern 'non-existent-directory/**/*.dat' attempts to match files in the directory 'non-existent-directory', but there is no directory by that name.
Warning: In 'data-files': the pattern 'non-existent-directory/*.dat' attempts to match files in the directory 'non-existent-directory', but there is no directory by that name.
Warning: Hackage would reject this package.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cabal-version: 2.4
cabal-version: 2.2
name: pkg
version: 0
data-files:
non-existent-directory/**/*.dat
non-existent-directory/*.dat
category: example
maintainer: none@example.com
synopsis: synopsis
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
index.js
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/Check/NoGlobMatches/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cabal check
Warning: The following errors will cause portability problems on other environments:
Warning: In 'extra-doc-files': the pattern '*.html' does not match any files.
Warning: Hackage would reject this package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Test.Cabal.Prelude
main = cabalTest $
fails $ cabal "check" []
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/Check/NoGlobMatches/pkg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cabal-version: 2.2
name: pkg
version: 0
extra-doc-files:
*.html
category: example
maintainer: none@example.com
synopsis: synopsis
description: description
license: BSD-3-Clause

library
exposed-modules: Foo
default-language: Haskell2010

0 comments on commit 6a55a01

Please sign in to comment.