@@ -40,7 +40,7 @@ import Data.Foldable (foldrM)
40
40
import Distribution.Compat.Prelude
41
41
import Prelude ()
42
42
43
- import Data.List (delete , group )
43
+ import Data.List (group )
44
44
import Distribution.CabalSpecVersion
45
45
import Distribution.Compat.Lens
46
46
import Distribution.Compiler
@@ -784,12 +784,12 @@ ppExplanation MissingSourceControl =
784
784
++ " control information in the .cabal file using one or more "
785
785
++ " 'source-repository' sections. See the Cabal user guide for "
786
786
++ " details."
787
- ppExplanation (MissingExpectedExtraDocFiles paths ) =
788
- " Please consider including the " ++ quotes paths
787
+ ppExplanation (MissingExpectedExtraDocFiles files ) =
788
+ " Please consider including " ++ gather files
789
789
++ " in the 'extra-doc-files' section of the .cabal file "
790
790
++ " if it contains useful information for users of the package."
791
- where quotes [p] = " file " ++ quote p
792
- quotes ps = " files " ++ intercalate " , " ( map quote ps)
791
+ where gather [p] = p ++ " file "
792
+ gather ps = intercalate " and " ps ++ " files "
793
793
ppExplanation (WrongFieldExpectedExtraDocFiles field paths) =
794
794
" Please consider moving the " ++ quotes paths
795
795
++ " from the '" ++ field ++ " ' section of the .cabal file "
@@ -2411,23 +2411,16 @@ checkGlobFiles :: Verbosity
2411
2411
-> FilePath
2412
2412
-> IO [PackageCheck ]
2413
2413
checkGlobFiles verbosity pkg root = do
2414
- -- Get the desirable doc files from package’s directory
2415
- rootContents <- System.Directory. getDirectoryContents root
2416
- desirableDocFiles0 <- filterM System. doesFileExist
2417
- [ root </> file
2418
- | file <- rootContents
2419
- , isDesirableExtraDocFile file
2420
- ]
2421
-
2422
2414
-- Check the globs
2423
- (warnings, unlisted ) <- foldrM checkGlob ([] , desirableDocFiles0 ) allGlobs
2415
+ (warnings, missingChangeLog ) <- foldrM checkGlob ([] , True ) allGlobs
2424
2416
2425
- return $ if null unlisted
2426
- -- No missing desirable file
2427
- then warnings
2417
+ return $ if missingChangeLog
2428
2418
-- Some missing desirable files
2429
- else warnings ++
2430
- [PackageDistSuspiciousWarn (MissingExpectedExtraDocFiles unlisted)]
2419
+ then let unlisted = [ " a changelog" | missingChangeLog]
2420
+ in warnings ++
2421
+ [PackageDistSuspiciousWarn (MissingExpectedExtraDocFiles unlisted)]
2422
+ -- No missing desirable file
2423
+ else warnings
2431
2424
where
2432
2425
adjustedDataDir = if null (dataDir pkg) then root else root </> dataDir pkg
2433
2426
-- Cabal fields with globs
@@ -2440,92 +2433,101 @@ checkGlobFiles verbosity pkg root = do
2440
2433
2441
2434
-- For each field with globs (see allGlobs), look for:
2442
2435
-- • errors (missing directory, no match)
2443
- -- • omitted documentation files (readme, changelog)
2436
+ -- • omitted documentation files (changelog)
2444
2437
checkGlob :: (String , Bool , FilePath , FilePath )
2445
- -> ([PackageCheck ], [ FilePath ] )
2446
- -> IO ([PackageCheck ], [ FilePath ] )
2447
- checkGlob (field, isDocField, dir, glob) acc@ (warnings, desirableDocs ) =
2438
+ -> ([PackageCheck ], Bool )
2439
+ -> IO ([PackageCheck ], Bool )
2440
+ checkGlob (field, isDocField, dir, glob) acc@ (warnings, changelog ) =
2448
2441
-- Note: we just skip over parse errors here; they're reported elsewhere.
2449
2442
case parseFileGlob (specVersion pkg) glob of
2450
2443
Left _ -> return acc
2451
2444
Right parsedGlob -> do
2452
2445
results <- runDirFileGlob verbosity (root </> dir) parsedGlob
2453
- let acc0 = (warnings, True , [] , desirableDocs )
2446
+ let acc0 = (warnings, True , changelog, [] )
2454
2447
return $ case foldr checkGlobResult acc0 results of
2455
- (individualWarnings , noMatchesWarn, wrongPaths, desirableDocs' ) ->
2448
+ (individualWarn , noMatchesWarn, changelog', wrongPaths ) ->
2456
2449
let wrongFieldWarnings = [ PackageDistSuspiciousWarn
2457
2450
(WrongFieldExpectedExtraDocFiles
2458
2451
field wrongPaths)
2459
2452
| not (null wrongPaths) ]
2460
2453
in
2461
2454
( if noMatchesWarn
2462
2455
then [PackageDistSuspiciousWarn (GlobNoMatch field glob)] ++
2463
- individualWarnings ++
2456
+ individualWarn ++
2464
2457
wrongFieldWarnings
2465
- else individualWarnings ++ wrongFieldWarnings
2466
- , desirableDocs '
2458
+ else individualWarn ++ wrongFieldWarnings
2459
+ , changelog '
2467
2460
)
2468
2461
where
2469
2462
checkGlobResult :: GlobResult FilePath
2470
- -> ([PackageCheck ], Bool , [ FilePath ] , [FilePath ])
2471
- -> ([PackageCheck ], Bool , [ FilePath ] , [FilePath ])
2472
- checkGlobResult result (ws, noMatchesWarn, wrongPaths, docFiles ) =
2463
+ -> ([PackageCheck ], Bool , Bool , [FilePath ])
2464
+ -> ([PackageCheck ], Bool , Bool , [FilePath ])
2465
+ checkGlobResult result (ws, noMatchesWarn, changelog1, wrongPaths ) =
2473
2466
let noMatchesWarn' = noMatchesWarn &&
2474
2467
not (suppressesNoMatchesWarning result)
2475
2468
in case getWarning field glob result of
2476
2469
-- No match: add warning and do no further check
2477
2470
Left w ->
2478
2471
( w : ws
2479
2472
, noMatchesWarn'
2473
+ , changelog1
2480
2474
, wrongPaths
2481
- , docFiles
2482
2475
)
2483
2476
-- Match: check doc files
2484
2477
Right path ->
2485
- let path' = " ." </> path -- HACK? match getDirectoryContents result
2486
- (wrongPaths', docFiles') = checkDoc isDocField path'
2487
- wrongPaths docFiles
2478
+ let (changelog1', wrongPaths') = checkDoc isDocField
2479
+ path
2480
+ changelog1
2481
+ wrongPaths
2488
2482
in
2489
2483
( ws
2490
2484
, noMatchesWarn'
2485
+ , changelog1'
2491
2486
, wrongPaths'
2492
- , docFiles'
2493
2487
)
2494
2488
2495
2489
-- Check whether a path is a desirable doc: if so, check if it is in the
2496
2490
-- field "extra-doc-files" and remove it from the list of paths to check.
2497
2491
checkDoc :: Bool -- Is it "extra-doc-files" ?
2498
2492
-> FilePath -- Path to test
2493
+ -> Bool -- Look for changelog?
2499
2494
-> [FilePath ] -- Previous wrong paths
2500
- -> [FilePath ] -- Remaining paths to check
2501
- -> ([ FilePath ], [ FilePath ]) -- Updated paths
2502
- checkDoc isDocField path wrongFieldPaths docFiles =
2503
- if path `elem` docFiles
2504
- -- Found desirable doc file
2505
- then
2506
- ( if isDocField then wrongFieldPaths else path : wrongFieldPaths
2507
- , delete path docFiles
2508
- )
2509
- -- Not a desirable doc file
2510
- else
2511
- ( wrongFieldPaths
2512
- , docFiles
2513
- )
2495
+ -> ( Bool , [FilePath ]) -- Updated paths
2496
+ checkDoc isDocField path changelog wrongFieldPaths
2497
+ -- Found desirable changelog file
2498
+ | changelog && isDesirableExtraDocFile desirableChangeLog path =
2499
+ ( False
2500
+ , if isDocField
2501
+ then wrongFieldPaths
2502
+ else (root </> path) : wrongFieldPaths
2503
+ )
2504
+ -- Not a desirable doc file
2505
+ | otherwise =
2506
+ ( changelog
2507
+ , wrongFieldPaths
2508
+ )
2514
2509
2515
2510
-- Test whether a file is a desirable documentation for Hackage server
2516
- isDesirableExtraDocFile :: FilePath -> Bool
2517
- isDesirableExtraDocFile fp = map toLower basename `elem` desirable
2511
+ isDesirableExtraDocFile :: [ FilePath ] -> FilePath -> Bool
2512
+ isDesirableExtraDocFile paths fp = map toLower basename `elem` paths
2518
2513
where
2519
2514
(basename, _ext) = splitExtension fp
2520
- desirable =
2521
- [ -- Source: hackage-server/src/Distribution/Server/Packages/Readme.hs
2522
- " readme"
2523
- -- Source: hackage-server/src/Distribution/Server/Packages/ChangeLog.hs
2524
- , " news"
2525
- , " changelog"
2526
- , " change_log"
2527
- , " changes"
2528
- ]
2515
+
2516
+ -- Source: hackage-server/src/Distribution/Server/Packages/ChangeLog.hs
2517
+ desirableChangeLog =
2518
+ [ " news"
2519
+ , " changelog"
2520
+ , " change_log"
2521
+ , " changes"
2522
+ ]
2523
+ -- [TODO] Check readme. Observations:
2524
+ -- • Readme is not necessary if package description is good.
2525
+ -- • Some readmes exists only for repository browsing.
2526
+ -- • There is currently no reliable way to check what a good
2527
+ -- description is; there will be complains if the criterion is
2528
+ -- based on the length or number of words (can of worms).
2529
+ -- -- Source: hackage-server/src/Distribution/Server/Packages/Readme.hs
2530
+ -- desirableReadme = ["readme"]
2529
2531
2530
2532
-- If there's a missing directory in play, since our globs don't
2531
2533
-- (currently) support disjunction, that will always mean there are no
0 commit comments