blob: 093a606cce35de4765f61112138be6d6838c9b58 [file] [log] [blame]
Richard Burtonf32a86a2022-11-15 11:46:11 +00001# SPDX-FileCopyrightText: Copyright 2021 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"""
19import datetime
Richard Burton17069622022-03-17 10:54:26 +000020from pathlib import Path
alexander3c798932021-03-26 21:42:19 +000021from argparse import ArgumentParser
Richard Burton17069622022-03-17 10:54:26 +000022
alexander3c798932021-03-26 21:42:19 +000023from jinja2 import Environment, FileSystemLoader
24
25parser = ArgumentParser()
26parser.add_argument("--header_folder_path", type=str, help="path to header folder to be generated.")
27parser.add_argument("--license_template", type=str, help="Header template file",
28 default="header_template.txt")
29args = parser.parse_args()
30
Richard Burton17069622022-03-17 10:54:26 +000031env = Environment(loader=FileSystemLoader(Path(__file__).parent / 'templates'),
alexander3c798932021-03-26 21:42:19 +000032 trim_blocks=True,
33 lstrip_blocks=True)
34
35
36def 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)
Richard Burton17069622022-03-17 10:54:26 +000039 hdr = header_template.render(script_name=Path(__file__).name,
alexander3c798932021-03-26 21:42:19 +000040 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
46def main(args):
47 header_filename = "InputFiles.hpp"
Richard Burton17069622022-03-17 10:54:26 +000048 header_filepath = Path(args.header_folder_path) / header_filename
alexander3c798932021-03-26 21:42:19 +000049 write_hpp_file(header_filepath, args.license_template)
50
51
52if __name__ == '__main__':
53 main(args)