Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | """ |
| 17 | Utility script to generate the minimum InputFiles.hpp and cpp files required by an application. |
| 18 | """ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 19 | from argparse import ArgumentParser |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 20 | from pathlib import Path |
Richard Burton | 1706962 | 2022-03-17 10:54:26 +0000 | [diff] [blame] | 21 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 22 | from jinja2 import Environment, FileSystemLoader |
| 23 | |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 24 | from gen_utils import GenUtils |
| 25 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 26 | parser = ArgumentParser() |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 27 | |
| 28 | # pylint: disable=duplicate-code |
| 29 | parser.add_argument( |
| 30 | "--header_folder_path", |
| 31 | type=str, |
| 32 | help="path to header folder to be generated." |
| 33 | ) |
| 34 | |
| 35 | parser.add_argument( |
| 36 | "--license_template", |
| 37 | type=str, |
| 38 | help="Header template file", |
| 39 | default="header_template.txt" |
| 40 | |
| 41 | ) |
| 42 | |
| 43 | parsed_args = parser.parse_args() |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 44 | |
Richard Burton | 1706962 | 2022-03-17 10:54:26 +0000 | [diff] [blame] | 45 | env = Environment(loader=FileSystemLoader(Path(__file__).parent / 'templates'), |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 46 | trim_blocks=True, |
| 47 | lstrip_blocks=True) |
| 48 | |
| 49 | |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 50 | # pylint: enable=duplicate-code |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 51 | def write_hpp_file(header_file_path, header_template_file): |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 52 | """ |
| 53 | Write .hpp file |
| 54 | @param header_file_path: Header file path |
| 55 | @param header_template_file: Header template file |
| 56 | """ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 57 | print(f"++ Generating {header_file_path}") |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 58 | hdr = GenUtils.gen_header(env, header_template_file) |
| 59 | env \ |
| 60 | .get_template('default.hpp.template') \ |
| 61 | .stream(common_template_header=hdr) \ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 62 | .dump(str(header_file_path)) |
| 63 | |
| 64 | |
| 65 | def main(args): |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 66 | """ |
| 67 | Generate InputFiles.hpp + .cpp |
| 68 | @param args: Parsed args |
| 69 | """ |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 70 | header_filename = "InputFiles.hpp" |
Richard Burton | 1706962 | 2022-03-17 10:54:26 +0000 | [diff] [blame] | 71 | header_filepath = Path(args.header_folder_path) / header_filename |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 72 | write_hpp_file(header_filepath, args.license_template) |
| 73 | |
| 74 | |
| 75 | if __name__ == '__main__': |
Alex Tawse | daba3cf | 2023-09-29 15:55:38 +0100 | [diff] [blame] | 76 | main(parsed_args) |