Automaticly generate psa_crypto_driver_wrappers_no_static.c

Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
This commit is contained in:
Xiaokang Qian 2023-09-11 02:39:27 +00:00
parent 97d1ccb781
commit 54a4fdfe91
3 changed files with 145 additions and 140 deletions

View file

@ -1,9 +1,10 @@
#!/usr/bin/env python3
"""Generate library/psa_crypto_driver_wrappers.c
"""Generate library/psa_crypto_driver_wrappers.h
library/psa_crypto_driver_wrappers_no_static.c
This module is invoked by the build scripts to auto generate the
psa_crypto_driver_wrappers.c based on template files in
script/data_files/driver_templates/.
psa_crypto_driver_wrappers.h and psa_crypto_driver_wrappers_no_static
based on template files in script/data_files/driver_templates/.
"""
# Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0
@ -59,19 +60,19 @@ def render(template_path: str, driver_jsoncontext: list) -> str:
return template.render(drivers=driver_jsoncontext)
def generate_driver_wrapper_file(template_dir: str,
output_dir: str,
template_file_name: str,
driver_jsoncontext: list) -> None:
"""
Generate the file psa_crypto_driver_wrapper.c.
"""
driver_wrapper_template_filename = \
os.path.join(template_dir, "psa_crypto_driver_wrappers.c.jinja")
os.path.join(template_dir, template_file_name)
result = render(driver_wrapper_template_filename, driver_jsoncontext)
with open(file=os.path.join(output_dir, "psa_crypto_driver_wrappers.c"),
with open(file=os.path.join(output_dir, template_file_name.rsplit(".", 1)[0]),
mode='w',
encoding='UTF-8') as out_file:
out_file.write(result)
@ -167,6 +168,9 @@ def trace_exception(e: Exception, file=sys.stderr) -> None:
), file)
TEMPLATE_FILENAMES = ["psa_crypto_driver_wrappers.c.jinja",
"psa_crypto_driver_wrappers_no_static.c.jinja"]
def main() -> int:
"""
Main with command line arguments.
@ -207,7 +211,9 @@ def main() -> int:
except DriverReaderException as e:
trace_exception(e)
return 1
generate_driver_wrapper_file(template_directory, output_directory, merged_driver_json)
for template_filename in TEMPLATE_FILENAMES:
generate_driver_wrapper_file(template_directory, output_directory,
template_filename, merged_driver_json)
return 0