.ycm_extra_conf.py revision 0d8efe3535b3ce9ecbc2c6482007edfc3ac492d0
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringimport itertools
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringimport os
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringimport subprocess
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringdef GetFlagsFromMakefile(varname):
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return subprocess.check_output([
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers "make", "-s", "print-%s" % varname]).decode().split()
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringdef Flatten(lists):
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return list(itertools.chain.from_iterable(lists))
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringdef DirectoryOfThisScript():
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return os.path.dirname(os.path.abspath(__file__))
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringdef MakeRelativePathsInFlagsAbsolute(flags, working_directory):
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if not working_directory:
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return flags
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering new_flags = []
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering make_next_absolute = False
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering for flag in flags:
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering new_flag = flag
a9cdc94f7ff40f22a3cf9472f612a80730a1b010Dave Reisner
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if make_next_absolute:
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen make_next_absolute = False
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen if not flag.startswith('/'):
a281d9c7851b16c4c9195d042901540ee9ced799Thomas Hindoe Paaboel Andersen new_flag = os.path.join(working_directory, flag)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering for path_flag in path_flags:
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if flag == path_flag:
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering make_next_absolute = True
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering break
288a74cce597f81d3ba01d8a5ca7d2ba5b654b7eRonny Chevalier
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering if flag.startswith(path_flag):
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering path = flag[ len(path_flag): ]
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering new_flag = path_flag + os.path.join(working_directory, path)
e1636421f46db6d06fbd028ef20a3113fa3e11f8Lennart Poettering break
7085053a437456ab87d726f3697002dd811fdf7aDaniel Wallace
e1636421f46db6d06fbd028ef20a3113fa3e11f8Lennart Poettering if new_flag:
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering new_flags.append(new_flag)
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return new_flags
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringdef FlagsForFile(filename):
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering relative_to = DirectoryOfThisScript()
1b12a7b5896f94bdf33b3a6661ebabd761ea6adcHarald Hoyer
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering return {
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering 'flags': MakeRelativePathsInFlagsAbsolute(flags, relative_to),
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering 'do_cache': True
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering }
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringflags = Flatten(map(GetFlagsFromMakefile, [
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering 'AM_CPPFLAGS',
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering 'CPPFLAGS',
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering 'AM_CFLAGS',
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering 'CFLAGS',
46e65dcc3a522b5e992e165b5e61d14254026859Lennart Poettering]))
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poettering# these flags cause crashes in libclang, so remove them
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringflags.remove('-Wlogical-op')
6d0274f11547a0f11200bb82bf598a5a253e12cfLennart Poetteringflags.remove('-Wsuggest-attribute=noreturn')
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers
ffc06c3513d9a0693c7f810d03b20705127ba55aKay Sievers# vim: set et ts=2 sw=2:
2f6a59070559786428d9eaf199ae3d61772b2225Kay Sievers