]> git.ipfire.org Git - thirdparty/systemd.git/blame - .ycm_extra_conf.py
Add YouCompleteMe configuration
[thirdparty/systemd.git] / .ycm_extra_conf.py
CommitLineData
328b5bc9
DR
1import os
2import ycm_core
3from clang_helpers import PrepareClangFlags
4
5compilation_database_folder = ''
6
7flags = [
8'-include',
9'./config.h',
10'-I',
11'/usr/include/dbus-1.0',
12'-I',
13'./src/shared',
14'-Wall',
15'-Wextra',
16'-Werror',
17'-Wno-long-long',
18'-Wno-variadic-macros',
19'-fexceptions',
20'-DNDEBUG',
21'-DUSE_CLANG_COMPLETER',
22'-D_GNU_SOURCE',
23'-std=c99',
24]
25
26if compilation_database_folder:
27 database = ycm_core.CompilationDatabase(compilation_database_folder)
28else:
29 database = None
30
31
32def DirectoryOfThisScript():
33 return os.path.dirname(os.path.abspath(__file__))
34
35
36def MakeRelativePathsInFlagsAbsolute(flags, working_directory):
37 if not working_directory:
38 return flags
39 new_flags = []
40 make_next_absolute = False
41 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
42 for flag in flags:
43 new_flag = flag
44
45 if make_next_absolute:
46 make_next_absolute = False
47 if not flag.startswith('/'):
48 new_flag = os.path.join(working_directory, flag)
49
50 for path_flag in path_flags:
51 if flag == path_flag:
52 make_next_absolute = True
53 break
54
55 if flag.startswith(path_flag):
56 path = flag[ len(path_flag): ]
57 new_flag = path_flag + os.path.join(working_directory, path)
58 break
59
60 if new_flag:
61 new_flags.append(new_flag)
62 return new_flags
63
64
65def FlagsForFile(filename):
66 if database:
67 compilation_info = database.GetCompilationInfoForFile(filename)
68 final_flags = PrepareClangFlags(
69 MakeRelativePathsInFlagsAbsolute(
70 compilation_info.compiler_flags_,
71 compilation_info.compiler_working_dir_),
72 filename)
73
74 else:
75 relative_to = DirectoryOfThisScript()
76 final_flags = MakeRelativePathsInFlagsAbsolute(flags, relative_to)
77
78 return {
79 'flags': final_flags,
80 'do_cache': True
81 }