Go to the documentation of this file.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 '-fexceptions',
00042
00043
00044
00045
00046
00047
00048 '-std=c++03',
00049
00050
00051
00052
00053 '-x',
00054 'c++',
00055 '-isystem', "/opt/ros/%s/include" % os.environ.get('ROS_DISTRO', 'indigo'),
00056 '-isystem', '/usr/include/Poco',
00057 '-isystem', '/usr/include',
00058 '-I', '.',
00059 '-I', './include',
00060 '-I', '../devel/include',
00061
00062 '-DROSCONSOLE_BACKEND_LOG4CXX',
00063
00064 ]
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 compilation_database_folder = ''
00077
00078 if os.path.exists( compilation_database_folder ):
00079 database = ycm_core.CompilationDatabase( compilation_database_folder )
00080 else:
00081 database = None
00082
00083 SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
00084
00085 def DirectoryOfThisScript():
00086 return os.path.dirname( os.path.abspath( __file__ ) )
00087
00088
00089 def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
00090 if not working_directory:
00091 return list( flags )
00092 new_flags = []
00093 make_next_absolute = False
00094 path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
00095 for flag in flags:
00096 new_flag = flag
00097
00098 if make_next_absolute:
00099 make_next_absolute = False
00100 if not flag.startswith( '/' ):
00101 new_flag = os.path.join( working_directory, flag )
00102
00103 for path_flag in path_flags:
00104 if flag == path_flag:
00105 make_next_absolute = True
00106 break
00107
00108 if flag.startswith( path_flag ):
00109 path = flag[ len( path_flag ): ]
00110 new_flag = path_flag + os.path.join( working_directory, path )
00111 break
00112
00113 if new_flag:
00114 new_flags.append( new_flag )
00115 return new_flags
00116
00117
00118 def IsHeaderFile( filename ):
00119 extension = os.path.splitext( filename )[ 1 ]
00120 return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
00121
00122
00123 def GetCompilationInfoForFile( filename ):
00124
00125
00126
00127
00128 if IsHeaderFile( filename ):
00129 basename = os.path.splitext( filename )[ 0 ]
00130 for extension in SOURCE_EXTENSIONS:
00131 replacement_file = basename + extension
00132 if os.path.exists( replacement_file ):
00133 compilation_info = database.GetCompilationInfoForFile(
00134 replacement_file )
00135 if compilation_info.compiler_flags_:
00136 return compilation_info
00137 return None
00138 return database.GetCompilationInfoForFile( filename )
00139
00140
00141 def FlagsForFile( filename, **kwargs ):
00142 if database:
00143
00144
00145 compilation_info = GetCompilationInfoForFile( filename )
00146 if not compilation_info:
00147 return None
00148
00149 final_flags = MakeRelativePathsInFlagsAbsolute(
00150 compilation_info.compiler_flags_,
00151 compilation_info.compiler_working_dir_ )
00152 else:
00153 relative_to = DirectoryOfThisScript()
00154 final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
00155
00156 return {
00157 'flags': final_flags,
00158 'do_cache': True
00159 }