Commit 6a55a01f authored by quasicomputational's avatar quasicomputational Committed by Alexis Williams

Make cabal check warn about globs that don't match anything

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.
parent 6c1342a3
......@@ -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.
----
......
......@@ -2167,7 +2167,14 @@ 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
......@@ -2175,6 +2182,15 @@ checkGlobFiles verbosity pkg root =
, (,,) "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 _) =
[]
......
# 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.
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
......
# 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.
import Test.Cabal.Prelude
main = cabalTest $
fails $ cabal "check" []
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment