-
Notifications
You must be signed in to change notification settings - Fork 691
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Naive implementation of 'cabal check'
A naive implementation of 'cabal check'. It will list the errors and warnings as implemented by Cabal, yielding them in groups of severity. Currently ignores verbosity levels, no additional arguments are understood. This addresses ticket #211.
- Loading branch information
Showing
3 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Hackage.Check | ||
-- Copyright : (c) Lennart Kolmodin 2008 | ||
-- License : BSD-like | ||
-- | ||
-- Maintainer : kolmodin@haskell.org | ||
-- Stability : provisional | ||
-- Portability : portable | ||
-- | ||
-- Check a package for common mistakes | ||
-- | ||
----------------------------------------------------------------------------- | ||
module Hackage.Check ( | ||
check | ||
) where | ||
|
||
import Control.Monad ( unless ) | ||
|
||
import Distribution.PackageDescription.Parse ( readPackageDescription ) | ||
import Distribution.PackageDescription.Check | ||
import Distribution.PackageDescription.Configuration ( flattenPackageDescription ) | ||
import Distribution.Verbosity ( Verbosity ) | ||
import Distribution.Simple.Utils ( defaultPackageDesc ) | ||
|
||
check :: Verbosity -> IO () | ||
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 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:" | ||
mapM_ (putStrLn . explanation) buildImpossible | ||
putStrLn "" | ||
|
||
unless (null buildWarning) $ do | ||
putStrLn "The following warnings are likely affect your build negatively:" | ||
mapM_ (putStrLn . explanation) buildWarning | ||
putStrLn "" | ||
|
||
unless (null distSuspicious) $ do | ||
putStrLn "These warnings may cause trouble when distribution the package:" | ||
mapM_ (putStrLn . explanation) distSuspicious | ||
putStrLn "" | ||
|
||
unless (null distInexusable) $ do | ||
putStrLn "The following errors will cause portability problems on other environments:" | ||
mapM_ (putStrLn . explanation) distInexusable | ||
putStrLn "" | ||
|
||
let isDistError (PackageDistSuspicious {}) = False | ||
isDistError _ = True | ||
errors = filter isDistError packageChecks | ||
|
||
unless (null errors) $ do | ||
putStrLn "Hackage would reject this package." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters