-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathcombine_compile_commands.py
More file actions
38 lines (33 loc) · 1.17 KB
/
combine_compile_commands.py
File metadata and controls
38 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#
# Copyright (c) 2021-present, Trail of Bits, Inc.
#
# This source code is licensed in accordance with the terms specified in
# the LICENSE file found in the root directory of this source tree.
#
# find ./ -type f -name '*.json' ! -name 'compile_commands.json' ! -name 'manifest.json' ! -name 'build-request.json' | xargs python3 ./combine_json_files.py >compile_commands.json
import json
import os
import sys
if __name__ == "__main__":
parts = []
for file_name in sys.argv[1:]:
if not file_name.endswith(".json"):
continue
if not os.path.isfile(file_name):
continue
with open(file_name, "r") as open_file:
parts.append(open_file.read().strip(" \r\n\t[],"))
all_data = "[{}]".format(",\n".join(parts))
commands = json.loads(all_data)
filtered_commands = []
for command in commands:
if "file" in command:
input_file = command["file"].lower()
if input_file.endswith(".i") or \
input_file.endswith(".ii") or \
input_file.endswith(".ir") or \
input_file.endswith(".bc") or \
input_file.endswith(".s"):
continue
filtered_commands.append(command)
print(json.dumps(filtered_commands, indent=2))