vim: update cdg.py

Taken from https://raw.githubusercontent.com/cerg2010cerg2010/texttoolkit/master/cdg.py
and add a small fix to get current dir for project path instead of
'/your/project/path'
This commit is contained in:
Mathieu Maret 2022-07-31 11:10:54 +02:00
parent 841caadc98
commit 7493517050
1 changed files with 16 additions and 10 deletions

View File

@ -4,7 +4,7 @@
import json
import sys
import re
import os
from os import getcwd
'''A simple compilation database generator, or cdg in short.
@ -12,11 +12,11 @@ It works by parsing the output of the GNU make command.'''
file_name_regex = re.compile(r"[\w./+\-]+\.(s|cc?|cpp|cxx)\b",
re.IGNORECASE)
enter_dir_regex = re.compile(r"^\s*make(?:\[\d+\])?: Entering directory [`\'\"](?P<dir>.*)[`\'\"]\s*$",
enter_dir_regex = re.compile(r"^\s*(?:make|ninja)(?:\[\d+\])?: Entering directory [`\'\"](?P<dir>.*)[`\'\"]\s*$",
re.MULTILINE)
leave_dir_regex = re.compile(r"^\s*make(?:\[\d+\])?: Leaving directory .*$",
leave_dir_regex = re.compile(r"^\s*(?:make|ninja)(?:\[\d+\])?: Leaving directory .*$",
re.MULTILINE)
compilers_regex = re.compile(r'\b(g?cc|[gc]\+\+|clang\+?\+?|icecc|s?ccache)\s')
compilers_regex = re.compile(r'\b(g?cc|[gc]\+\+|clang\+?\+?|icecc|s?ccache)(?:.exe)?"?\s')
def parse(make_output):
@ -49,11 +49,17 @@ Per https://clang.llvm.org/docs/JSONCompilationDatabase.html
# look backward and discard anything before delimiters
i = match.start()
while i > 0:
j = i - 1
if line[j] in (' ', '\t', '\n', ';', '&'):
break
i -= 1
if line[match.start():match.end()].rstrip()[-1] == '"':
while i > 0:
i -= 1
if line[i] == '"' and (i == 0 or line[i-1] != '\\'):
break
else:
while i > 0:
j = i - 1
if line[j] in (' ', '\t', '\n', ';', '&'):
break
i -= 1
line = line[i:]
file_match = file_name_regex.search(line)
@ -63,7 +69,7 @@ Per https://clang.llvm.org/docs/JSONCompilationDatabase.html
# To workaround that there is no "entering directory..."
if not pwd:
pwd = os.getcwd()
pwd = getcwd()
path_stack.append(pwd)
# Special handling for projects like Redis,