From 20b9357d37dcc9d690aad0112eaa774d4227dd1a Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Sat, 3 Aug 2024 14:29:42 +0200 Subject: [PATCH] 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 --- scripts/mbedtls_framework/c_build_helper.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/mbedtls_framework/c_build_helper.py b/scripts/mbedtls_framework/c_build_helper.py index f2cbbe4af7..16845fcbad 100644 --- a/scripts/mbedtls_framework/c_build_helper.py +++ b/scripts/mbedtls_framework/c_build_helper.py @@ -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: @@ -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,