From 235c72d3cb63fb8f6021867dc2baeb3c6e2ebaa3 Mon Sep 17 00:00:00 2001 From: Hugues de Valon Date: Thu, 28 May 2020 08:42:01 +0100 Subject: [PATCH 1/2] Generate PSA constant names in CMake build dir This commit modifies the generate_psa_constants.py script to take as input argument the location of where to write the psa_constant_names_generated.c file. For make-based build system, this commit does not change anything. For CMake build system, this commit modifies the generation location of that file to be inside the build directory and include it from there in psa_constant_names.c Fix #3365 Signed-off-by: Hugues de Valon --- programs/psa/CMakeLists.txt | 3 ++- scripts/generate_psa_constants.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/programs/psa/CMakeLists.txt b/programs/psa/CMakeLists.txt index c80043bc4..201f987c7 100644 --- a/programs/psa/CMakeLists.txt +++ b/programs/psa/CMakeLists.txt @@ -5,11 +5,12 @@ add_executable(key_ladder_demo key_ladder_demo.c) target_link_libraries(key_ladder_demo mbedtls) add_executable(psa_constant_names psa_constant_names.c) +target_include_directories(psa_constant_names PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_link_libraries(psa_constant_names mbedtls) add_custom_target( psa_constant_names_generated - COMMAND ${PYTHON_EXECUTABLE} scripts/generate_psa_constants.py + COMMAND ${PYTHON_EXECUTABLE} scripts/generate_psa_constants.py ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../ ) add_dependencies(psa_constant_names psa_constant_names_generated) diff --git a/scripts/generate_psa_constants.py b/scripts/generate_psa_constants.py index c6bd9b6a0..c441b4e15 100755 --- a/scripts/generate_psa_constants.py +++ b/scripts/generate_psa_constants.py @@ -8,6 +8,7 @@ of that program. import os import re +import sys OUTPUT_TEMPLATE = '''\ /* Automatically generated by generate_psa_constant.py. DO NOT EDIT. */ @@ -395,6 +396,8 @@ def generate_psa_constants(header_file_names, output_file_name): if __name__ == '__main__': if not os.path.isdir('programs') and os.path.isdir('../programs'): os.chdir('..') + # Allow to change the directory where psa_constant_names_generated.c is written to. + OUTPUT_FILE_DIR = sys.argv[1] if len(sys.argv) == 2 else "programs/psa" generate_psa_constants(['include/psa/crypto_values.h', 'include/psa/crypto_extra.h'], - 'programs/psa/psa_constant_names_generated.c') + OUTPUT_FILE_DIR + '/psa_constant_names_generated.c') From 600cf9d142ebe8520020d9d49bb8f314a37cf459 Mon Sep 17 00:00:00 2001 From: Hugues de Valon Date: Fri, 29 May 2020 10:29:49 +0100 Subject: [PATCH 2/2] Add usage info of generate_psa_constants script Signed-off-by: Hugues de Valon --- scripts/generate_psa_constants.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/generate_psa_constants.py b/scripts/generate_psa_constants.py index c441b4e15..175cd9ffc 100755 --- a/scripts/generate_psa_constants.py +++ b/scripts/generate_psa_constants.py @@ -1,9 +1,14 @@ #!/usr/bin/env python3 -"""Generate programs/psa/psa_constant_names_generated.c +"""Generate psa_constant_names_generated.c which is included by programs/psa/psa_constant_names.c. The code generated by this module is only meant to be used in the context of that program. + +An argument passed to this script will modify the output directory where the +file is written: +* by default (no arguments passed): writes to programs/psa/ +* OUTPUT_FILE_DIR passed: writes to OUTPUT_FILE_DIR/ """ import os