alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | # Copyright (c) 2021 Arm Limited. All rights reserved. |
| 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 | """ |
| 19 | import datetime |
| 20 | import os |
| 21 | |
| 22 | from argparse import ArgumentParser |
| 23 | from jinja2 import Environment, FileSystemLoader |
| 24 | |
| 25 | parser = ArgumentParser() |
| 26 | parser.add_argument("--header_folder_path", type=str, help="path to header folder to be generated.") |
| 27 | parser.add_argument("--license_template", type=str, help="Header template file", |
| 28 | default="header_template.txt") |
| 29 | args = parser.parse_args() |
| 30 | |
| 31 | env = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')), |
| 32 | trim_blocks=True, |
| 33 | lstrip_blocks=True) |
| 34 | |
| 35 | |
| 36 | def write_hpp_file(header_file_path, header_template_file): |
| 37 | print(f"++ Generating {header_file_path}") |
| 38 | header_template = env.get_template(header_template_file) |
| 39 | hdr = header_template.render(script_name=os.path.basename(__file__), |
| 40 | gen_time=datetime.datetime.now(), |
| 41 | year=datetime.datetime.now().year) |
| 42 | env.get_template('default.hpp.template').stream(common_template_header=hdr) \ |
| 43 | .dump(str(header_file_path)) |
| 44 | |
| 45 | |
| 46 | def main(args): |
| 47 | header_filename = "InputFiles.hpp" |
| 48 | header_filepath = os.path.join(args.header_folder_path, header_filename) |
| 49 | write_hpp_file(header_filepath, args.license_template) |
| 50 | |
| 51 | |
| 52 | if __name__ == '__main__': |
| 53 | main(args) |