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:
parent
a8939b6da3
commit
6f21e45b78
@ -157,10 +157,26 @@ if(GEN_FILES)
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../scripts/generate_ssl_debug_helpers.py
|
||||
${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()
|
||||
link_to_source(error.c)
|
||||
link_to_source(version_features.c)
|
||||
link_to_source(ssl_debug_helpers_generated.c)
|
||||
link_to_source(psa_crypto_driver_wrappers.c)
|
||||
endif()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
|
@ -324,8 +324,7 @@ psa_crypto_driver_wrappers.c: ../scripts/data_files/driver_templates/psa_crypto_
|
||||
psa_crypto_driver_wrappers.c:
|
||||
echo " Gen $@"
|
||||
$(PYTHON) ../scripts/generate_driver_wrappers.py \
|
||||
"../scripts/data_files/driver_templates/psa_crypto_driver_wrappers.conf" \
|
||||
"psa_crypto_driver_wrappers.c"
|
||||
"../"
|
||||
|
||||
clean:
|
||||
ifndef WINDOWS
|
||||
|
@ -1,28 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
"""This script is required for the auto generation of the
|
||||
psa_crypto_driver_wrappers.c file"""
|
||||
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
import jinja2
|
||||
|
||||
def render(tpl_path):
|
||||
path, filename = os.path.split(tpl_path)
|
||||
return jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader(path or './'),
|
||||
keep_trailing_newline=True,
|
||||
).get_template(filename).render()
|
||||
def render(template_path: str) -> str:
|
||||
environment = jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader(os.path.dirname(template_path)),
|
||||
keep_trailing_newline=True)
|
||||
template = environment.get_template(os.path.basename(template_path))
|
||||
return template.render()
|
||||
|
||||
n = len(sys.argv)
|
||||
if ( n != 3 ):
|
||||
sys.exit("The template file name and output file name are expected as arguments")
|
||||
# set template file name, output file name
|
||||
driver_wrapper_template_filename = sys.argv[1]
|
||||
driver_wrapper_output_filename = sys.argv[2]
|
||||
N = len(sys.argv)
|
||||
if N != 2:
|
||||
# This is the Root directory.
|
||||
ROOT_DIR = ""
|
||||
else:
|
||||
# Set the root based on the argument passed.
|
||||
ROOT_DIR = sys.argv[1]
|
||||
|
||||
# render the template
|
||||
result = render(driver_wrapper_template_filename)
|
||||
# Set template file name, output file name from the root directory
|
||||
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
|
||||
outFile = open(driver_wrapper_output_filename,"w")
|
||||
outFile.write(result)
|
||||
outFile.close()
|
||||
# Render the template
|
||||
RESULT = render(DRIVER_WRAPPER_TEMPLATE_FILENAME)
|
||||
|
||||
# Write output to file
|
||||
OUT_FILE = open(DRIVER_WRAPPER_OUTPUT_FILENAME, "w")
|
||||
OUT_FILE.write(RESULT)
|
||||
OUT_FILE.close()
|
||||
|
@ -1,15 +1,13 @@
|
||||
@rem Generate automatically-generated configuration-independent source files
|
||||
@rem and build scripts.
|
||||
@rem Perl and Python 3 must be on the PATH.
|
||||
@rem psa_crypto_driver_wrappers.c needs to be generated prior to
|
||||
@rem generate_visualc_files.pl being invoked.
|
||||
python scripts/generate_driver_wrappers.py ^
|
||||
"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_query_config.pl || exit /b 1
|
||||
perl scripts\generate_features.pl || exit /b 1
|
||||
python scripts\generate_ssl_debug_helpers.py || exit /b 1
|
||||
perl scripts\generate_visualc_files.pl || exit /b 1
|
||||
@rem Generate automatically-generated configuration-independent source files
|
||||
@rem and build scripts.
|
||||
@rem Perl and Python 3 must be on the PATH.
|
||||
@rem psa_crypto_driver_wrappers.c needs to be generated prior to
|
||||
@rem generate_visualc_files.pl being invoked.
|
||||
python scripts\generate_driver_wrappers.py || exit /b 1
|
||||
perl scripts\generate_errors.pl || exit /b 1
|
||||
perl scripts\generate_query_config.pl || exit /b 1
|
||||
perl scripts\generate_features.pl || exit /b 1
|
||||
python scripts\generate_ssl_debug_helpers.py || exit /b 1
|
||||
perl scripts\generate_visualc_files.pl || exit /b 1
|
||||
python scripts\generate_psa_constants.py || exit /b 1
|
||||
python tests\scripts\generate_psa_tests.py || exit /b 1
|
||||
|
@ -117,6 +117,7 @@ check()
|
||||
|
||||
check scripts/generate_errors.pl library/error.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_ssl_debug_helpers.py library/ssl_debug_helpers_generated.c
|
||||
# generate_visualc_files enumerates source files (library/*.c). It doesn't
|
||||
|
Loading…
Reference in New Issue
Block a user