summaryrefslogtreecommitdiff
path: root/hadrian/src
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-02-18 17:27:32 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-02-24 20:25:06 -0500
commit6555b68ca0678827b89c5624db071f5a485d18b7 (patch)
tree9dbcd231add48a179d7751606523865029d2fc1a /hadrian/src
parent06c18990fb6f10aaf1907ba8f0fe3f1a138da159 (diff)
downloadhaskell-6555b68ca0678827b89c5624db071f5a485d18b7.tar.gz
Move linters into the tree
This MR moves the GHC linters into the tree, so that they can be run directly using Hadrian. * Query all files tracked by Git instead of using changed files, so that we can run the exact same linting step locally and in a merge request. * Only check that the changelogs don't contain TBA when RELEASE=YES. * Add hadrian/lint script, which runs all the linting steps. * Ensure the hlint job exits with a failure if hlint is not installed (otherwise we were ignoring the failure). Given that hlint doesn't seem to be available in CI at the moment, I've temporarily allowed failure in the hlint job. * Run all linting tests in CI using hadrian.
Diffstat (limited to 'hadrian/src')
-rw-r--r--hadrian/src/Packages.hs29
-rw-r--r--hadrian/src/Rules/Docspec.hs4
-rw-r--r--hadrian/src/Rules/Lint.hs4
-rw-r--r--hadrian/src/Rules/Test.hs18
-rw-r--r--hadrian/src/Settings/Default.hs6
5 files changed, 50 insertions, 11 deletions
diff --git a/hadrian/src/Packages.hs b/hadrian/src/Packages.hs
index a44e3cd95e..9ca18f14c3 100644
--- a/hadrian/src/Packages.hs
+++ b/hadrian/src/Packages.hs
@@ -9,7 +9,9 @@ module Packages (
hsc2hs, hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, iservProxy,
libffi, libiserv, mtl, parsec, pretty, primitive, process, remoteIserv, rts,
runGhc, stm, templateHaskell, terminfo, text, time, timeout, touchy,
- transformers, unlit, unix, win32, xhtml, noteLinter, ghcPackages, isGhcPackage,
+ transformers, unlit, unix, win32, xhtml,
+ lintersCommon, lintNotes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace,
+ ghcPackages, isGhcPackage,
-- * Package information
programName, nonHsMainPackage, autogenPath, programPath, timeoutPath,
@@ -39,13 +41,25 @@ ghcPackages =
, hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, libffi, libiserv, mtl
, parsec, pretty, process, rts, runGhc, stm, templateHaskell
, terminfo, text, time, touchy, transformers, unlit, unix, win32, xhtml
- , timeout, noteLinter ]
+ , timeout
+ , lintersCommon
+ , lintNotes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace ]
-- TODO: Optimise by switching to sets of packages.
isGhcPackage :: Package -> Bool
isGhcPackage = (`elem` ghcPackages)
-- | Package definitions, see 'Package'.
+array, base, binary, bytestring, cabalSyntax, cabal, checkPpr, checkExact, countDeps,
+ compareSizes, compiler, containers, deepseq, deriveConstants, directory,
+ exceptions, filepath, genapply, genprimopcode, ghc, ghcBignum, ghcBoot, ghcBootTh,
+ ghcCompact, ghcHeap, ghci, ghciWrapper, ghcPkg, ghcPrim, haddock, haskeline, hsc2hs,
+ hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, iservProxy, remoteIserv, libffi, libiserv, mtl,
+ parsec, pretty, primitive, process, rts, runGhc, stm, templateHaskell,
+ terminfo, text, time, touchy, transformers, unlit, unix, win32, xhtml,
+ timeout,
+ lintersCommon, lintNotes, lintCommitMsg, lintSubmoduleRefs, lintWhitespace
+ :: Package
array = lib "array"
base = lib "base"
binary = lib "binary"
@@ -108,7 +122,12 @@ unlit = util "unlit"
unix = lib "unix"
win32 = lib "Win32"
xhtml = lib "xhtml"
-noteLinter = prg "notes-util" `setPath` "utils/notes-util"
+
+lintersCommon = lib "linters-common" `setPath` "linters/linters-common"
+lintNotes = linter "lint-notes"
+lintCommitMsg = linter "lint-commit-msg"
+lintSubmoduleRefs = linter "lint-submodule-refs"
+lintWhitespace = linter "lint-whitespace"
-- | Construct a library package, e.g. @array@.
lib :: PackageName -> Package
@@ -126,6 +145,10 @@ prg name = program name name
util :: PackageName -> Package
util name = program name ("utils" -/- name)
+-- | Construct a linter executable program (lives in the \"linters\" subdirectory).
+linter :: PackageName -> Package
+linter name = program name ("linters" -/- name)
+
-- | Amend a package path if it doesn't conform to a typical pattern.
setPath :: Package -> FilePath -> Package
setPath pkg path = pkg { pkgPath = path }
diff --git a/hadrian/src/Rules/Docspec.hs b/hadrian/src/Rules/Docspec.hs
index 69b49a1cc5..30f6a039eb 100644
--- a/hadrian/src/Rules/Docspec.hs
+++ b/hadrian/src/Rules/Docspec.hs
@@ -8,6 +8,7 @@ import Base
import Context.Path
import Settings.Builders.Common
import qualified Packages as P
+import System.Exit (exitFailure)
docspecRules :: Rules ()
docspecRules = do
@@ -21,8 +22,9 @@ docspec lintAction = do
putBuild "| Running cabal-docspec…"
lintAction
putSuccess "| Done."
- else
+ else do
putFailure "| Please make sure you have the `cabal-docspec` executable in your $PATH"
+ liftIO exitFailure
base :: Action ()
base = do
diff --git a/hadrian/src/Rules/Lint.hs b/hadrian/src/Rules/Lint.hs
index bb7df1687a..58f9715f21 100644
--- a/hadrian/src/Rules/Lint.hs
+++ b/hadrian/src/Rules/Lint.hs
@@ -5,6 +5,7 @@ module Rules.Lint
import Base
import Settings.Builders.Common
import System.Directory (findExecutable)
+import System.Exit (exitFailure)
lintRules :: Rules ()
lintRules = do
@@ -19,8 +20,9 @@ lint lintAction = do
putBuild "| Running the linter…"
lintAction
putSuccess "| Done."
- else
+ else do
putFailure "| Please make sure you have the `hlint` executable in your $PATH"
+ liftIO exitFailure
runHLint :: [FilePath] -- ^ include directories
-> [String] -- ^ CPP defines
diff --git a/hadrian/src/Rules/Test.hs b/hadrian/src/Rules/Test.hs
index fe0aba04cc..4b0ba4a913 100644
--- a/hadrian/src/Rules/Test.hs
+++ b/hadrian/src/Rules/Test.hs
@@ -44,17 +44,24 @@ countDepsExtra :: Maybe String
countDepsExtra = Just "-iutils/count-deps"
noteLinterProgPath, noteLinterSourcePath :: FilePath
-noteLinterProgPath = "test/bin/notes-util" <.> exe
-noteLinterSourcePath = "utils/notes-util/Main.hs"
+noteLinterProgPath = "test/bin/lint-notes" <.> exe
+noteLinterSourcePath = "linters/lint-notes/Main.hs"
noteLinterExtra :: Maybe String
-noteLinterExtra = Just "-iutils/notes-util"
+noteLinterExtra = Just "-ilinters/lint-notes"
+
+whitespaceLinterProgPath, whitespaceLinterSourcePath :: FilePath
+whitespaceLinterProgPath = "test/bin/lint-whitespace" <.> exe
+whitespaceLinterSourcePath = "linters/lint-whitespace/Main.hs"
+whitespaceLinterExtra :: Maybe String
+whitespaceLinterExtra = Just "-ilinters/lint-whitespace"
checkPrograms :: [(String,FilePath, FilePath, Maybe String, Package, Stage -> Stage)]
checkPrograms =
[ ("test:check-ppr",checkPprProgPath, checkPprSourcePath, checkPprExtra, checkPpr, id)
, ("test:check-exact",checkExactProgPath, checkExactSourcePath, checkExactExtra, checkExact, id)
, ("test:count-deps",countDepsProgPath, countDepsSourcePath, countDepsExtra, countDeps, id)
- , ("lint:notes-util", noteLinterProgPath, noteLinterSourcePath, noteLinterExtra, noteLinter, const Stage0)
+ , ("lint:notes", noteLinterProgPath, noteLinterSourcePath, noteLinterExtra, lintNotes, const Stage0)
+ , ("lint:whitespace", whitespaceLinterProgPath, whitespaceLinterSourcePath, whitespaceLinterExtra, lintWhitespace, const Stage0)
]
inTreeOutTree :: (Stage -> Action b) -> Action b -> Action b
@@ -213,7 +220,8 @@ testRules = do
setEnv "CHECK_PPR" (top -/- root -/- checkPprProgPath)
setEnv "CHECK_EXACT" (top -/- root -/- checkExactProgPath)
setEnv "COUNT_DEPS" (top -/- root -/- countDepsProgPath)
- setEnv "NOTES_UTIL" (top -/- root -/- noteLinterProgPath)
+ setEnv "LINT_NOTES" (top -/- root -/- noteLinterProgPath)
+ setEnv "LINT_WHITESPACE" (top -/- root -/- whitespaceLinterProgPath)
-- This lets us bypass the need to generate a config
-- through Make, which happens in testsuite/mk/boilerplate.mk
diff --git a/hadrian/src/Settings/Default.hs b/hadrian/src/Settings/Default.hs
index 8c490347b9..21ab008cb7 100644
--- a/hadrian/src/Settings/Default.hs
+++ b/hadrian/src/Settings/Default.hs
@@ -87,7 +87,11 @@ stage0Packages = do
, text
, transformers
, unlit
- , noteLinter
+ , lintersCommon
+ , lintNotes
+ , lintCommitMsg
+ , lintSubmoduleRefs
+ , lintWhitespace
]
++ [ terminfo | not windowsHost, not cross ]
++ [ timeout | windowsHost ]