Blame .ycm_extra_conf.py

Packit Service 64969d
# This file is NOT licensed under the GPLv3, which is the license for the rest
Packit Service 64969d
# of YouCompleteMe.
Packit Service 64969d
#
Packit Service 64969d
# Here's the license text for this file:
Packit Service 64969d
#
Packit Service 64969d
# This is free and unencumbered software released into the public domain.
Packit Service 64969d
#
Packit Service 64969d
# Anyone is free to copy, modify, publish, use, compile, sell, or
Packit Service 64969d
# distribute this software, either in source code form or as a compiled
Packit Service 64969d
# binary, for any purpose, commercial or non-commercial, and by any
Packit Service 64969d
# means.
Packit Service 64969d
#
Packit Service 64969d
# In jurisdictions that recognize copyright laws, the author or authors
Packit Service 64969d
# of this software dedicate any and all copyright interest in the
Packit Service 64969d
# software to the public domain. We make this dedication for the benefit
Packit Service 64969d
# of the public at large and to the detriment of our heirs and
Packit Service 64969d
# successors. We intend this dedication to be an overt act of
Packit Service 64969d
# relinquishment in perpetuity of all present and future rights to this
Packit Service 64969d
# software under copyright law.
Packit Service 64969d
#
Packit Service 64969d
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service 64969d
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service 64969d
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Packit Service 64969d
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
Packit Service 64969d
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Packit Service 64969d
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Packit Service 64969d
# OTHER DEALINGS IN THE SOFTWARE.
Packit Service 64969d
#
Packit Service 64969d
# For more information, please refer to <http://unlicense.org/>
Packit Service 64969d
Packit Service 64969d
import os
Packit Service 64969d
import ycm_core
Packit Service 64969d
Packit Service 64969d
# These are the compilation flags that will be used in case there's no
Packit Service 64969d
# compilation database set (by default, one is not set).
Packit Service 64969d
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
Packit Service 64969d
flags = [
Packit Service 64969d
'-Wall',
Packit Service 64969d
'-Wextra',
Packit Service 64969d
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
Packit Service 64969d
# language to use when compiling headers. So it will guess. Badly. So C++
Packit Service 64969d
# headers will be compiled as C headers. You don't want that so ALWAYS specify
Packit Service 64969d
# a "-std=<something>".
Packit Service 64969d
# For a C project, you would set this to something like 'c99' instead of
Packit Service 64969d
# 'c++11'.
Packit Service 64969d
'-std=gnu90',
Packit Service 64969d
# ...and the same thing goes for the magic -x option which specifies the
Packit Service 64969d
# language that the files to be compiled are written in. This is mostly
Packit Service 64969d
# relevant for c++ headers.
Packit Service 64969d
# For a C project, you would set this to 'c' instead of 'c++'.
Packit Service 64969d
'-x',
Packit Service 64969d
'c',
Packit Service 64969d
'-I', './librabbitmq',
Packit Service 64969d
'-I', './librabbitmq/unix',
Packit Service 64969d
'-D', 'HAVE_POLL',
Packit Service 64969d
]
Packit Service 64969d
Packit Service 64969d
Packit Service 64969d
# Set this to the absolute path to the folder (NOT the file!) containing the
Packit Service 64969d
# compile_commands.json file to use that instead of 'flags'. See here for
Packit Service 64969d
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
Packit Service 64969d
#
Packit Service 64969d
# You can get CMake to generate this file for you by adding:
Packit Service 64969d
#   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
Packit Service 64969d
# to your CMakeLists.txt file.
Packit Service 64969d
#
Packit Service 64969d
# Most projects will NOT need to set this to anything; you can just change the
Packit Service 64969d
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
Packit Service 64969d
compilation_database_folder = ''
Packit Service 64969d
Packit Service 64969d
if os.path.exists( compilation_database_folder ):
Packit Service 64969d
  database = ycm_core.CompilationDatabase( compilation_database_folder )
Packit Service 64969d
else:
Packit Service 64969d
  database = None
Packit Service 64969d
Packit Service 64969d
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
Packit Service 64969d
Packit Service 64969d
def DirectoryOfThisScript():
Packit Service 64969d
  return os.path.dirname( os.path.abspath( __file__ ) )
Packit Service 64969d
Packit Service 64969d
Packit Service 64969d
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
Packit Service 64969d
  if not working_directory:
Packit Service 64969d
    return list( flags )
Packit Service 64969d
  new_flags = []
Packit Service 64969d
  make_next_absolute = False
Packit Service 64969d
  path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
Packit Service 64969d
  for flag in flags:
Packit Service 64969d
    new_flag = flag
Packit Service 64969d
Packit Service 64969d
    if make_next_absolute:
Packit Service 64969d
      make_next_absolute = False
Packit Service 64969d
      if not flag.startswith( '/' ):
Packit Service 64969d
        new_flag = os.path.join( working_directory, flag )
Packit Service 64969d
Packit Service 64969d
    for path_flag in path_flags:
Packit Service 64969d
      if flag == path_flag:
Packit Service 64969d
        make_next_absolute = True
Packit Service 64969d
        break
Packit Service 64969d
Packit Service 64969d
      if flag.startswith( path_flag ):
Packit Service 64969d
        path = flag[ len( path_flag ): ]
Packit Service 64969d
        new_flag = path_flag + os.path.join( working_directory, path )
Packit Service 64969d
        break
Packit Service 64969d
Packit Service 64969d
    if new_flag:
Packit Service 64969d
      new_flags.append( new_flag )
Packit Service 64969d
  return new_flags
Packit Service 64969d
Packit Service 64969d
Packit Service 64969d
def IsHeaderFile( filename ):
Packit Service 64969d
  extension = os.path.splitext( filename )[ 1 ]
Packit Service 64969d
  return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
Packit Service 64969d
Packit Service 64969d
Packit Service 64969d
def GetCompilationInfoForFile( filename ):
Packit Service 64969d
  # The compilation_commands.json file generated by CMake does not have entries
Packit Service 64969d
  # for header files. So we do our best by asking the db for flags for a
Packit Service 64969d
  # corresponding source file, if any. If one exists, the flags for that file
Packit Service 64969d
  # should be good enough.
Packit Service 64969d
  if IsHeaderFile( filename ):
Packit Service 64969d
    basename = os.path.splitext( filename )[ 0 ]
Packit Service 64969d
    for extension in SOURCE_EXTENSIONS:
Packit Service 64969d
      replacement_file = basename + extension
Packit Service 64969d
      if os.path.exists( replacement_file ):
Packit Service 64969d
        compilation_info = database.GetCompilationInfoForFile(
Packit Service 64969d
          replacement_file )
Packit Service 64969d
        if compilation_info.compiler_flags_:
Packit Service 64969d
          return compilation_info
Packit Service 64969d
    return None
Packit Service 64969d
  return database.GetCompilationInfoForFile( filename )
Packit Service 64969d
Packit Service 64969d
Packit Service 64969d
def FlagsForFile( filename, **kwargs ):
Packit Service 64969d
  if database:
Packit Service 64969d
    # Bear in mind that compilation_info.compiler_flags_ does NOT return a
Packit Service 64969d
    # python list, but a "list-like" StringVec object
Packit Service 64969d
    compilation_info = GetCompilationInfoForFile( filename )
Packit Service 64969d
    if not compilation_info:
Packit Service 64969d
      relative_to = DirectoryOfThisScript()
Packit Service 64969d
      return {
Packit Service 64969d
        'flags': MakeRelativePathsInFlagsAbsolute( flags, relative_to ),
Packit Service 64969d
        'do_cache': True
Packit Service 64969d
      }
Packit Service 64969d
Packit Service 64969d
    final_flags = MakeRelativePathsInFlagsAbsolute(
Packit Service 64969d
      compilation_info.compiler_flags_,
Packit Service 64969d
      compilation_info.compiler_working_dir_ )
Packit Service 64969d
Packit Service 64969d
  else:
Packit Service 64969d
    relative_to = DirectoryOfThisScript()
Packit Service 64969d
    final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
Packit Service 64969d
Packit Service 64969d
  return {
Packit Service 64969d
    'flags': final_flags,
Packit Service 64969d
    'do_cache': True
Packit Service 64969d
  }