github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/src/.ycm_extra_conf.py (about)

     1  import os
     2  import ycm_core
     3  
     4  # These are the compilation flags that will be used in case there's no
     5  # compilation database set (by default, one is not set).
     6  # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
     7  flags = [
     8  '-Wall',
     9  '-Werror',
    10  '-std=c++0x',
    11  '-x',
    12  'c++',
    13  '-I',
    14  '.',
    15  '-I',
    16  './third_party/gflags/src',
    17  '-I',
    18  './third_party/google-glog/src',
    19  '-I',
    20  './third_party/keyczar/cpp/src',
    21  '-I',
    22  './third_party/googlemock/include',
    23  '-I',
    24  './third_party/googlemock/gtest/include',
    25  '-I',
    26  './third_party/protobuf/src',
    27  '-I',
    28  './out/Release/gen',
    29  ]
    30  
    31  
    32  # Set this to the absolute path to the folder (NOT the file!) containing the
    33  # compile_commands.json file to use that instead of 'flags'. See here for
    34  # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
    35  #
    36  # Most projects will NOT need to set this to anything; you can just change the
    37  # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
    38  compilation_database_folder = ''
    39  
    40  if os.path.exists( compilation_database_folder ):
    41    database = ycm_core.CompilationDatabase( compilation_database_folder )
    42  else:
    43    database = None
    44  
    45  SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
    46  
    47  def DirectoryOfThisScript():
    48    return os.path.dirname( os.path.abspath( __file__ ) )
    49  
    50  
    51  def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
    52    if not working_directory:
    53      return list( flags )
    54    new_flags = []
    55    make_next_absolute = False
    56    path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
    57    for flag in flags:
    58      new_flag = flag
    59  
    60      if make_next_absolute:
    61        make_next_absolute = False
    62        if not flag.startswith( '/' ):
    63          new_flag = os.path.join( working_directory, flag )
    64  
    65      for path_flag in path_flags:
    66        if flag == path_flag:
    67          make_next_absolute = True
    68          break
    69  
    70        if flag.startswith( path_flag ):
    71          path = flag[ len( path_flag ): ]
    72          new_flag = path_flag + os.path.join( working_directory, path )
    73          break
    74  
    75      if new_flag:
    76        new_flags.append( new_flag )
    77    return new_flags
    78  
    79  
    80  def IsHeaderFile( filename ):
    81    extension = os.path.splitext( filename )[ 1 ]
    82    return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
    83  
    84  
    85  def GetCompilationInfoForFile( filename ):
    86    # The compilation_commands.json file generated by CMake does not have entries
    87    # for header files. So we do our best by asking the db for flags for a
    88    # corresponding source file, if any. If one exists, the flags for that file
    89    # should be good enough.
    90    if IsHeaderFile( filename ):
    91      basename = os.path.splitext( filename )[ 0 ]
    92      for extension in SOURCE_EXTENSIONS:
    93        replacement_file = basename + extension
    94        if os.path.exists( replacement_file ):
    95          compilation_info = database.GetCompilationInfoForFile(
    96            replacement_file )
    97          if compilation_info.compiler_flags_:
    98            return compilation_info
    99      return None
   100    return database.GetCompilationInfoForFile( filename )
   101  
   102  
   103  def FlagsForFile( filename, **kwargs ):
   104    if database:
   105      # Bear in mind that compilation_info.compiler_flags_ does NOT return a
   106      # python list, but a "list-like" StringVec object
   107      compilation_info = GetCompilationInfoForFile( filename )
   108      if not compilation_info:
   109        return None
   110  
   111      final_flags = MakeRelativePathsInFlagsAbsolute(
   112        compilation_info.compiler_flags_,
   113        compilation_info.compiler_working_dir_ )
   114    else:
   115      relative_to = DirectoryOfThisScript()
   116      final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
   117  
   118    return {
   119      'flags': final_flags,
   120      'do_cache': True
   121    }