build: add compile_commands.json cleanup script
[vpp.git] / extras / scripts / compdb_cleanup.py
1 #!/usr/bin/env python3
2
3 import sys
4 import json
5
6 objects = json.load(sys.stdin)
7
8 for i in range(len(objects) - 1, -1, -1):
9     obj = objects[i]
10
11     # Remove everything except .c files
12     if not obj["file"].endswith(".c"):
13         objects.remove(obj)
14         continue
15
16     # remove duplicates introduced my multiarch
17     if "CLIB_MARCH_VARIANT" in obj["command"]:
18         objects.remove(obj)
19         continue
20
21     # remove ccache prefix
22     s = str.split(obj["command"])
23     if s[0] == "ccache":
24         s.remove(s[0])
25         s[0] = s[0].split("/")[-1]
26     obj["command"] = " ".join(s)
27
28 json.dump(objects, sys.stdout, indent=2)