Skip to content

Instantly share code, notes, and snippets.

@teki
Created March 14, 2017 23:04
Show Gist options
  • Save teki/84816c5a6311b095a180a47996961ad3 to your computer and use it in GitHub Desktop.
Save teki/84816c5a6311b095a180a47996961ad3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import json
import sys
import re
import subprocess
incdirs = set()
with open("compile_commands.json") as fp:
cc = json.load(fp)
for comp in cc:
for inc in re.findall(r"-I(/\S+)", comp[u'command']):
incdirs.add(inc)
clangout = subprocess.check_output("clang++ -E -x c++ - -v < /dev/null 2>&1", shell=True)
for line in clangout:
for inc in re.findall(r" (/Appl.*include)", line):
incdirs.add(inc)
with open(".vscode/c_cpp_properties.json") as fp:
props = json.load(fp)
for idx, conf in enumerate(props[u'configurations']):
if conf[u'name'] == u'Mac':
props[u'configurations'][idx]['includePath'] = list(incdirs)
with open(".vscode/c_cpp_properties.json", 'w') as fp:
json.dump(props, fp, indent=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment