lib: Remove tdb_compat
[nivanova/samba-autobuild/.git] / .ycm_extra_conf.py
1 # This file is NOT licensed under the GPLv3, which is the license for the rest
2 # of Samba.
3 #
4 # Here's the license text for this file:
5 #
6 # This is free and unencumbered software released into the public domain.
7 #
8 # Anyone is free to copy, modify, publish, use, compile, sell, or
9 # distribute this software, either in source code form or as a compiled
10 # binary, for any purpose, commercial or non-commercial, and by any
11 # means.
12 #
13 # In jurisdictions that recognize copyright laws, the author or authors
14 # of this software dedicate any and all copyright interest in the
15 # software to the public domain. We make this dedication for the benefit
16 # of the public at large and to the detriment of our heirs and
17 # successors. We intend this dedication to be an overt act of
18 # relinquishment in perpetuity of all present and future rights to this
19 # software under copyright law.
20 #
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 # OTHER DEALINGS IN THE SOFTWARE.
28 #
29 # For more information, please refer to <http://unlicense.org/>
30
31 import os
32 import ycm_core
33
34 flags = [
35 '-Wall',
36 '-Wextra',
37 '-Werror',
38 '-Wno-unused-parameter',
39 # This is a C project
40 '-x', 'c',
41 # Defines
42 '-DCONFIG_H_IS_FROM_SAMBA=1',
43 '-DHAVE_CONFIG_H=1',
44 '-D_SAMBA_BUILD_=4',
45 '-DAD_DC_BUILD_IS_ENABLED=1',
46 '-D_GNU_SOURCE=1',
47 '-DHAVE_IPV6=1',
48 # Includes
49 '-I.',
50 '-Iauth',
51 '-Iauth/credentials',
52 '-Iauth/gensec',
53 '-Iauth/kerberos',
54 '-Iauth/ntlmssp',
55 '-Idfs_server',
56 '-Idynconfig',
57 '-Iinclude',
58 '-Iinclude/public',
59 '-Ilib',
60 '-Ilib/addns',
61 '-Ilib/async_req',
62 '-Ilib/ccan',
63 '-Ilib/compression',
64 '-Ilib/crypto',
65 '-Ilib/dbwrap',
66 '-Ilib/krb5_wrap',
67 '-Ilib/ldb',
68 '-Ilib/ldb-samba',
69 '-Ilib/ldb/include',
70 '-Ilib/param',
71 '-Ilib/replace',
72 '-Ilib/smbconf',
73 '-Ilib/socket',
74 '-Ilib/talloc',
75 '-Ilib/tdb',
76 '-Ilib/tdb/include',
77 '-Ilib/tevent',
78 '-Ilib/tsocket',
79 '-Ilib/util/charset',
80 '-Ilibcli/auth',
81 '-Ilibcli/cldap',
82 '-Ilibcli/dns',
83 '-Ilibcli/drsuapi',
84 '-Ilibcli/ldap',
85 '-Ilibcli/lsarpc',
86 '-Ilibcli/named_pipe_auth',
87 '-Ilibcli/nbt',
88 '-Ilibcli/netlogon',
89 '-Ilibcli/registry',
90 '-Ilibcli/security',
91 '-Ilibcli/smb',
92 '-Ilibcli/util',
93 '-Ilibds/common',
94 '-Ilibrpc',
95 '-Insswitch',
96 '-Insswitch/libwbclient',
97 '-Isource3',
98 '-Isource3/auth',
99 '-Isource3/include',
100 '-Isource3/lib',
101 '-Isource3/lib/asys',
102 '-Isource3/lib/pthreadpool',
103 '-Isource3/librpc',
104 '-Isource3/modules',
105 '-Isource3/passdb',
106 '-Isource3/rpc_server',
107 '-Isource4',
108 '-Isource4/auth',
109 '-Isource4/auth/gensec',
110 '-Isource4/auth/kerberos',
111 '-Isource4/dsdb',
112 '-Isource4/include',
113 '-Isource4/lib',
114 '-Isource4/lib/events',
115 '-Isource4/lib/socket',
116 '-Isource4/lib/stream',
117 '-Isource4/lib/tls',
118 '-Isource4/libcli',
119 '-Isource4/libcli/ldap',
120 '-Isource4/param',
121 '-Isource4/winbind',
122 # Generated headers
123 '-Ibin/default',
124 '-Ibin/default/auth/credentials',
125 '-Ibin/default/auth/gensec',
126 '-Ibin/default/file_server',
127 '-Ibin/default/include',
128 '-Ibin/default/include/public',
129 '-Ibin/default/include/public/core',
130 '-Ibin/default/include/public/gen_ndr',
131 '-Ibin/default/include/public/ndr',
132 '-Ibin/default/include/public/samba',
133 '-Ibin/default/include/public/util',
134 '-Ibin/default/libcli/nbt',
135 '-Ibin/default/lib/crypto',
136 '-Ibin/default/lib/ldb/include',
137 '-Ibin/default/lib/ldb-samba',
138 '-Ibin/default/lib/param',
139 '-Ibin/default/librpc/gen_ndr',
140 '-Ibin/default/lib/util',
141 '-Ibin/default/source3/include',
142 '-Ibin/default/source3/librpc/gen_ndr',
143 '-Ibin/default/source3/param',
144 '-Ibin/default/source4/auth',
145 '-Ibin/default/source4/auth/gensec',
146 '-Ibin/default/source4/auth/kerberos',
147 '-Ibin/default/source4/auth/ntlm',
148 '-Ibin/default/source4/cldap_server',
149 '-Ibin/default/source4/dsdb/common',
150 '-Ibin/default/source4/dsdb/kcc',
151 '-Ibin/default/source4/dsdb/repl',
152 '-Ibin/default/source4/dsdb/samdb',
153 '-Ibin/default/source4/dsdb/samdb/ldb_modules',
154 '-Ibin/default/source4/dsdb/schema',
155 '-Ibin/default/source4/heimdal/kdc',
156 '-Ibin/default/source4/heimdal/lib/asn1',
157 '-Ibin/default/source4/heimdal/lib/gssapi',
158 '-Ibin/default/source4/heimdal/lib/gssapi/krb5',
159 '-Ibin/default/source4/heimdal/lib/gssapi/spnego',
160 '-Ibin/default/source4/heimdal/lib/hdb',
161 '-Ibin/default/source4/heimdal/lib/hx509',
162 '-Ibin/default/source4/heimdal/lib/krb5',
163 '-Ibin/default/source4/heimdal/lib/ntlm',
164 '-Ibin/default/source4/heimdal/lib/wind',
165 '-Ibin/default/source4/ldap_server',
166 '-Ibin/default/source4/libcli',
167 '-Ibin/default/source4/libcli/composite',
168 '-Ibin/default/source4/libcli/ldap',
169 '-Ibin/default/source4/libcli/rap',
170 '-Ibin/default/source4/libcli/raw',
171 '-Ibin/default/source4/libcli/resolve',
172 '-Ibin/default/source4/libcli/smb2',
173 '-Ibin/default/source4/libcli/util',
174 '-Ibin/default/source4/libcli/wrepl',
175 '-Ibin/default/source4/lib/cmdline',
176 '-Ibin/default/source4/libnet',
177 '-Ibin/default/source4/lib/registry',
178 '-Ibin/default/source4/lib/registry/tests',
179 '-Ibin/default/source4/lib/registry/tools',
180 '-Ibin/default/source4/librpc/gen_ndr',
181 '-Ibin/default/source4/librpc/rpc',
182 '-Ibin/default/source4/lib/socket',
183 '-Ibin/default/source4/nbt_server',
184 '-Ibin/default/source4/nbt_server/dgram',
185 '-Ibin/default/source4/nbt_server/wins',
186 '-Ibin/default/source4/ntptr',
187 '-Ibin/default/source4/ntvfs',
188 '-Ibin/default/source4/ntvfs/cifs_posix_cli',
189 '-Ibin/default/source4/ntvfs/common',
190 '-Ibin/default/source4/ntvfs/ipc',
191 '-Ibin/default/source4/ntvfs/posix',
192 '-Ibin/default/source4/ntvfs/simple',
193 '-Ibin/default/source4/rpc_server',
194 '-Ibin/default/source4/rpc_server/backupkey',
195 '-Ibin/default/source4/rpc_server/common',
196 '-Ibin/default/source4/rpc_server/lsa',
197 '-Ibin/default/source4/rpc_server/samr',
198 '-Ibin/default/source4/rpc_server/srvsvc',
199 '-Ibin/default/source4/smbd',
200 '-Ibin/default/source4/smb_server',
201 '-Ibin/default/source4/smb_server/smb',
202 '-Ibin/default/source4/smb_server/smb2',
203 '-Ibin/default/source4/torture/auth',
204 '-Ibin/default/source4/torture/basic',
205 '-Ibin/default/source4/torture/dfs',
206 '-Ibin/default/source4/torture/drs',
207 '-Ibin/default/source4/torture/ldap',
208 '-Ibin/default/source4/torture/libnet',
209 '-Ibin/default/source4/torture/libnetapi',
210 '-Ibin/default/source4/torture/libsmbclient',
211 '-Ibin/default/source4/torture/local',
212 '-Ibin/default/source4/torture/nbench',
213 '-Ibin/default/source4/torture/nbt',
214 '-Ibin/default/source4/torture/ndr',
215 '-Ibin/default/source4/torture/ntp',
216 '-Ibin/default/source4/torture/rap',
217 '-Ibin/default/source4/torture/raw',
218 '-Ibin/default/source4/torture/rpc',
219 '-Ibin/default/source4/torture/smb2',
220 '-Ibin/default/source4/torture/unix',
221 '-Ibin/default/source4/torture/winbind',
222 '-Ibin/default/source4/winbind',
223 '-Ibin/default/source4/wrepl_server',
224 '-Ibin/default/testsuite/headers',
225 ]
226
227 # Set this to the absolute path to the folder (NOT the file!) containing the
228 # compile_commands.json file to use that instead of 'flags'. See here for
229 # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
230 #
231 # Most projects will NOT need to set this to anything; you can just change the
232 # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
233 compilation_database_folder = ''
234
235 if os.path.exists( compilation_database_folder ):
236   database = ycm_core.CompilationDatabase( compilation_database_folder )
237 else:
238   database = None
239
240 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
241
242 def DirectoryOfThisScript():
243   return os.path.dirname( os.path.abspath( __file__ ) )
244
245
246 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
247   if not working_directory:
248     return list( flags )
249   new_flags = []
250   make_next_absolute = False
251   path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
252   for flag in flags:
253     new_flag = flag
254
255     if make_next_absolute:
256       make_next_absolute = False
257       if not flag.startswith( '/' ):
258         new_flag = os.path.join( working_directory, flag )
259
260     for path_flag in path_flags:
261       if flag == path_flag:
262         make_next_absolute = True
263         break
264
265       if flag.startswith( path_flag ):
266         path = flag[ len( path_flag ): ]
267         new_flag = path_flag + os.path.join( working_directory, path )
268         break
269
270     if new_flag:
271       new_flags.append( new_flag )
272   return new_flags
273
274
275 def IsHeaderFile( filename ):
276   extension = os.path.splitext( filename )[ 1 ]
277   return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
278
279
280 def GetCompilationInfoForFile( filename ):
281   # The compilation_commands.json file generated by CMake does not have entries
282   # for header files. So we do our best by asking the db for flags for a
283   # corresponding source file, if any. If one exists, the flags for that file
284   # should be good enough.
285   if IsHeaderFile( filename ):
286     basename = os.path.splitext( filename )[ 0 ]
287     for extension in SOURCE_EXTENSIONS:
288       replacement_file = basename + extension
289       if os.path.exists( replacement_file ):
290         compilation_info = database.GetCompilationInfoForFile(
291           replacement_file )
292         if compilation_info.compiler_flags_:
293           return compilation_info
294     return None
295   return database.GetCompilationInfoForFile( filename )
296
297
298 def FlagsForFile( filename, **kwargs ):
299   if database:
300     # Bear in mind that compilation_info.compiler_flags_ does NOT return a
301     # python list, but a "list-like" StringVec object
302     compilation_info = GetCompilationInfoForFile( filename )
303     if not compilation_info:
304       return None
305
306     final_flags = MakeRelativePathsInFlagsAbsolute(
307       compilation_info.compiler_flags_,
308       compilation_info.compiler_working_dir_ )
309   else:
310     relative_to = DirectoryOfThisScript()
311     final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
312
313   return {
314     'flags': final_flags,
315     'do_cache': True
316   }