00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import os
00032 import ycm_core
00033
00034
00035
00036
00037 flags = [
00038 '-Wall',
00039 '-Wextra',
00040 '-Werror',
00041 '-Wno-long-long',
00042 '-Wno-variadic-macros',
00043 '-fexceptions',
00044 '-DNDEBUG',
00045
00046
00047 '-DUSE_CLANG_COMPLETER',
00048
00049
00050
00051
00052
00053
00054 '-std=c++11',
00055
00056
00057
00058
00059 '-x',
00060 'c++',
00061 '-isystem', '../BoostParts',
00062 '-isystem', '/System/Library/Frameworks/Python.framework/Headers',
00063 '-isystem', '../llvm/include',
00064 '-isystem', '../llvm/tools/clang/include',
00065 '-I', '.',
00066 '-I', './ClangCompleter',
00067 '-isystem', './tests/gmock/gtest',
00068 '-isystem', './tests/gmock/gtest/include',
00069 '-isystem', './tests/gmock',
00070 '-isystem', './tests/gmock/include',
00071 '-I', '/usr/local/include',
00072 '-I', 'include',
00073 '-I', '/usr/lib/gcc/x86_64-linux-gnu/4.9/include',
00074 '-I', '/usr/include/x86_64-linux-gnu',
00075 '-I', '/usr/include'
00076
00077 ]
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 compilation_database_folder = ''
00091
00092 if os.path.exists( compilation_database_folder ):
00093 database = ycm_core.CompilationDatabase( compilation_database_folder )
00094 else:
00095 database = None
00096
00097 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
00098
00099 def DirectoryOfThisScript():
00100 return os.path.dirname( os.path.abspath( __file__ ) )
00101
00102
00103 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
00104 if not working_directory:
00105 return list( flags )
00106 new_flags = []
00107 make_next_absolute = False
00108 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
00109 for flag in flags:
00110 new_flag = flag
00111
00112 if make_next_absolute:
00113 make_next_absolute = False
00114 if not flag.startswith( '/' ):
00115 new_flag = os.path.join( working_directory, flag )
00116
00117 for path_flag in path_flags:
00118 if flag == path_flag:
00119 make_next_absolute = True
00120 break
00121
00122 if flag.startswith( path_flag ):
00123 path = flag[ len( path_flag ): ]
00124 new_flag = path_flag + os.path.join( working_directory, path )
00125 break
00126
00127 if new_flag:
00128 new_flags.append( new_flag )
00129 return new_flags
00130
00131
00132 def IsHeaderFile( filename ):
00133 extension = os.path.splitext( filename )[ 1 ]
00134 return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
00135
00136
00137 def GetCompilationInfoForFile( filename ):
00138
00139
00140
00141
00142 if IsHeaderFile( filename ):
00143 basename = os.path.splitext( filename )[ 0 ]
00144 for extension in SOURCE_EXTENSIONS:
00145 replacement_file = basename + extension
00146 if os.path.exists( replacement_file ):
00147 compilation_info = database.GetCompilationInfoForFile(
00148 replacement_file )
00149 if compilation_info.compiler_flags_:
00150 return compilation_info
00151 return None
00152 return database.GetCompilationInfoForFile( filename )
00153
00154
00155 def FlagsForFile( filename, **kwargs ):
00156 if database:
00157
00158
00159 compilation_info = GetCompilationInfoForFile( filename )
00160 if not compilation_info:
00161 return None
00162
00163 final_flags = MakeRelativePathsInFlagsAbsolute(
00164 compilation_info.compiler_flags_,
00165 compilation_info.compiler_working_dir_ )
00166
00167 else:
00168 relative_to = DirectoryOfThisScript()
00169 final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
00170
00171 return {
00172 'flags': final_flags,
00173 'do_cache': True
00174 }