Archana | 1f1a34a | 2021-11-17 08:44:07 +0530 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame^] | 2 | """This script is required for the auto generation of the |
| 3 | psa_crypto_driver_wrappers.c file""" |
Archana | 1f1a34a | 2021-11-17 08:44:07 +0530 | [diff] [blame] | 4 | |
| 5 | import sys |
Archana | 1f1a34a | 2021-11-17 08:44:07 +0530 | [diff] [blame] | 6 | import os |
| 7 | import jinja2 |
| 8 | |
Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame^] | 9 | def render(template_path: str) -> str: |
| 10 | environment = jinja2.Environment( |
| 11 | loader=jinja2.FileSystemLoader(os.path.dirname(template_path)), |
| 12 | keep_trailing_newline=True) |
| 13 | template = environment.get_template(os.path.basename(template_path)) |
| 14 | return template.render() |
Archana | 1f1a34a | 2021-11-17 08:44:07 +0530 | [diff] [blame] | 15 | |
Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame^] | 16 | N = len(sys.argv) |
| 17 | if N != 2: |
| 18 | # This is the Root directory. |
| 19 | ROOT_DIR = "" |
| 20 | else: |
| 21 | # Set the root based on the argument passed. |
| 22 | ROOT_DIR = sys.argv[1] |
Archana | 1f1a34a | 2021-11-17 08:44:07 +0530 | [diff] [blame] | 23 | |
Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame^] | 24 | # Set template file name, output file name from the root directory |
| 25 | DRIVER_WRAPPER_TEMPLATE_FILENAME = ROOT_DIR +\ |
| 26 | "scripts/data_files/driver_templates/psa_crypto_driver_wrappers.conf" |
| 27 | DRIVER_WRAPPER_OUTPUT_FILENAME = ROOT_DIR + "library/psa_crypto_driver_wrappers.c" |
Archana | 1f1a34a | 2021-11-17 08:44:07 +0530 | [diff] [blame] | 28 | |
Archana | 6f21e45 | 2021-11-23 14:46:51 +0530 | [diff] [blame^] | 29 | # Render the template |
| 30 | RESULT = render(DRIVER_WRAPPER_TEMPLATE_FILENAME) |
| 31 | |
| 32 | # Write output to file |
| 33 | OUT_FILE = open(DRIVER_WRAPPER_OUTPUT_FILENAME, "w") |
| 34 | OUT_FILE.write(RESULT) |
| 35 | OUT_FILE.close() |