blob: 8a52830dea25a9f9be109826ea64cca79c943c1a [file] [log] [blame]
Maxwell Henderson80bec322024-01-09 15:48:44 -08001#!/usr/bin/env python3
2
3import argparse
4import json
5
6
7def main():
8 parser = argparse.ArgumentParser(
9 description="Fix compile_commands.json generated by Gradle"
10 )
11 parser.add_argument("filename", help="compile_commands.json location")
12 cmd_args = parser.parse_args()
13
14 # Read JSON
15 with open(cmd_args.filename) as f:
16 data = json.load(f)
17
18 for obj in data:
19 out_args = []
20
21 # Filter out -isystem flags that cause false positives
22 iter_args = iter(obj["arguments"])
23 for arg in iter_args:
24 if arg == "-isystem":
25 next_arg = next(iter_args)
26
27 # /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/include/xmmintrin.h:54:1:
28 # error: conflicting types for '_mm_prefetch' [clang-diagnostic-error]
29 if not next_arg.startswith("/usr/lib/gcc/"):
30 out_args += ["-isystem", next_arg]
31 else:
32 out_args.append(arg)
33
34 obj["arguments"] = out_args
35
36 # Write JSON
37 with open(cmd_args.filename, "w") as f:
38 json.dump(data, f, indent=2)
39
40
41if __name__ == "__main__":
42 main()