-
Notifications
You must be signed in to change notification settings - Fork 626
/
Copy pathfix_compile_commands.py
executable file
·42 lines (31 loc) · 1.12 KB
/
fix_compile_commands.py
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
39
40
41
42
#!/usr/bin/env python3
import argparse
import json
def main():
parser = argparse.ArgumentParser(
description="Fix compile_commands.json generated by Gradle"
)
parser.add_argument("filename", help="compile_commands.json location")
cmd_args = parser.parse_args()
# Read JSON
with open(cmd_args.filename) as f:
data = json.load(f)
for obj in data:
out_args = []
# Filter out -isystem flags that cause false positives
iter_args = iter(obj["arguments"])
for arg in iter_args:
if arg == "-isystem":
next_arg = next(iter_args)
# /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/include/xmmintrin.h:54:1:
# error: conflicting types for '_mm_prefetch' [clang-diagnostic-error]
if not next_arg.startswith("/usr/lib/gcc/"):
out_args += ["-isystem", next_arg]
else:
out_args.append(arg)
obj["arguments"] = out_args
# Write JSON
with open(cmd_args.filename, "w") as f:
json.dump(data, f, indent=2)
if __name__ == "__main__":
main()