ghc 8.91 KB
Newer Older
1 2
import re

3 4 5 6 7
# Testsuite configuration setup for GHC
#
# This file is Python source
#
config.compiler              = 'ghc'
8
config.compiler_always_flags = ghc_compiler_always_flags.split()
9

10
config.haddock               = 'haddock'
dterei's avatar
dterei committed
11 12 13
config.hp2ps                 = 'hp2ps'
config.hpc                   = 'hpc'
config.gs                    = 'gs'
14 15
config.confdir               = '.'

thomie's avatar
thomie committed
16 17 18 19 20
# By default, the 'normal' and 'hpc' ways are enabled. In addition, certain
# ways are enabled automatically if this GHC supports them. Ways that fall in
# this group are 'optasm', 'optllvm', 'profasm', 'threaded1', 'threaded2',
# 'profthreaded', 'ghci', and whichever of 'static/dyn' is not this GHC's
# default mode. Other ways should be set explicitly from .T files.
dterei's avatar
dterei committed
21 22
config.compile_ways       = ['normal', 'hpc']
config.run_ways           = ['normal', 'hpc']
23

krc's avatar
krc committed
24
# ways that are not enabled by default, but can always be invoked explicitly
25
config.other_ways         = ['prof', 'normal_h',
dterei's avatar
dterei committed
26 27
                             'prof_hc_hb','prof_hb',
                             'prof_hd','prof_hy','prof_hr',
28
                             'sanity',
Simon Marlow's avatar
Simon Marlow committed
29
                             'threaded1_ls', 'threaded2_hT', 'debug_numa',
30 31
                             'llvm', 'debugllvm',
                             'profllvm', 'profoptllvm', 'profthreadedllvm',
32
                             'debug',
33
                             'ghci-ext', 'ghci-ext-prof',
34
                             'ext-interp']
krc's avatar
krc committed
35

36
if (ghc_with_native_codegen == 1):
dterei's avatar
dterei committed
37 38
    config.compile_ways.append('optasm')
    config.run_ways.append('optasm')
39

thomie's avatar
thomie committed
40
if config.have_profiling:
41 42
    config.compile_ways.append('profasm')
    config.run_ways.append('profasm')
43

thomie's avatar
thomie committed
44
if config.have_interp:
dterei's avatar
dterei committed
45
    config.run_ways.append('ghci')
46

47
if (ghc_with_threaded_rts == 1):
dterei's avatar
dterei committed
48 49
    config.run_ways.append('threaded1')
    if (ghc_with_smp == 1):
Simon Marlow's avatar
Simon Marlow committed
50
        config.have_smp = True
dterei's avatar
dterei committed
51
        config.run_ways.append('threaded2')
52

53 54 55
if (ghc_with_dynamic_rts == 1):
    config.have_shared_libs = True

thomie's avatar
thomie committed
56
if config.ghc_dynamic_by_default and config.have_vanilla == 1:
57
    config.run_ways.append('static')
58 59 60
else:
    if (ghc_with_dynamic_rts == 1):
        config.run_ways.append('dyn')
61

thomie's avatar
thomie committed
62
if (config.have_profiling and ghc_with_threaded_rts == 1):
dterei's avatar
dterei committed
63
    config.run_ways.append('profthreaded')
64

65
if (ghc_with_llvm == 1 and not config.unregisterised):
dterei's avatar
dterei committed
66
    config.compile_ways.append('optllvm')
dterei's avatar
dterei committed
67
    config.run_ways.append('optllvm')
68

thomie's avatar
thomie committed
69
config.way_flags = {
dterei's avatar
dterei committed
70
    'normal'       : [],
71
    'normal_h'     : [],
dterei's avatar
dterei committed
72
    'g1'           : [],
Simon Marlow's avatar
Simon Marlow committed
73 74
    'nursery_chunks' : [],
    'debug_numa'   : ['-threaded', '-debug'],
75
    'optasm'       : ['-O', '-fasm'],
dterei's avatar
dterei committed
76
    'llvm'         : ['-fllvm'],
77
    'optllvm'      : ['-O', '-fllvm'],
dterei's avatar
dterei committed
78
    'debugllvm'    : ['-fllvm', '-keep-llvm-files'],
79
    'prof'         : ['-prof', '-static', '-fprof-auto', '-fasm'],
80
    'prof_no_auto' : ['-prof', '-static', '-fasm'],
81 82
    'profasm'      : ['-O', '-prof', '-static', '-fprof-auto'],
    'profthreaded' : ['-O', '-prof', '-static', '-fprof-auto', '-threaded'],
83
    'ghci'         : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '-fghci-leak-check', '+RTS', '-I0.1', '-RTS'],
