Skip to content

Instantly share code, notes, and snippets.

@casimir
Created May 19, 2015 10:45
Show Gist options
  • Save casimir/25edaa18c87cf3a55b82 to your computer and use it in GitHub Desktop.
Save casimir/25edaa18c87cf3a55b82 to your computer and use it in GitHub Desktop.
Global conf for ycmd that uses existing environnement variables and Makefiles
import os
import re
FlagsNames = {
'c': 'CFLAGS',
'c++': 'CXXFLAGS',
'objective-c': 'OBJCFLAGS',
}
def FlagsFromMakefile(var, flags):
raw = open('Makefile').read()
line = re.search(var + '\s*([+?]*=)([^\n]*)', raw)
if not line:
return flags
op = line.group(1)
val = line.group(2).strip()
mflags = val.split()
if op == '=':
return mflags
elif op == '+=':
return flags + mflags
elif op == '?=' and not flags:
return mflags
return flags
def FlagsForLang(lang):
var = FlagsNames[lang]
flags = os.getenv(var, '').split()
if os.path.isfile('Makefile'):
flags = FlagsFromMakefile(var, flags)
return flags
def FlagsForFile(filename, **kwargs):
ft = kwargs['client_data']['&filetype']
flags = []
lang = ft
if ft == 'cpp':
lang = 'c++'
flags += ['-std=c++11']
elif ft == 'objc':
lang = 'objective-c'
flags += FlagsForLang(lang) + ['-x', lang]
return {
'flags': flags,
'do_cache': True
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment