blob: 636f31dd0709375715947cfd1f4553f2d829fea3 [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
12def get_compile_command(compile_commands_file, c_file):
13 with open(compile_commands_file, "rt") as f:
14 compile_commands = json.load(f)
15
16 return [x['command'] for x in compile_commands if c_file in x['file']][0]
17
18def get_includes(compile_commands_file, c_file):
19 compile_command = get_compile_command(compile_commands_file, c_file).split()
20 return [x[2:].strip() for x in compile_command if x.rstrip()[:2] == "-I"]
21
22def get_defines(compile_commands_file, c_file):
23 compile_command = get_compile_command(compile_commands_file, c_file).split()
24 return [x[2:].strip() for x in compile_command if x.rstrip()[:2] == "-D"]
25
26
27if __name__ == '__main__':
28 import argparse
29
30 parser = argparse.ArgumentParser(allow_abbrev=False)
31 parser.add_argument("--compile_commands_file", help="path to compile_command.json", required=True)
32 parser.add_argument("--c_file", help="name of the c file to take", required=True)
33 parser.add_argument("--log_level", help="log level", required=False, default="ERROR", choices=logging._levelToName.values())
34 args = parser.parse_args()
35 logger.setLevel(args.log_level)
36
37 print(get_compile_command(args.compile_commands_file, args.c_file))
38 print(get_includes(args.compile_commands_file, args.c_file))
39 print(get_defines(args.compile_commands_file, args.c_file))