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