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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
module Rules.Lint
( lintRules
) where
import Base
import Settings.Builders.Common
import System.Directory (findExecutable)
import System.Exit (exitFailure)
lintRules :: Rules ()
lintRules = do
root <- buildRootRules
"lint:base" ~> lint base
"lint:compiler" ~> lint compiler
"libraries" -/- "base" -/- "include" -/- "HsBaseConfig.h" %> \_ ->
-- ./configure is called here manually because we need to generate
-- HsBaseConfig.h, which is created from HsBaseConfig.h.in. ./configure
-- is usually run by Cabal which generates this file but if we do that
-- then hadrian thinks it needs to build the stage0 compiler before
-- attempting to configure. Therefore we just run it directly here.
cmd_ (Cwd "libraries/base") "./configure"
lint :: Action () -> Action ()
lint lintAction = do
isHlintPresent <- isJust <$> liftIO (findExecutable "hlint")
if isHlintPresent
then do
putBuild "| Running the linter…"
lintAction
putSuccess "| Done."
else do
putFailure "| Please make sure you have the `hlint` executable in your $PATH"
liftIO exitFailure
runHLint :: [FilePath] -- ^ include directories
-> [String] -- ^ CPP defines
-> FilePath
-> Action ()
runHLint includeDirs defines dir = do
threads <- shakeThreads <$> getShakeOptions
hostArch <- (<> "_HOST_ARCH") <$> setting HostArch
let hlintYaml = dir </> ".hlint.yaml"
defines' = hostArch : defines
cmdLine = unwords $
[ "hlint"
, "--colour=never"
, "-j" <> show threads
] ++
map ("--cpp-define=" <>) defines' ++
map ("--cpp-include=" <>) includeDirs ++
[ "-h" <> hlintYaml
, dir
]
putBuild $ "| " <> cmdLine
cmd_ cmdLine
base :: Action ()
base = do
buildDir <- buildRoot
let stage1RtsInc = buildDir </> "stage1/rts/build/include"
let machDeps = "rts/include/MachDeps.h"
let ghcautoconf = stage1RtsInc </> "ghcautoconf.h"
let ghcplatform = stage1RtsInc </> "ghcplatform.h"
need [ghcautoconf, ghcplatform, machDeps, "libraries/base/include/HsBaseConfig.h"]
let includeDirs =
[ "rts/include"
, "libraries/base/include"
, stage1RtsInc
]
runHLint includeDirs [] "libraries/base"
compiler :: Action ()
compiler = do
buildDir <- buildRoot
let stage1RtsInc = buildDir </> "stage1/rts/build/include"
let stage1Compiler = buildDir </> "stage1/compiler/build"
let machDeps = "rts/include/MachDeps.h"
let compilerDir = "compiler"
let ghcautoconf = stage1RtsInc </> "ghcautoconf.h"
let ghcplatform = stage1RtsInc </> "ghcplatform.h"
need $ mconcat [[ghcautoconf, ghcplatform], hsIncls stage1Compiler, [machDeps]]
let includeDirs =
[ stage1RtsInc
, compilerDir
, ghcplatform
, stage1Compiler
]
runHLint includeDirs [] "compiler"
hsIncls :: FilePath -> [FilePath]
hsIncls path = [ path </> "primop-vector-tycons.hs-incl"
, path </> "primop-vector-tys.hs-incl"
, path </> "primop-vector-tys-exports.hs-incl"
, path </> "primop-code-size.hs-incl"
, path </> "primop-vector-uniques.hs-incl"
, path </> "primop-data-decl.hs-incl"
, path </> "primop-tag.hs-incl"
, path </> "primop-list.hs-incl"
, path </> "primop-strictness.hs-incl"
, path </> "primop-fixity.hs-incl"
, path </> "primop-docs.hs-incl"
, path </> "primop-primop-info.hs-incl"
, path </> "primop-out-of-line.hs-incl"
, path </> "primop-has-side-effects.hs-incl"
, path </> "primop-can-fail.hs-incl"
, path </> "primop-commutable.hs-incl"
]
|