Skip to content

Commit cc75891

Browse files
wismillmergify[bot]
andcommitted
cabal-install: check: Whitelist doc file extensions (#8747)
* check: Test only doc files with supported extensions * Cleanup --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit bae536f)
1 parent 05b0630 commit cc75891

File tree

10 files changed

+10
-16
lines changed

10 files changed

+10
-16
lines changed

Cabal/src/Distribution/PackageDescription/Check.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,19 +2545,21 @@ checkGlobFiles verbosity pkg root = do
25452545
)
25462546

25472547
-- Predicate for desirable documentation file on Hackage server
2548-
isDesirableExtraDocFile :: [FilePath] -> FilePath -> Bool
2549-
isDesirableExtraDocFile paths path = map toLower basename `elem` paths
2548+
isDesirableExtraDocFile :: ([FilePath], [FilePath]) -> FilePath -> Bool
2549+
isDesirableExtraDocFile (basenames, extensions) path =
2550+
basename `elem` basenames && ext `elem` extensions
25502551
where
2551-
(basename, _ext) = splitExtension path
2552+
(basename, ext) = splitExtension (map toLower path)
25522553

2553-
-- Changelog patterns
2554+
-- Changelog patterns (basenames & extensions)
25542555
-- Source: hackage-server/src/Distribution/Server/Packages/ChangeLog.hs
25552556
desirableChangeLog =
25562557
[ "news"
25572558
, "changelog"
25582559
, "change_log"
25592560
, "changes"
25602561
]
2562+
desirableChangeLogExtensions = ["", ".txt", ".md", ".markdown", ".rst"]
25612563
-- [TODO] Check readme. Observations:
25622564
-- • Readme is not necessary if package description is good.
25632565
-- • Some readmes exists only for repository browsing.
@@ -2567,7 +2569,7 @@ checkGlobFiles verbosity pkg root = do
25672569
-- -- Readme patterns
25682570
-- -- Source: hackage-server/src/Distribution/Server/Packages/Readme.hs
25692571
-- desirableReadme = ["readme"]
2570-
desirableDocFiles = desirableChangeLog
2572+
desirableDocFiles = (desirableChangeLog, desirableChangeLogExtensions)
25712573

25722574
-- If there's a missing directory in play, since our globs don't
25732575
-- (currently) support disjunction, that will always mean there are no
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Test.Cabal.Prelude
22

3-
import System.Directory (createDirectoryIfMissing)
4-
53
-- Omitting ChangeLog.md but not README in extra-doc-files
64
main = cabalTest $ do
75
cabal "check" []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Needed for test, to ensure we test the file extension as well.
2+
!ChangeLog.md~
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Test.Cabal.Prelude
22

3-
import System.Directory (createDirectoryIfMissing)
4-
53
-- Omitting ChangeLog.md but not README in extra-doc-files
64
main = cabalTest $ do
75
cabal "check" []

cabal-testsuite/PackageTests/Check/PackageFiles/MissingExpectedDocFiles/ChangeLog/NotIncluded/V3.0/CHANGELOG.TXT

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# cabal check
22
Warning: These warnings may cause trouble when distributing the package:
3-
Warning: Please consider including the file './ChangeLog.md' in the 'extra-doc-files' section of the .cabal file if it contains useful information for users of the package.
3+
Warning: 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.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Test.Cabal.Prelude
22

3-
import System.Directory (createDirectoryIfMissing)
4-
53
-- Omitting ChangeLog.md but not README in extra-doc-files
64
main = cabalTest $ do
75
cabal "check" []
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Test.Cabal.Prelude
22

3-
import System.Directory (createDirectoryIfMissing)
4-
53
-- Included ChangeLog.md but not in extra-doc-files
64
main = cabalTest $ do
75
cabal "check" []
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Test.Cabal.Prelude
22

3-
import System.Directory (createDirectoryIfMissing)
4-
53
-- Included ChangeLog.md but not in extra-doc-files
64
main = cabalTest $ do
75
cabal "check" []

0 commit comments

Comments
 (0)