blob: e3185dc922f93a0730510adf6ad3627912866bf8 [file] [log] [blame]
Raef Coles59cf5d82024-12-09 15:41:13 +00001#!/usr/bin/env python3
2#-------------------------------------------------------------------------------
3# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7#-------------------------------------------------------------------------------
8
9import os
10import json
11
Raef Colescfc31242025-04-04 09:38:47 +010012import logging
13logger = logging.getLogger("TF-M.{}".format(__name__))
14
Raef Coles59cf5d82024-12-09 15:41:13 +000015def get_compile_command(compile_commands_file, c_file):
16 with open(compile_commands_file, "rt") as f:
17 compile_commands = json.load(f)
18
19 return [x['command'] for x in compile_commands if c_file in x['file']][0]
20
21def get_includes(compile_commands_file, c_file):
22 compile_command = get_compile_command(compile_commands_file, c_file).split()
23 return [x[2:].strip() for x in compile_command if x.rstrip()[:2] == "-I"]
24
25def get_defines(compile_commands_file, c_file):
26 compile_command = get_compile_command(compile_commands_file, c_file).split()
27 return [x[2:].strip() for x in compile_command if x.rstrip()[:2] == "-D"]
28
29
30if __name__ == '__main__':
31 import argparse
32
33 parser = argparse.ArgumentParser(allow_abbrev=False)
34 parser.add_argument("--compile_commands_file", help="path to compile_command.json", required=True)
35 parser.add_argument("--c_file", help="name of the c file to take", required=True)
36 parser.add_argument("--log_level", help="log level", required=False, default="ERROR", choices=logging._levelToName.values())
37 args = parser.parse_args()
Raef Colescfc31242025-04-04 09:38:47 +010038 logging.getLogger("TF-M").setLevel(args.log_level)
39 logger.addHandler(logging.StreamHandler())
Raef Coles59cf5d82024-12-09 15:41:13 +000040
41 print(get_compile_command(args.compile_commands_file, args.c_file))
42 print(get_includes(args.compile_commands_file, args.c_file))
43 print(get_defines(args.compile_commands_file, args.c_file))