1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.Client.Check
-- Copyright : (c) Lennart Kolmodin 2008
-- License : BSD-like
--
-- Maintainer : kolmodin@haskell.org
-- Stability : provisional
-- Portability : portable
--
-- Check a package for common mistakes
--
-----------------------------------------------------------------------------
module Distribution.Client.Check (
check
) where
import Control.Monad ( when, unless )
import Distribution.PackageDescription.Parse
( readPackageDescription )
import Distribution.PackageDescription.Check
import Distribution.PackageDescription.Configuration
( flattenPackageDescription )
import Distribution.Verbosity
( Verbosity )
import Distribution.Simple.Utils
( defaultPackageDesc, toUTF8, wrapText )
check :: Verbosity -> IO Bool
check verbosity = do
pdfile <- defaultPackageDesc verbosity
ppd <- readPackageDescription verbosity pdfile
-- flatten the generic package description into a regular package
-- description
-- TODO: this may give more warnings than it should give;
-- consider two branches of a condition, one saying
-- ghc-options: -Wall
-- and the other
-- ghc-options: -Werror
-- joined into
-- ghc-options: -Wall -Werror
-- checkPackages will yield a warning on the last line, but it
-- would not on each individual branch.
-- Hovever, this is the same way hackage does it, so we will yield
-- the exact same errors as it will.
let pkg_desc = flattenPackageDescription ppd
ioChecks <- checkPackageFiles pkg_desc "."
let packageChecks = ioChecks ++ checkPackage ppd (Just pkg_desc)
buildImpossible = [ x | x@PackageBuildImpossible {} <- packageChecks ]
buildWarning = [ x | x@PackageBuildWarning {} <- packageChecks ]
distSuspicious = [ x | x@PackageDistSuspicious {} <- packageChecks ]
distInexusable = [ x | x@PackageDistInexcusable {} <- packageChecks ]
unless (null buildImpossible) $ do
putStrLn "The package will not build sanely due to these errors:"
printCheckMessages buildImpossible
unless (null buildWarning) $ do
putStrLn "The following warnings are likely affect your build negatively:"
printCheckMessages buildWarning
unless (null distSuspicious) $ do
putStrLn "These warnings may cause trouble when distributing the package:"
printCheckMessages distSuspicious
unless (null distInexusable) $ do
putStrLn "The following errors will cause portability problems on other environments:"
printCheckMessages distInexusable
let isDistError (PackageDistSuspicious {}) = False
isDistError _ = True
errors = filter isDistError packageChecks
unless (null errors) $
putStrLn "Hackage would reject this package."
when (null packageChecks) $
putStrLn "No errors or warnings could be found in the package."
return (null packageChecks)
where
printCheckMessages = mapM_ (putStrLn . format . explanation)
format = toUTF8 . wrapText . ("* "++)
|