From ac49ee5d4cf75a865bf852ca05f01d520976eaa2 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Wed, 18 Jan 2023 11:52:56 +0000 Subject: [PATCH] c_build_helper.py: Move compile to helper Move compilation to a separate helper function in c_build_helper.py to allow more generic use. Signed-off-by: David Horstmann --- scripts/mbedtls_dev/c_build_helper.py | 39 +++++++++++++++------------ 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/scripts/mbedtls_dev/c_build_helper.py b/scripts/mbedtls_dev/c_build_helper.py index 459afba426..7e0cac7302 100644 --- a/scripts/mbedtls_dev/c_build_helper.py +++ b/scripts/mbedtls_dev/c_build_helper.py @@ -89,6 +89,27 @@ int main(void) } ''') +def compile_c_file(c_filename, exe_filename, include_dirs): + cc = os.getenv('CC', 'cc') + cmd = [cc] + + proc = subprocess.Popen(cmd, + stdout=subprocess.DEVNULL, + stderr=subprocess.PIPE, + universal_newlines=True) + cc_is_msvc = 'Microsoft (R) C/C++' in proc.communicate()[1] + + cmd += ['-I' + dir for dir in include_dirs] + if cc_is_msvc: + # MSVC has deprecated using -o to specify the output file, + # and produces an object file in the working directory by default. + obj_filename = exe_filename[:-4] + '.obj' + cmd += ['-Fe' + exe_filename, '-Fo' + obj_filename] + else: + cmd += ['-o' + exe_filename] + + subprocess.check_call(cmd + [c_filename]) + def get_c_expression_values( cast_to, printf_format, expressions, @@ -128,24 +149,8 @@ def get_c_expression_values( expressions) ) c_file.close() - cc = os.getenv('CC', 'cc') - cmd = [cc] - proc = subprocess.Popen(cmd, - stdout=subprocess.DEVNULL, - stderr=subprocess.PIPE, - universal_newlines=True) - cc_is_msvc = 'Microsoft (R) C/C++' in proc.communicate()[1] - - cmd += ['-I' + dir for dir in include_path] - if cc_is_msvc: - # MSVC has deprecated using -o to specify the output file, - # and produces an object file in the working directory by default. - obj_name = exe_name[:-4] + '.obj' - cmd += ['-Fe' + exe_name, '-Fo' + obj_name] - else: - cmd += ['-o' + exe_name] - subprocess.check_call(cmd + [c_name]) + compile_c_file(c_name, exe_name, include_path) if keep_c: sys.stderr.write('List of {} tests kept at {}\n' .format(caller, c_name))