summaryrefslogtreecommitdiff
path: root/hadrian/src/Rules/Lint.hs
blob: bbecc08c310a0a7ade8eb850b6f116f5acd57c86 (plain)
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
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