Skip to content

Commit a5ac374

Browse files
authored
[mypyc] Support --junit-xml (#7942)
1 parent 9453f5f commit a5ac374

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

mypyc/build.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from mypy.options import Options
3333
from mypy.build import BuildSource
3434
from mypy.fscache import FileSystemCache
35+
from mypy.util import write_junit_xml
3536

3637
from mypyc.namegen import exported_name
3738
from mypyc.options import CompilerOptions
@@ -166,7 +167,7 @@ def generate_c(sources: List[BuildSource],
166167
options: Options,
167168
groups: emitmodule.Groups,
168169
fscache: FileSystemCache,
169-
compiler_options: Optional[CompilerOptions] = None
170+
compiler_options: CompilerOptions,
170171
) -> Tuple[List[List[Tuple[str, str]]], str]:
171172
"""Drive the actual core compilation step.
172173
@@ -176,36 +177,49 @@ def generate_c(sources: List[BuildSource],
176177
177178
Returns the C source code and (for debugging) the pretty printed IR.
178179
"""
179-
compiler_options = compiler_options or CompilerOptions()
180+
t0 = time.time()
180181

181182
# Do the actual work now
182-
t0 = time.time()
183+
serious = False
184+
result = None
183185
try:
184186
result = emitmodule.parse_and_typecheck(
185187
sources, options, compiler_options, groups, fscache)
188+
messages = result.errors
186189
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
190193

191194
t1 = time.time()
192195
if compiler_options.verbose:
193196
print("Parsed and typechecked in {:.3f}s".format(t1 - t0))
194197

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)
196202

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())
204205

205206
t2 = time.time()
206207
if compiler_options.verbose:
207208
print("Compiled to C in {:.3f}s".format(t2 - t1))
208209

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+
209223
return ctext, '\n'.join(format_modules(modules))
210224

211225

mypyc/errors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List
2+
13
import mypy.errors
24

35

@@ -15,6 +17,9 @@ def warning(self, msg: str, path: str, line: int) -> None:
1517
self._errors.report(line, None, msg, severity='warning', file=path)
1618
self.num_warnings += 1
1719

20+
def new_messages(self) -> List[str]:
21+
return self._errors.new_messages()
22+
1823
def flush_errors(self) -> None:
19-
for error in self._errors.new_messages():
24+
for error in self.new_messages():
2025
print(error)

0 commit comments

Comments
 (0)