32
32
from mypy .options import Options
33
33
from mypy .build import BuildSource
34
34
from mypy .fscache import FileSystemCache
35
+ from mypy .util import write_junit_xml
35
36
36
37
from mypyc .namegen import exported_name
37
38
from mypyc .options import CompilerOptions
@@ -166,7 +167,7 @@ def generate_c(sources: List[BuildSource],
166
167
options : Options ,
167
168
groups : emitmodule .Groups ,
168
169
fscache : FileSystemCache ,
169
- compiler_options : Optional [ CompilerOptions ] = None
170
+ compiler_options : CompilerOptions ,
170
171
) -> Tuple [List [List [Tuple [str , str ]]], str ]:
171
172
"""Drive the actual core compilation step.
172
173
@@ -176,36 +177,49 @@ def generate_c(sources: List[BuildSource],
176
177
177
178
Returns the C source code and (for debugging) the pretty printed IR.
178
179
"""
179
- compiler_options = compiler_options or CompilerOptions ()
180
+ t0 = time . time ()
180
181
181
182
# Do the actual work now
182
- t0 = time .time ()
183
+ serious = False
184
+ result = None
183
185
try :
184
186
result = emitmodule .parse_and_typecheck (
185
187
sources , options , compiler_options , groups , fscache )
188
+ messages = result .errors
186
189
except CompileError as e :
187
- for line in e .messages :
188
- print ( line )
189
- fail ( 'Typechecking failure' )
190
+ messages = e .messages
191
+ if not e . use_stdout :
192
+ serious = True
190
193
191
194
t1 = time .time ()
192
195
if compiler_options .verbose :
193
196
print ("Parsed and typechecked in {:.3f}s" .format (t1 - t0 ))
194
197
195
- errors = Errors ()
198
+ if not messages and result :
199
+ errors = Errors ()
200
+ modules , ctext = emitmodule .compile_modules_to_c (
201
+ result , compiler_options = compiler_options , errors = errors , groups = groups )
196
202
197
- modules , ctext = emitmodule .compile_modules_to_c (result ,
198
- compiler_options = compiler_options ,
199
- errors = errors ,
200
- groups = groups )
201
- if errors .num_errors :
202
- errors .flush_errors ()
203
- sys .exit (1 )
203
+ if errors .num_errors :
204
+ messages .extend (errors .new_messages ())
204
205
205
206
t2 = time .time ()
206
207
if compiler_options .verbose :
207
208
print ("Compiled to C in {:.3f}s" .format (t2 - t1 ))
208
209
210
+ # ... you know, just in case.
211
+ if options .junit_xml :
212
+ py_version = "{}_{}" .format (
213
+ options .python_version [0 ], options .python_version [1 ]
214
+ )
215
+ write_junit_xml (
216
+ t2 - t0 , serious , messages , options .junit_xml , py_version , options .platform
217
+ )
218
+
219
+ if messages :
220
+ print ("\n " .join (messages ))
221
+ sys .exit (1 )
222
+
209
223
return ctext , '\n ' .join (format_modules (modules ))
210
224
211
225
0 commit comments