spacepaste

  1.  
  2. # Generated by YCM Generator at 2016-04-06 17:34:51.920266
  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. import os
  33. import ycm_core
  34. flags = [
  35. '-x',
  36. 'c',
  37. '-Wall',
  38. '-Werror',
  39. '-Wno-unused-function',
  40. '-Wno-unused-variable',
  41. '-std=c99'
  42. ]
  43. # Set this to the absolute path to the folder (NOT the file!) containing the
  44. # compile_commands.json file to use that instead of 'flags'. See here for
  45. # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  46. #
  47. # You can get CMake to generate this file for you by adding:
  48. # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
  49. # to your CMakeLists.txt file.
  50. #
  51. # Most projects will NOT need to set this to anything; you can just change the
  52. # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
  53. compilation_database_folder = ''
  54. if os.path.exists( compilation_database_folder ):
  55. database = ycm_core.CompilationDatabase( compilation_database_folder )
  56. else:
  57. database = None
  58. SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
  59. def DirectoryOfThisScript():
  60. return os.path.dirname( os.path.abspath( __file__ ) )
  61. def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
  62. if not working_directory:
  63. return list( flags )
  64. new_flags = []
  65. make_next_absolute = False
  66. path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
  67. for flag in flags:
  68. new_flag = flag
  69. if make_next_absolute:
  70. make_next_absolute = False
  71. if not flag.startswith( '/' ):
  72. new_flag = os.path.join( working_directory, flag )
  73. for path_flag in path_flags:
  74. if flag == path_flag:
  75. make_next_absolute = True
  76. break
  77. if flag.startswith( path_flag ):
  78. path = flag[ len( path_flag ): ]
  79. new_flag = path_flag + os.path.join( working_directory, path )
  80. break
  81. if new_flag:
  82. new_flags.append( new_flag )
  83. return new_flags
  84. def IsHeaderFile( filename ):
  85. extension = os.path.splitext( filename )[ 1 ]
  86. return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
  87. def GetCompilationInfoForFile( filename ):
  88. # The compilation_commands.json file generated by CMake does not have entries
  89. # for header files. So we do our best by asking the db for flags for a
  90. # corresponding source file, if any. If one exists, the flags for that file
  91. # should be good enough.
  92. if IsHeaderFile( filename ):
  93. basename = os.path.splitext( filename )[ 0 ]
  94. for extension in SOURCE_EXTENSIONS:
  95. replacement_file = basename + extension
  96. if os.path.exists( replacement_file ):
  97. compilation_info = database.GetCompilationInfoForFile(
  98. replacement_file )
  99. if compilation_info.compiler_flags_:
  100. return compilation_info
  101. return None
  102. return database.GetCompilationInfoForFile( filename )
  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. final_flags = MakeRelativePathsInFlagsAbsolute(
  111. compilation_info.compiler_flags_,
  112. compilation_info.compiler_working_dir_ )
  113. else:
  114. relative_to = DirectoryOfThisScript()
  115. final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
  116. return {
  117. 'flags': final_flags,
  118. 'do_cache': True
  119. }
  120.