84
    'sanity'       : ['-debug'],
dterei's avatar
dterei committed
85 86 87 88
    'threaded1'    : ['-threaded', '-debug'],
    'threaded1_ls' : ['-threaded', '-debug'],
    'threaded2'    : ['-O', '-threaded', '-eventlog'],
    'threaded2_hT' : ['-O', '-threaded'],
thomie's avatar
thomie committed
89
    'hpc'          : ['-O', '-fhpc'],
90 91 92 93 94
    'prof_hc_hb'   : ['-O', '-prof', '-static', '-fprof-auto'],
    'prof_hb'      : ['-O', '-prof', '-static', '-fprof-auto'],
    'prof_hd'      : ['-O', '-prof', '-static', '-fprof-auto'],
    'prof_hy'      : ['-O', '-prof', '-static', '-fprof-auto'],
    'prof_hr'      : ['-O', '-prof', '-static', '-fprof-auto'],
95
    'dyn'          : ['-O', '-dynamic'],
96
    'static'       : ['-O', '-static'],
97
    'debug'        : ['-O', '-g', '-dannot-lint'],
98
    # llvm variants...
99 100 101
    'profllvm'         : ['-prof', '-static', '-fprof-auto', '-fllvm'],
    'profoptllvm'      : ['-O', '-prof', '-static', '-fprof-auto', '-fllvm'],
    'profthreadedllvm' : ['-O', '-prof', '-static', '-fprof-auto', '-threaded', '-fllvm'],
thomie's avatar
thomie committed
102
    'ghci-ext'         : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '-fexternal-interpreter', '+RTS', '-I0.1', '-RTS'],
103
    'ghci-ext-prof'    : ['--interactive', '-v0', '-ignore-dot-ghci', '-fno-ghci-history', '-fexternal-interpreter', '-prof', '+RTS', '-I0.1', '-RTS'],
104
    'ext-interp' : ['-fexternal-interpreter'],
dterei's avatar
dterei committed
105
   }
106

107
config.way_rts_flags = {
dterei's avatar
dterei committed
108
    'normal'       : [],
109
    'normal_h'     : ['-h'], # works without -prof
dterei's avatar
dterei committed
110
    'g1'           : ['-G1'],
Simon Marlow's avatar
Simon Marlow committed
111 112
    'nursery_chunks' : ['-n32k'],
    'debug_numa'   : ['-N2', '--debug-numa=2'],
dterei's avatar
dterei committed
113 114 115 116
    'optasm'       : [],
    'llvm'         : [],
    'optllvm'      : [],
    'debugllvm'    : [],
117
    'prof'         : ['-p'],
118
    'prof_no_auto' : ['-p'],
119
    'profasm'      : ['-hc', '-p'], # test heap profiling too
dterei's avatar
dterei committed
120 121
    'profthreaded' : ['-p'],
    'ghci'         : [],
122
    'sanity'       : ['-DS'],
dterei's avatar
dterei committed
123 124 125 126 127 128 129 130 131 132
    'threaded1'    : [],
    'threaded1_ls' : ['-ls'],
    'threaded2'    : ['-N2 -ls'],
    'threaded2_hT' : ['-N2', '-hT'],
    'hpc'          : [],
    'prof_hc_hb'   : ['-hc -hbvoid'],
    'prof_hb'      : ['-hb'],
    'prof_hd'      : ['-hd'],
    'prof_hy'      : ['-hy'],
    'prof_hr'      : ['-hr'],
133
    'dyn'          : [],
134
    'static'       : [],
135
    'debug'        : [],
136 137 138 139
    # llvm variants...
    'profllvm'         : ['-p'],
    'profoptllvm'      : ['-hc', '-p'],
    'profthreadedllvm' : ['-p'],
140
    'ghci-ext'         : [],
141
    'ghci-ext-prof'    : [],
142
    'ext-interp'       : [],
dterei's avatar
dterei committed
143
   }
144

145
# Useful classes of ways that can be used with only_ways(), omit_ways() and
146
# expect_broken_for().
147

thomie's avatar
thomie committed
148
prof_ways     = [x[0] for x in config.way_flags.items()
149
                      if '-prof' in x[1]]
150

thomie's avatar
thomie committed
151
threaded_ways = [x[0] for x in config.way_flags.items()
152
                      if '-threaded' in x[1] or 'ghci' == x[0]]
153

thomie's avatar
thomie committed
154
opt_ways      = [x[0] for x in config.way_flags.items()
155
                      if '-O' in x[1]]
rwbarton's avatar
rwbarton committed
156

thomie's avatar
thomie committed
157
llvm_ways     = [x[0] for x in config.way_flags.items()
158
                      if '-fflvm' in x[1]]
159

160
def get_compiler_info():
161
    s = getStdout([config.compiler, '--info']).decode('utf8')
162
    s = re.sub('[\r\n]', '', s)
163
    compilerInfoDict = dict(eval(s))
164
    s = getStdout([config.compiler, '+RTS', '--info']).decode('utf8')
165
    s = re.sub('[\r\n]', '', s)
166 167
    rtsInfoDict = dict(eval(s))

168
    # external interpreter needs RTS linker support
169 170 171 172
    # If the field is not present (GHC 8.0 and earlier), assume we don't
    # have -fexternal-interpreter (though GHC 8.0 actually does)
    # so we can still run most tests.
    config.have_ext_interp = compilerInfoDict.get("target has RTS linker", "NO") == "YES"
173

174 175
    # See Note [Replacing backward slashes in config.libdir].
    config.libdir = compilerInfoDict['LibDir'].replace('\\', '/')
176

177 178 179 180 181
    if re.match(".*_p(_.*|$)", rtsInfoDict["RTS way"]):
        config.compiler_profiled = True
    else:
        config.compiler_profiled = False

182
    try:
dterei's avatar
dterei committed
183
        config.package_conf_cache_file = compilerInfoDict["Global Package DB"] + '/package.cache'
184
    except:
dterei's avatar
dterei committed
185
        config.package_conf_cache_file = ''
dterei's avatar
dterei committed
186

187
    # See Note [WayFlags]
thomie's avatar
thomie committed
188
    if config.ghc_dynamic:
ian@well-typed.com's avatar
ian@well-typed.com committed
189 190
        config.ghc_th_way_flags = "-dynamic"
        config.ghci_way_flags   = "-dynamic"
191
        config.plugin_way_flags = "-dynamic"
ian@well-typed.com's avatar
ian@well-typed.com committed
192 193
        config.ghc_th_way       = "dyn"
        config.ghc_plugin_way   = "dyn"
194 195 196
    elif config.compiler_profiled:
        config.ghc_th_way_flags = "-prof"
        config.ghci_way_flags   = "-prof"
197
        config.plugin_way_flags = "-prof"
198 199
        config.ghc_th_way       = "prof"
        config.ghc_plugin_way   = "prof"
200
    else:
ian@well-typed.com's avatar
ian@well-typed.com committed
201 202
        config.ghc_th_way_flags = "-static"
        config.ghci_way_flags   = "-static"
203
        config.plugin_way_flags = "-static"
204
        config.ghc_th_way       = "normal"
ian@well-typed.com's avatar
ian@well-typed.com committed
205
        config.ghc_plugin_way   = "normal"
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231

# Note [Replacing backward slashes in config.libdir]
# 
# We *do* need to replace backslashes in config.libdir, for the following
# reason:
#
# * Tests use config.libdir as follows:
#
#     extra_run_opts('"' + config.libdir + '"')
#
#   The double quotes are there because config.libdir might contain
#   spaces.
#
# * This string is then written /as is/ to <testname>.genscript in
#   testlib.interpreter_run:
#
#     script.write(':set args ' + opts.extra_run_opts + '\n')
#
# * But GHCi expects the arguments to ':set args' to be proper Haskell
#   strings (when they are quoted), with backslashes escaped. Since
#   config.libdir contains single backslash characters, tests such as T5313
#   will fail for WAY=ghci with "Pattern match failure in do expression".
#
# Arguably the above code for writing `:set args` should be smarter. This
# is tricky to get right though, because in GHCI `:set args foo\bar` (no
# double quotes) works perfectly fine, and is interpreted as the Haskell
Gabor Greif's avatar
Gabor Greif committed
232
# string "foo\\bar". Therefore, simply escaping all backward slashes in
233 234 235 236 237
# opts.extra_run_opts before concatenating it with ':set args' is not right
# either.
#
# Replacing backslashes to forward slashes in config.libdir works around the
# problem.