Skip to content

Commit

Permalink
Capture error message when building C files
Browse files Browse the repository at this point in the history
Add a new exception `CompileError` to differtiate that the exception raised
during the compilation.

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
  • Loading branch information
gabor-mezei-arm committed Sep 19, 2024
1 parent ac4c133 commit 20b9357
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scripts/mbedtls_framework/c_build_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
import sys
import tempfile

class CompileError(Exception):
"""Excetion to represent an error during the compilation."""

def __init__(self, message):
"""Save the error massage"""

super().__init__()
self.message = message

def remove_file_if_exists(filename):
"""Remove the specified file, ignoring errors."""
if not filename:
Expand Down Expand Up @@ -107,7 +116,13 @@ def compile_c_file(c_filename, exe_filename, include_dirs):
else:
cmd += ['-o' + exe_filename]

subprocess.check_call(cmd + [c_filename])
try:
subprocess.check_output(cmd + [c_filename],
stderr=subprocess.PIPE,
universal_newlines=True)

except subprocess.CalledProcessError as e:
raise CompileError(e.stderr) from e

def get_c_expression_values(
cast_to, printf_format,
Expand Down

0 comments on commit 20b9357

Please sign in to comment.