mbedtls/scripts/generate_driver_wrappers.py
Archana 6f21e45b78
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>
2021-12-18 13:28:59 +05:30

36 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""This script is required for the auto generation of the
psa_crypto_driver_wrappers.c file"""
import sys
import os
import jinja2
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 != 2:
# This is the Root directory.
ROOT_DIR = ""
else:
# Set the root based on the argument passed.
ROOT_DIR = sys.argv[1]
# 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"
# 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()