Skip to content

Commit fe82d9b

Browse files
authored
Merge pull request #9673 from alt-romes/wip/romes/globbing
Merge two Globbing Modules and Fix #5349
2 parents 3d3622f + e2019f5 commit fe82d9b

File tree

29 files changed

+754
-549
lines changed

29 files changed

+754
-549
lines changed

Cabal-tests/tests/UnitTests/Distribution/Simple/Glob.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE LambdaCase #-}
12
module UnitTests.Distribution.Simple.Glob
23
( tests
34
) where
@@ -54,7 +55,7 @@ compatibilityTests version =
5455
[ testCase "literal match" $
5556
testMatches "foo/a" [GlobMatch "foo/a"]
5657
, testCase "literal no match on prefix" $
57-
testMatches "foo/c.html" []
58+
testMatches "foo/c.html" [GlobMatchesDirectory "foo/c.html"]
5859
, testCase "literal no match on suffix" $
5960
testMatches "foo/a.html" [GlobMatch "foo/a.html"]
6061
, testCase "literal no prefix" $
@@ -64,7 +65,7 @@ compatibilityTests version =
6465
, testCase "glob" $
6566
testMatches "*.html" [GlobMatch "a.html", GlobMatch "b.html"]
6667
, testCase "glob in subdir" $
67-
testMatches "foo/*.html" [GlobMatch "foo/a.html", GlobMatch "foo/b.html"]
68+
testMatches "foo/*.html" [GlobMatchesDirectory "foo/c.html", GlobMatch "foo/b.html", GlobMatch "foo/a.html"]
6869
, testCase "glob multiple extensions" $
6970
testMatches "foo/*.html.gz" [GlobMatch "foo/a.html.gz", GlobMatch "foo/b.html.gz"]
7071
, testCase "glob in deep subdir" $
@@ -101,13 +102,16 @@ testMatchesVersion version pat expected = do
101102
where
102103
isEqual = (==) `on` (sort . fmap (fmap normalise))
103104
checkPure globPat = do
104-
let actual = mapMaybe (fileGlobMatches globPat) sampleFileNames
105-
unless (sort expected == sort actual) $
105+
let actual = mapMaybe (\p -> (p <$) <$> fileGlobMatches version globPat p) sampleFileNames
106+
-- We drop directory matches from the expected results since the pure
107+
-- check can't identify that kind of match.
108+
expected' = filter (\case GlobMatchesDirectory _ -> False; _ -> True) expected
109+
unless (sort expected' == sort actual) $
106110
assertFailure $ "Unexpected result (pure matcher): " ++ show actual
107111
checkIO globPat =
108112
withSystemTempDirectory "globstar-sample" $ \tmpdir -> do
109113
makeSampleFiles tmpdir
110-
actual <- runDirFileGlob Verbosity.normal tmpdir globPat
114+
actual <- runDirFileGlob Verbosity.normal (Just version) tmpdir globPat
111115
unless (isEqual actual expected) $
112116
assertFailure $ "Unexpected result (impure matcher): " ++ show actual
113117

Cabal/Cabal.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ library
108108
Distribution.Simple.GHCJS
109109
Distribution.Simple.Haddock
110110
Distribution.Simple.Glob
111+
Distribution.Simple.Glob.Internal
111112
Distribution.Simple.HaskellSuite
112113
Distribution.Simple.Hpc
113114
Distribution.Simple.Install

Cabal/src/Distribution/PackageDescription/Check.hs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,20 @@ import Distribution.PackageDescription.Check.Warning
6161
import Distribution.Parsec.Warning (PWarning)
6262
import Distribution.Pretty (prettyShow)
6363
import Distribution.Simple.Glob
64+
( Glob
65+
, GlobResult (..)
66+
, globMatches
67+
, parseFileGlob
68+
, runDirFileGlob
69+
)
6470
import Distribution.Simple.Utils hiding (findPackageDesc, notice)
6571
import Distribution.Utils.Generic (isAscii)
6672
import Distribution.Utils.Path
73+
( LicenseFile
74+
, PackageDir
75+
, SymbolicPath
76+
, getSymbolicPath
77+
)
6778
import Distribution.Verbosity
6879
import Distribution.Version
6980
import System.FilePath (splitExtension, takeFileName, (<.>), (</>))
@@ -170,7 +181,7 @@ checkPackageFilesGPD verbosity gpd root =
170181

171182
checkPreIO =
172183
CheckPreDistributionOps
173-
{ runDirFileGlobM = \fp g -> runDirFileGlob verbosity (root </> fp) g
184+
{ runDirFileGlobM = \fp g -> runDirFileGlob verbosity (Just . specVersion $ packageDescription gpd) (root </> fp) g
174185
, getDirectoryContentsM = System.Directory.getDirectoryContents . relative
175186
}
176187

@@ -853,13 +864,14 @@ checkGlobResult title fp rs = dirCheck ++ catMaybes (map getWarning rs)
853864
[PackageDistSuspiciousWarn $ GlobNoMatch title fp]
854865
| otherwise = []
855866

856-
-- If there's a missing directory in play, since our globs don't
857-
-- (currently) support disjunction, that will always mean there are
867+
-- If there's a missing directory in play, since globs in Cabal packages
868+
-- don't (currently) support disjunction, that will always mean there are
858869
-- no matches. The no matches error in this case is strictly less
859870
-- informative than the missing directory error.
860871
withoutNoMatchesWarning (GlobMatch _) = True
861872
withoutNoMatchesWarning (GlobWarnMultiDot _) = False
862873
withoutNoMatchesWarning (GlobMissingDirectory _) = True
874+
withoutNoMatchesWarning (GlobMatchesDirectory _) = True
863875

864876
getWarning :: GlobResult FilePath -> Maybe PackageCheck
865877
getWarning (GlobMatch _) = Nothing
@@ -871,6 +883,9 @@ checkGlobResult title fp rs = dirCheck ++ catMaybes (map getWarning rs)
871883
Just $ PackageDistSuspiciousWarn (GlobExactMatch title fp file)
872884
getWarning (GlobMissingDirectory dir) =
873885
Just $ PackageDistSuspiciousWarn (GlobNoDir title fp dir)
886+
-- GlobMatchesDirectory is handled elsewhere if relevant;
887+
-- we can discard it here.
888+
getWarning (GlobMatchesDirectory _) = Nothing
874889

875890
-- ------------------------------------------------------------
876891
-- Other exports
@@ -1012,10 +1027,6 @@ checkMissingDocs dgs esgs edgs = do
10121027
return (mcs ++ pcs)
10131028
)
10141029
where
1015-
-- From Distribution.Simple.Glob.
1016-
globMatches :: [GlobResult a] -> [a]
1017-
globMatches input = [a | GlobMatch a <- input]
1018-
10191030
checkDoc
10201031
:: Bool -- Cabal spec ≥ 1.18?
10211032
-> [FilePath] -- Desirables.

Cabal/src/Distribution/PackageDescription/Check/Paths.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import Distribution.PackageDescription.Check.Common
2424
import Distribution.PackageDescription.Check.Monad
2525
import Distribution.Simple.CCompiler
2626
import Distribution.Simple.Glob
27+
( Glob
28+
, explainGlobSyntaxError
29+
, isRecursiveInRoot
30+
, parseFileGlob
31+
)
2732
import Distribution.Simple.Utils hiding (findPackageDesc, notice)
2833
import System.FilePath (splitDirectories, splitPath, takeExtension)
2934

0 commit comments

Comments
 (0)