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:
parent
841caadc98
commit
7493517050
@ -4,7 +4,7 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import os
|
from os import getcwd
|
||||||
|
|
||||||
'''A simple compilation database generator, or cdg in short.
|
'''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",
|
file_name_regex = re.compile(r"[\w./+\-]+\.(s|cc?|cpp|cxx)\b",
|
||||||
re.IGNORECASE)
|
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)
|
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)
|
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):
|
def parse(make_output):
|
||||||
@ -49,6 +49,12 @@ Per https://clang.llvm.org/docs/JSONCompilationDatabase.html
|
|||||||
|
|
||||||
# look backward and discard anything before delimiters
|
# look backward and discard anything before delimiters
|
||||||
i = match.start()
|
i = match.start()
|
||||||
|
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:
|
while i > 0:
|
||||||
j = i - 1
|
j = i - 1
|
||||||
if line[j] in (' ', '\t', '\n', ';', '&'):
|
if line[j] in (' ', '\t', '\n', ';', '&'):
|
||||||
@ -63,7 +69,7 @@ Per https://clang.llvm.org/docs/JSONCompilationDatabase.html
|
|||||||
|
|
||||||
# To workaround that there is no "entering directory..."
|
# To workaround that there is no "entering directory..."
|
||||||
if not pwd:
|
if not pwd:
|
||||||
pwd = os.getcwd()
|
pwd = getcwd()
|
||||||
path_stack.append(pwd)
|
path_stack.append(pwd)
|
||||||
|
|
||||||
# Special handling for projects like Redis,
|
# Special handling for projects like Redis,
|
||||||
|
Loading…
Reference in New Issue
Block a user