Advertisement
Guest User

.ycm_extra_conf.py

a guest
Jan 17th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.21 KB | None | 0 0
  1. # Generated by YCM Generator at 2016-12-23 18:58:41.880840
  2.  
  3. # This file is NOT licensed under the GPLv3, which is the license for the rest
  4. # of YouCompleteMe.
  5. #
  6. # Here's the license text for this file:
  7. #
  8. # This is free and unencumbered software released into the public domain.
  9. #
  10. # Anyone is free to copy, modify, publish, use, compile, sell, or
  11. # distribute this software, either in source code form or as a compiled
  12. # binary, for any purpose, commercial or non-commercial, and by any
  13. # means.
  14. #
  15. # In jurisdictions that recognize copyright laws, the author or authors
  16. # of this software dedicate any and all copyright interest in the
  17. # software to the public domain. We make this dedication for the benefit
  18. # of the public at large and to the detriment of our heirs and
  19. # successors. We intend this dedication to be an overt act of
  20. # relinquishment in perpetuity of all present and future rights to this
  21. # software under copyright law.
  22. #
  23. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  27. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  28. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29. # OTHER DEALINGS IN THE SOFTWARE.
  30. #
  31. # For more information, please refer to <http://unlicense.org/>
  32.  
  33. import os
  34. import ycm_core
  35.  
  36. flags = [
  37.     #'-Wall',
  38.     #'-g',
  39.     #'-lSDL2',
  40.     '-isystem /usr/include/linux/stddef.h',
  41.     '-isystem /usr/include',
  42.     '-isystem /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.1',
  43.     '-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/6.3.1',
  44.     '-isystem /usr/bin/',
  45.     '-I/usr/include/linux/stddef.h',
  46.     '-I/usr/local/include',
  47.     '-I/usr/include/clang-c',
  48.     '-I/usr/include/linux',
  49.     '-I/usr/bin/../lib/gcc/x86_64-pc-linux-gnu',
  50.     '-I/usr/include',
  51.     #'-I/usr/include/SDL2',
  52.     #'-I/usr/include/SDL2/SDL_render.h'
  53.  
  54. ]
  55.  
  56.  
  57. # Set this to the absolute path to the folder (NOT the file!) containing the
  58. # compile_commands.json file to use that instead of 'flags'. See here for
  59. # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  60. #
  61. # You can get CMake to generate this file for you by adding:
  62. #   set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
  63. # to your CMakeLists.txt file.
  64. #
  65. # Most projects will NOT need to set this to anything; you can just change the
  66. # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
  67. compilation_database_folder = ''
  68.  
  69. if os.path.exists( compilation_database_folder ):
  70.   database = ycm_core.CompilationDatabase( compilation_database_folder )
  71. else:
  72.   database = None
  73.  
  74. SOURCE_EXTENSIONS = [ '.C', '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
  75.  
  76. def DirectoryOfThisScript():
  77.   return os.path.dirname( os.path.abspath( __file__ ) )
  78.  
  79.  
  80. def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  81.   if not working_directory:
  82.     return list( flags )
  83.   new_flags = []
  84.   make_next_absolute = False
  85.   path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  86.   for flag in flags:
  87.     new_flag = flag
  88.  
  89.     if make_next_absolute:
  90.       make_next_absolute = False
  91.       if not flag.startswith( '/' ):
  92.         new_flag = os.path.join( working_directory, flag )
  93.  
  94.     for path_flag in path_flags:
  95.       if flag == path_flag:
  96.         make_next_absolute = True
  97.         break
  98.  
  99.       if flag.startswith( path_flag ):
  100.         path = flag[ len( path_flag ): ]
  101.         new_flag = path_flag + os.path.join( working_directory, path )
  102.         break
  103.  
  104.     if new_flag:
  105.       new_flags.append( new_flag )
  106.   return new_flags
  107.  
  108.  
  109. def IsHeaderFile( filename ):
  110.   extension = os.path.splitext( filename )[ 1 ]
  111.   return extension in [ '.H', '.h', '.hxx', '.hpp', '.hh' ]
  112.  
  113.  
  114. def GetCompilationInfoForFile( filename ):
  115.   # The compilation_commands.json file generated by CMake does not have entries
  116.   # for header files. So we do our best by asking the db for flags for a
  117.   # corresponding source file, if any. If one exists, the flags for that file
  118.   # should be good enough.
  119.   if IsHeaderFile( filename ):
  120.     basename = os.path.splitext( filename )[ 0 ]
  121.     for extension in SOURCE_EXTENSIONS:
  122.       replacement_file = basename + extension
  123.       if os.path.exists( replacement_file ):
  124.         compilation_info = database.GetCompilationInfoForFile(
  125.           replacement_file )
  126.         if compilation_info.compiler_flags_:
  127.           return compilation_info
  128.     return None
  129.   return database.GetCompilationInfoForFile( filename )
  130.  
  131.  
  132. def FlagsForFile( filename, **kwargs ):
  133.   if database:
  134.     # Bear in mind that compilation_info.compiler_flags_ does NOT return a
  135.     # python list, but a "list-like" StringVec object
  136.     compilation_info = GetCompilationInfoForFile( filename )
  137.     if not compilation_info:
  138.       return None
  139.  
  140.     final_flags = MakeRelativePathsInFlagsAbsolute(
  141.       compilation_info.compiler_flags_,
  142.       compilation_info.compiler_working_dir_ )
  143.  
  144.   else:
  145.     relative_to = DirectoryOfThisScript()
  146.     final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
  147.  
  148.   return {
  149.     'flags': final_flags,
  150.     'do_cache': True
  151.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement