build: add compile_commands.json cleanup script 14/29614/3
authorDamjan Marion <damarion@cisco.com>
Fri, 23 Oct 2020 15:20:32 +0000 (17:20 +0200)
committerDamjan Marion <dmarion@me.com>
Sat, 24 Oct 2020 09:14:11 +0000 (09:14 +0000)
Type: make
Change-Id: I8d6a5018bddf029e106df3cb8b8eded4fa28067d
Signed-off-by: Damjan Marion <damarion@cisco.com>
Makefile
extras/scripts/compdb_cleanup.py [new file with mode: 0755]

index 3bdba65..aaba277 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -606,7 +606,9 @@ cscope: cscope.files
 
 .PHONY: compdb
 compdb:
-       @ninja -C build-root/build-vpp_debug-native/vpp -t compdb > compile_commands.json
+       @ninja -C build-root/build-vpp_debug-native/vpp build.ninja
+       @ninja -C build-root/build-vpp_debug-native/vpp -t compdb | \
+         extras/scripts/compdb_cleanup.py > compile_commands.json
 
 .PHONY: checkstyle
 checkstyle: checkfeaturelist
diff --git a/extras/scripts/compdb_cleanup.py b/extras/scripts/compdb_cleanup.py
new file mode 100755 (executable)
index 0000000..0139b6b
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+import sys
+import json
+
+objects = json.load(sys.stdin)
+
+for i in range(len(objects) - 1, -1, -1):
+    obj = objects[i]
+
+    # Remove everything except .c files
+    if not obj["file"].endswith(".c"):
+        objects.remove(obj)
+        continue
+
+    # remove duplicates introduced my multiarch
+    if "CLIB_MARCH_VARIANT" in obj["command"]:
+        objects.remove(obj)
+        continue
+
+    # remove ccache prefix
+    s = str.split(obj["command"])
+    if s[0] == "ccache":
+        s.remove(s[0])
+        s[0] = s[0].split("/")[-1]
+    obj["command"] = " ".join(s)
+
+json.dump(objects, sys.stdout, indent=2)