Created
July 11, 2017 22:14
-
-
Save aldanor/0c16c63c8461eb72f4f10349636a0260 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import os | |
import shlex | |
import sys | |
def extract_includes(): | |
cwd = os.getcwd() | |
cc1 = os.path.join(cwd, 'cmake', 'compile_commands.json') | |
cc2 = os.path.join(cwd, 'compile_commands.json') | |
if os.path.isfile(cc2): | |
cc = cc2 | |
elif os.path.isfile(cc1): | |
cc = cc1 | |
else: | |
return [] | |
with open(cc, 'r') as f: | |
cc = json.load(f) | |
includes, sys_includes = [], [] | |
for entry in cc: | |
next_path = None | |
for flag in shlex.split(entry.get('command', '')): | |
if next_path is not None: | |
next_path.append(flag) | |
next_path = None | |
else: | |
if flag == '-I': | |
next_path = includes | |
elif flag == '-isystem': | |
next_path = sys_includes | |
elif flag.startswith('-I'): | |
includes.append(flag.lstrip('-I')) | |
elif flag.startswith('-isystem'): | |
includes.append(flag.lstrip('-isystem')) | |
flags = [] | |
for path in sorted(set(sys_includes)): | |
flags.append('-isystem') | |
flags.append(path) | |
for path in sorted(set(includes)): | |
flags.append('-I' + path) | |
return flags | |
def FlagsForFile(filename, **kwargs): | |
flags =['-x', 'c++', '-std=c++1z', '-Wall', '-Wextra', '-Werror'] | |
flags += extract_includes() | |
return {'flags': flags, 'do_cache': True} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment