blob: 6056dc15f524640bbcfe51dab114a0fee22f468a [file] [log] [blame]
Alex Tawsedaba3cf2023-09-29 15:55:38 +01001# SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
alexander3c798932021-03-26 21:42:19 +00002# 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"""
17Utility script to generate the minimum InputFiles.hpp and cpp files required by an application.
18"""
alexander3c798932021-03-26 21:42:19 +000019from argparse import ArgumentParser
Alex Tawsedaba3cf2023-09-29 15:55:38 +010020from pathlib import Path
Richard Burton17069622022-03-17 10:54:26 +000021
alexander3c798932021-03-26 21:42:19 +000022from jinja2 import Environment, FileSystemLoader
23
Alex Tawsedaba3cf2023-09-29 15:55:38 +010024from gen_utils import GenUtils
25
alexander3c798932021-03-26 21:42:19 +000026parser = ArgumentParser()
Alex Tawsedaba3cf2023-09-29 15:55:38 +010027
28# pylint: disable=duplicate-code
29parser.add_argument(
30 "--header_folder_path",
31 type=str,
32 help="path to header folder to be generated."
33)
34
35parser.add_argument(
36 "--license_template",
37 type=str,
38 help="Header template file",
39 default="header_template.txt"
40
41)
42
43parsed_args = parser.parse_args()
alexander3c798932021-03-26 21:42:19 +000044
Richard Burton17069622022-03-17 10:54:26 +000045env = Environment(loader=FileSystemLoader(Path(__file__).parent / 'templates'),
alexander3c798932021-03-26 21:42:19 +000046 trim_blocks=True,
47 lstrip_blocks=True)
48
49
Alex Tawsedaba3cf2023-09-29 15:55:38 +010050# pylint: enable=duplicate-code
alexander3c798932021-03-26 21:42:19 +000051def write_hpp_file(header_file_path, header_template_file):
Alex Tawsedaba3cf2023-09-29 15:55:38 +010052 """
53 Write .hpp file
54 @param header_file_path: Header file path
55 @param header_template_file: Header template file
56 """
alexander3c798932021-03-26 21:42:19 +000057 print(f"++ Generating {header_file_path}")
Alex Tawsedaba3cf2023-09-29 15:55:38 +010058 hdr = GenUtils.gen_header(env, header_template_file)
59 env \
60 .get_template('default.hpp.template') \
61 .stream(common_template_header=hdr) \
alexander3c798932021-03-26 21:42:19 +000062 .dump(str(header_file_path))
63
64
65def main(args):
Alex Tawsedaba3cf2023-09-29 15:55:38 +010066 """
67 Generate InputFiles.hpp + .cpp
68 @param args: Parsed args
69 """
alexander3c798932021-03-26 21:42:19 +000070 header_filename = "InputFiles.hpp"
Richard Burton17069622022-03-17 10:54:26 +000071 header_filepath = Path(args.header_folder_path) / header_filename
alexander3c798932021-03-26 21:42:19 +000072 write_hpp_file(header_filepath, args.license_template)
73
74
75if __name__ == '__main__':
Alex Tawsedaba3cf2023-09-29 15:55:38 +010076 main(parsed_args)