diff options
author | Hécate <hecate+gitlab@glitchbra.in> | 2020-07-06 01:32:15 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-18 07:26:43 -0400 |
commit | e6cf27dfded59fe42bd6be323573c0d576e6204a (patch) | |
tree | cac89a332670a602871071e1983d3275320e4ce2 /hadrian/src/Rules | |
parent | 6ba6a881c58459008f02fb4816f8dec2800c2b73 (diff) | |
download | haskell-e6cf27dfded59fe42bd6be323573c0d576e6204a.tar.gz |
Add a Lint hadrian rule and an .hlint.yaml file in base/
Diffstat (limited to 'hadrian/src/Rules')
-rw-r--r-- | hadrian/src/Rules/Lint.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/hadrian/src/Rules/Lint.hs b/hadrian/src/Rules/Lint.hs new file mode 100644 index 0000000000..bbecc08c31 --- /dev/null +++ b/hadrian/src/Rules/Lint.hs @@ -0,0 +1,45 @@ +module Rules.Lint + ( lintRules + ) where + +import Base +import Settings.Builders.Common +import System.Directory (findExecutable) + +lintRules :: Rules () +lintRules = "lint" ~> lint + +lint :: Action () +lint = do + isHlintPresent <- isJust <$> (liftIO $ findExecutable "hlint") + if isHlintPresent + then do + putBuild "| Running the linter…" + lintBase + putSuccess "| Done." + else + putFailure "| Please make sure you have the `hlint` executable in your $PATH" + +lintBase :: Action () +lintBase = do + topDir <- topDirectory + buildDir <- buildRoot + let stage1Lib = topDir </> buildDir </> "stage1/lib" + let machDeps = topDir </> "includes/MachDeps.h" + let hsBaseConfig = topDir </> buildDir </> "stage1/libraries/base/build/include/HsBaseConfig.h" + let ghcautoconf = stage1Lib </> "ghcautoconf.h" + let ghcplatform = stage1Lib </> "ghcplatform.h" + need [ghcautoconf, ghcplatform, machDeps, hsBaseConfig] + let include0 = topDir </> "includes" + let include1 = topDir </> "libraries/base/include" + let include2 = stage1Lib + let include3 = topDir </> buildDir </> "stage1/libraries/base/build/include" + let hlintYaml = topDir </> "libraries/base/.hlint.yaml" + hostArch <- (<> "_HOST_ARCH") <$> setting HostArch + let cmdLine = "hlint -j --cpp-define " <> hostArch <> " --cpp-include=" <> include0 <> + " --cpp-include=" <> include1 <> + " --cpp-include=" <> include2 <> + " --cpp-include=" <> include3 <> + " -h " <> hlintYaml <> " libraries/base" + putBuild $ "| " <> cmdLine + cmd_ cmdLine |