Updated compiler database generator to handle multiple target executables
This commit is contained in:
@@ -7,11 +7,12 @@ import os
|
||||
def is_source_file(filepath):
|
||||
return filepath.endswith('.c') or filepath.endswith('.h') or filepath.endswith('.S')
|
||||
|
||||
dir_stack = []
|
||||
rootdir = os.getcwd()
|
||||
|
||||
compile_db = []
|
||||
|
||||
make_output = subprocess.check_output(['make', '-n']).decode('utf-8')
|
||||
make_output = subprocess.check_output(['make', '-nw']).decode('utf-8')
|
||||
|
||||
make_output_lines = make_output.split('\n')
|
||||
|
||||
@@ -19,6 +20,15 @@ for line in make_output_lines:
|
||||
line_parts = line.split(' ')
|
||||
new_line_parts = []
|
||||
|
||||
if len(line_parts) >= 2 and 'Entering directory' in line:
|
||||
new_dir = line[line.find('`') + 1:-1]
|
||||
dir_stack.append(new_dir)
|
||||
continue
|
||||
|
||||
if len(line_parts) >= 2 and 'Leaving directory' in line:
|
||||
dir_stack.pop()
|
||||
continue;
|
||||
|
||||
if 'gcc' not in line_parts[0]:
|
||||
continue
|
||||
|
||||
@@ -27,7 +37,7 @@ for line in make_output_lines:
|
||||
part = part.strip()
|
||||
if is_source_file(part):
|
||||
src_file = part
|
||||
part = '../{}'.format(part)
|
||||
part = os.path.join(dir_stack[-1], part)
|
||||
|
||||
new_line_parts.append(part)
|
||||
|
||||
@@ -35,9 +45,9 @@ for line in make_output_lines:
|
||||
continue
|
||||
|
||||
db_entry = {
|
||||
'directory': '{}/build'.format(rootdir),
|
||||
'directory': dir_stack[-1],
|
||||
'command': ' '.join(new_line_parts).strip(),
|
||||
'file': '{}/{}'.format(rootdir, src_file)
|
||||
'file': os.path.join(dir_stack[-1], src_file)
|
||||
}
|
||||
|
||||
compile_db.append(db_entry)
|
||||
|
||||
Reference in New Issue
Block a user