mirror of
https://github.com/systemd/systemd.git
synced 2024-12-22 17:35:35 +03:00
ycm: autocompose flags from the Makefile
This should hopefully be self-maintaining.
This commit is contained in:
parent
8042e377b8
commit
0d8efe3535
@ -1,34 +1,14 @@
|
|||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
import ycm_core
|
import subprocess
|
||||||
from clang_helpers import PrepareClangFlags
|
|
||||||
|
|
||||||
compilation_database_folder = ''
|
def GetFlagsFromMakefile(varname):
|
||||||
|
return subprocess.check_output([
|
||||||
|
"make", "-s", "print-%s" % varname]).decode().split()
|
||||||
|
|
||||||
flags = [
|
|
||||||
'-include',
|
|
||||||
'./config.h',
|
|
||||||
'-I',
|
|
||||||
'/usr/include/dbus-1.0',
|
|
||||||
'-I',
|
|
||||||
'./src/shared',
|
|
||||||
'-I',
|
|
||||||
'./src/systemd',
|
|
||||||
'-Wall',
|
|
||||||
'-Wextra',
|
|
||||||
'-Werror',
|
|
||||||
'-Wno-long-long',
|
|
||||||
'-Wno-variadic-macros',
|
|
||||||
'-fexceptions',
|
|
||||||
'-DNDEBUG',
|
|
||||||
'-DUSE_CLANG_COMPLETER',
|
|
||||||
'-D_GNU_SOURCE',
|
|
||||||
'-std=c99',
|
|
||||||
]
|
|
||||||
|
|
||||||
if compilation_database_folder:
|
def Flatten(lists):
|
||||||
database = ycm_core.CompilationDatabase(compilation_database_folder)
|
return list(itertools.chain.from_iterable(lists))
|
||||||
else:
|
|
||||||
database = None
|
|
||||||
|
|
||||||
|
|
||||||
def DirectoryOfThisScript():
|
def DirectoryOfThisScript():
|
||||||
@ -65,19 +45,22 @@ def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
|
|||||||
|
|
||||||
|
|
||||||
def FlagsForFile(filename):
|
def FlagsForFile(filename):
|
||||||
if database:
|
relative_to = DirectoryOfThisScript()
|
||||||
compilation_info = database.GetCompilationInfoForFile(filename)
|
|
||||||
final_flags = PrepareClangFlags(
|
|
||||||
MakeRelativePathsInFlagsAbsolute(
|
|
||||||
compilation_info.compiler_flags_,
|
|
||||||
compilation_info.compiler_working_dir_),
|
|
||||||
filename)
|
|
||||||
|
|
||||||
else:
|
|
||||||
relative_to = DirectoryOfThisScript()
|
|
||||||
final_flags = MakeRelativePathsInFlagsAbsolute(flags, relative_to)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'flags': final_flags,
|
'flags': MakeRelativePathsInFlagsAbsolute(flags, relative_to),
|
||||||
'do_cache': True
|
'do_cache': True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flags = Flatten(map(GetFlagsFromMakefile, [
|
||||||
|
'AM_CPPFLAGS',
|
||||||
|
'CPPFLAGS',
|
||||||
|
'AM_CFLAGS',
|
||||||
|
'CFLAGS',
|
||||||
|
]))
|
||||||
|
|
||||||
|
# these flags cause crashes in libclang, so remove them
|
||||||
|
flags.remove('-Wlogical-op')
|
||||||
|
flags.remove('-Wsuggest-attribute=noreturn')
|
||||||
|
|
||||||
|
# vim: set et ts=2 sw=2:
|
||||||
|
@ -5081,3 +5081,7 @@ tests += \
|
|||||||
|
|
||||||
cppcheck:
|
cppcheck:
|
||||||
cppcheck --enable=all -q $(top_srcdir)
|
cppcheck --enable=all -q $(top_srcdir)
|
||||||
|
|
||||||
|
# Used to extract compile flags for YCM.
|
||||||
|
print-%:
|
||||||
|
@echo $($*)
|
||||||
|
Loading…
Reference in New Issue
Block a user