notify gitter on travis build failures
[sddekit.git] / .ycm_extra_conf.py
blob1cc900989987ac6bb332d9ad7132814edfc7dede
1 #!/usr/bin/env python
3 # Copyright (C) 2014 Google Inc.
5 # This file is part of YouCompleteMe.
7 # YouCompleteMe is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # YouCompleteMe is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
20 import os
21 import ycm_core
23 # These are the compilation flags that will be used in case there's no
24 # compilation database set (by default, one is not set).
25 # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
26 flags = [
27 '-Wall', '-Wextra', '-Wpedantic', '-fexceptions', '-fstrict-aliasing',
28 '-I', './include', '-isystem', '/usr/include', '-isystem', '/usr/local/include',
29 '-DSKDEBUG',
32 cflags = flags + [ '-std=ansi', '-x', 'c', ]
33 cxxflags = flags + [ '-std=c++11', '-x', 'c++' ]
35 mex_flags = []
36 if 'MATLAB' in os.environ:
37 mex_flags.append('-I%s/extern/include' % (
38 os.path.abspath(os.environ['MATLAB'])))
40 print mex_flags
42 # Set this to the absolute path to the folder (NOT the file!) containing the
43 # compile_commands.json file to use that instead of 'flags'. See here for
44 # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
46 # Most projects will NOT need to set this to anything; you can just change the
47 # 'flags' list of compilation flags.
48 compilation_database_folder = ''
50 if os.path.exists( compilation_database_folder ):
51 database = ycm_core.CompilationDatabase( compilation_database_folder )
52 else:
53 database = None
55 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
57 def DirectoryOfThisScript():
58 return os.path.dirname( os.path.abspath( __file__ ) )
61 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
62 if not working_directory:
63 return list( flags )
64 new_flags = []
65 make_next_absolute = False
66 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
67 for flag in flags:
68 new_flag = flag
70 if make_next_absolute:
71 make_next_absolute = False
72 if not flag.startswith( '/' ):
73 new_flag = os.path.join( working_directory, flag )
75 for path_flag in path_flags:
76 if flag == path_flag:
77 make_next_absolute = True
78 break
80 if flag.startswith( path_flag ):
81 path = flag[ len( path_flag ): ]
82 new_flag = path_flag + os.path.join( working_directory, path )
83 break
85 if new_flag:
86 new_flags.append( new_flag )
87 return new_flags
90 def IsHeaderFile( filename ):
91 extension = os.path.splitext( filename )[ 1 ]
92 return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
95 def GetCompilationInfoForFile( filename ):
96 # The compilation_commands.json file generated by CMake does not have entries
97 # for header files. So we do our best by asking the db for flags for a
98 # corresponding source file, if any. If one exists, the flags for that file
99 # should be good enough.
100 if IsHeaderFile( filename ):
101 basename = os.path.splitext( filename )[ 0 ]
102 for extension in SOURCE_EXTENSIONS:
103 replacement_file = basename + extension
104 if os.path.exists( replacement_file ):
105 compilation_info = database.GetCompilationInfoForFile(
106 replacement_file )
107 if compilation_info.compiler_flags_:
108 return compilation_info
109 return None
110 return database.GetCompilationInfoForFile( filename )
113 # This is the entry point; this function is called by ycmd to produce flags for
114 # a file.
115 def FlagsForFile( filename, **kwargs ):
116 if database:
117 # Bear in mind that compilation_info.compiler_flags_ does NOT return a
118 # python list, but a "list-like" StringVec object
119 compilation_info = GetCompilationInfoForFile( filename )
120 if not compilation_info:
121 return None
123 final_flags = MakeRelativePathsInFlagsAbsolute(
124 compilation_info.compiler_flags_,
125 compilation_info.compiler_working_dir_ )
126 else:
127 relative_to = DirectoryOfThisScript()
128 final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
130 if 'matlab' in filename:
131 final_flags += mex_flags
133 return {
134 'flags': final_flags,
135 'do_cache': True