1
0
mirror of https://github.com/ARMmbed/mbedtls.git synced 2025-05-12 09:54:38 +08:00

Fix Pylint errors and improve Python script

Pylint errors are fixed.
The Python script is improved to take default arguments when not
passed (eg invoked from root of the tree)

check-generated-files.sh and CMakeLists.sh updated.

Signed-off-by: Archana <archana.madhavan@silabs.com>
This commit is contained in:
Archana 2021-11-23 14:46:51 +05:30
parent a8939b6da3
commit 6f21e45b78
No known key found for this signature in database
GPG Key ID: 0F162FC9DB6BE502
5 changed files with 55 additions and 34 deletions

View File

@ -157,10 +157,26 @@ if(GEN_FILES)
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_ssl_debug_helpers.py ${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_ssl_debug_helpers.py
${error_headers} ${error_headers}
) )
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers.c
COMMAND
${MBEDTLS_PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_driver_wrappers.py
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.conf
${CMAKE_CURRENT_BINARY_DIR}/psa_crypto_driver_wrappers.c
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_driver_wrappers.py
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.conf
)
else() else()
link_to_source(error.c) link_to_source(error.c)
link_to_source(version_features.c) link_to_source(version_features.c)
link_to_source(ssl_debug_helpers_generated.c) link_to_source(ssl_debug_helpers_generated.c)
link_to_source(psa_crypto_driver_wrappers.c)
endif() endif()
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)

View File

@ -324,8 +324,7 @@ psa_crypto_driver_wrappers.c: ../scripts/data_files/driver_templates/psa_crypto_
psa_crypto_driver_wrappers.c: psa_crypto_driver_wrappers.c:
echo " Gen $@" echo " Gen $@"
$(PYTHON) ../scripts/generate_driver_wrappers.py \ $(PYTHON) ../scripts/generate_driver_wrappers.py \
"../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.conf" \ "../"
"psa_crypto_driver_wrappers.c"
clean: clean:
ifndef WINDOWS ifndef WINDOWS

View File

@ -1,28 +1,35 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""This script is required for the auto generation of the
psa_crypto_driver_wrappers.c file"""
import sys import sys
import json
import os import os
import jinja2 import jinja2
def render(tpl_path): def render(template_path: str) -> str:
path, filename = os.path.split(tpl_path) environment = jinja2.Environment(
return jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.dirname(template_path)),
loader=jinja2.FileSystemLoader(path or './'), keep_trailing_newline=True)
keep_trailing_newline=True, template = environment.get_template(os.path.basename(template_path))
).get_template(filename).render() return template.render()
n = len(sys.argv) N = len(sys.argv)
if ( n != 3 ): if N != 2:
sys.exit("The template file name and output file name are expected as arguments") # This is the Root directory.
# set template file name, output file name ROOT_DIR = ""
driver_wrapper_template_filename = sys.argv[1] else:
driver_wrapper_output_filename = sys.argv[2] # Set the root based on the argument passed.
ROOT_DIR = sys.argv[1]
# render the template # Set template file name, output file name from the root directory
result = render(driver_wrapper_template_filename) DRIVER_WRAPPER_TEMPLATE_FILENAME = ROOT_DIR +\
"scripts/data_files/driver_templates/psa_crypto_driver_wrappers.conf"
DRIVER_WRAPPER_OUTPUT_FILENAME = ROOT_DIR + "library/psa_crypto_driver_wrappers.c"
# write output to file # Render the template
outFile = open(driver_wrapper_output_filename,"w") RESULT = render(DRIVER_WRAPPER_TEMPLATE_FILENAME)
outFile.write(result)
outFile.close() # Write output to file
OUT_FILE = open(DRIVER_WRAPPER_OUTPUT_FILENAME, "w")
OUT_FILE.write(RESULT)
OUT_FILE.close()

View File

@ -3,9 +3,7 @@
@rem Perl and Python 3 must be on the PATH. @rem Perl and Python 3 must be on the PATH.
@rem psa_crypto_driver_wrappers.c needs to be generated prior to @rem psa_crypto_driver_wrappers.c needs to be generated prior to
@rem generate_visualc_files.pl being invoked. @rem generate_visualc_files.pl being invoked.
python scripts/generate_driver_wrappers.py ^ python scripts\generate_driver_wrappers.py || exit /b 1
"scripts/data_files/driver_templates/psa_crypto_driver_wrappers.conf" ^
"library/psa_crypto_driver_wrappers.c" || exit /b 1
perl scripts\generate_errors.pl || exit /b 1 perl scripts\generate_errors.pl || exit /b 1
perl scripts\generate_query_config.pl || exit /b 1 perl scripts\generate_query_config.pl || exit /b 1
perl scripts\generate_features.pl || exit /b 1 perl scripts\generate_features.pl || exit /b 1

View File

@ -117,6 +117,7 @@ check()
check scripts/generate_errors.pl library/error.c check scripts/generate_errors.pl library/error.c
check scripts/generate_query_config.pl programs/test/query_config.c check scripts/generate_query_config.pl programs/test/query_config.c
check scripts/generate_driver_wrappers.py library/psa_crypto_driver_wrappers.c
check scripts/generate_features.pl library/version_features.c check scripts/generate_features.pl library/version_features.c
check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c check scripts/generate_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c
# generate_visualc_files enumerates source files (library/*.c). It doesn't # generate_visualc_files enumerates source files (library/*.c). It doesn't