Skip to content

Commit 20b9357

Browse files
Capture error message when building C files
Add a new exception `CompileError` to differtiate that the exception raised during the compilation. Signed-off-by: Gabor Mezei <[email protected]>
1 parent ac4c133 commit 20b9357

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/mbedtls_framework/c_build_helper.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
import sys
1212
import tempfile
1313

14+
class CompileError(Exception):
15+
"""Excetion to represent an error during the compilation."""
16+
17+
def __init__(self, message):
18+
"""Save the error massage"""
19+
20+
super().__init__()
21+
self.message = message
22+
1423
def remove_file_if_exists(filename):
1524
"""Remove the specified file, ignoring errors."""
1625
if not filename:
@@ -107,7 +116,13 @@ def compile_c_file(c_filename, exe_filename, include_dirs):
107116
else:
108117
cmd += ['-o' + exe_filename]
109118

110-
subprocess.check_call(cmd + [c_filename])
119+
try:
120+
subprocess.check_output(cmd + [c_filename],
121+
stderr=subprocess.PIPE,
122+
universal_newlines=True)
123+
124+
except subprocess.CalledProcessError as e:
125+
raise CompileError(e.stderr) from e
111126

112127
def get_c_expression_values(
113128
cast_to, printf_format,

0 commit comments

Comments
 (0)