Dotfiles for different machines on different branches.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
7.6 KiB

  1. # This file is NOT licensed under the GPLv3, which is the license for the rest
  2. # of YouCompleteMe.
  3. #
  4. # Here's the license text for this file:
  5. #
  6. # This is free and unencumbered software released into the public domain.
  7. #
  8. # Anyone is free to copy, modify, publish, use, compile, sell, or
  9. # distribute this software, either in source code form or as a compiled
  10. # binary, for any purpose, commercial or non-commercial, and by any
  11. # means.
  12. #
  13. # In jurisdictions that recognize copyright laws, the author or authors
  14. # of this software dedicate any and all copyright interest in the
  15. # software to the public domain. We make this dedication for the benefit
  16. # of the public at large and to the detriment of our heirs and
  17. # successors. We intend this dedication to be an overt act of
  18. # relinquishment in perpetuity of all present and future rights to this
  19. # software under copyright law.
  20. #
  21. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  26. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. # OTHER DEALINGS IN THE SOFTWARE.
  28. #
  29. # For more information, please refer to <http://unlicense.org/>
  30. from distutils.sysconfig import get_python_inc
  31. import os
  32. import platform
  33. import os.path as p
  34. import subprocess
  35. DIR_OF_THIS_SCRIPT = p.abspath( p.dirname( __file__ ) )
  36. DIR_OF_THIRD_PARTY = p.join( DIR_OF_THIS_SCRIPT, 'third_party' )
  37. SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
  38. database = None
  39. # These are the compilation flags that will be used in case there's no
  40. # compilation database set (by default, one is not set).
  41. # CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
  42. flags = [
  43. '-Wall',
  44. '-Wextra',
  45. '-Werror',
  46. '-Wno-long-long',
  47. '-Wno-variadic-macros',
  48. '-fexceptions',
  49. '-DNDEBUG',
  50. # You 100% do NOT need -DUSE_CLANG_COMPLETER and/or -DYCM_EXPORT in your flags;
  51. # only the YCM source code needs it.
  52. '-DUSE_CLANG_COMPLETER',
  53. '-DYCM_EXPORT=',
  54. # THIS IS IMPORTANT! Without the '-x' flag, Clang won't know which language to
  55. # use when compiling headers. So it will guess. Badly. So C++ headers will be
  56. # compiled as C headers. You don't want that so ALWAYS specify the '-x' flag.
  57. # For a C project, you would set this to 'c' instead of 'c++'.
  58. '-x',
  59. 'c++',
  60. '-isystem',
  61. 'cpp/pybind11',
  62. '-isystem',
  63. 'cpp/whereami',
  64. '-isystem',
  65. 'cpp/BoostParts',
  66. '-isystem',
  67. get_python_inc(),
  68. '-isystem',
  69. 'cpp/llvm/include',
  70. '-isystem',
  71. 'cpp/llvm/tools/clang/include',
  72. '-I',
  73. 'cpp/ycm',
  74. '-I',
  75. 'cpp/ycm/ClangCompleter',
  76. '-isystem',
  77. 'cpp/ycm/tests/gmock/gtest',
  78. '-isystem',
  79. 'cpp/ycm/tests/gmock/gtest/include',
  80. '-isystem',
  81. 'cpp/ycm/tests/gmock',
  82. '-isystem',
  83. 'cpp/ycm/tests/gmock/include',
  84. '-isystem',
  85. 'cpp/ycm/benchmarks/benchmark/include',
  86. ]
  87. # Clang automatically sets the '-std=' flag to 'c++14' for MSVC 2015 or later,
  88. # which is required for compiling the standard library, and to 'c++11' for older
  89. # versions.
  90. if platform.system() != 'Windows':
  91. flags.append( '-std=c++11' )
  92. # Set this to the absolute path to the folder (NOT the file!) containing the
  93. # compile_commands.json file to use that instead of 'flags'. See here for
  94. # more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
  95. #
  96. # You can get CMake to generate this file for you by adding:
  97. # set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
  98. # to your CMakeLists.txt file.
  99. #
  100. # Most projects will NOT need to set this to anything; you can just change the
  101. # 'flags' list of compilation flags. Notice that YCM itself uses that approach.
  102. compilation_database_folder = ''
  103. def IsHeaderFile( filename ):
  104. extension = p.splitext( filename )[ 1 ]
  105. return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
  106. def FindCorrespondingSourceFile( filename ):
  107. if IsHeaderFile( filename ):
  108. basename = p.splitext( filename )[ 0 ]
  109. for extension in SOURCE_EXTENSIONS:
  110. replacement_file = basename + extension
  111. if p.exists( replacement_file ):
  112. return replacement_file
  113. return filename
  114. def PathToPythonUsedDuringBuild():
  115. try:
  116. filepath = p.join( DIR_OF_THIS_SCRIPT, 'PYTHON_USED_DURING_BUILDING' )
  117. with open( filepath ) as f:
  118. return f.read().strip()
  119. except OSError:
  120. return None
  121. def Settings( **kwargs ):
  122. # Do NOT import ycm_core at module scope.
  123. import ycm_core
  124. global database
  125. if database is None and p.exists( compilation_database_folder ):
  126. database = ycm_core.CompilationDatabase( compilation_database_folder )
  127. language = kwargs[ 'language' ]
  128. if language == 'cfamily':
  129. # If the file is a header, try to find the corresponding source file and
  130. # retrieve its flags from the compilation database if using one. This is
  131. # necessary since compilation databases don't have entries for header files.
  132. # In addition, use this source file as the translation unit. This makes it
  133. # possible to jump from a declaration in the header file to its definition
  134. # in the corresponding source file.
  135. filename = FindCorrespondingSourceFile( kwargs[ 'filename' ] )
  136. if not database:
  137. return {
  138. 'flags': flags,
  139. 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT,
  140. 'override_filename': filename
  141. }
  142. compilation_info = database.GetCompilationInfoForFile( filename )
  143. if not compilation_info.compiler_flags_:
  144. return {}
  145. # Bear in mind that compilation_info.compiler_flags_ does NOT return a
  146. # python list, but a "list-like" StringVec object.
  147. final_flags = list( compilation_info.compiler_flags_ )
  148. # NOTE: This is just for YouCompleteMe; it's highly likely that your project
  149. # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
  150. # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
  151. try:
  152. final_flags.remove( '-stdlib=libc++' )
  153. except ValueError:
  154. pass
  155. return {
  156. 'flags': final_flags,
  157. 'include_paths_relative_to_dir': compilation_info.compiler_working_dir_,
  158. 'override_filename': filename
  159. }
  160. if language == 'python':
  161. return {
  162. 'interpreter_path': PathToPythonUsedDuringBuild()
  163. }
  164. return {}
  165. def PythonSysPath( **kwargs ):
  166. sys_path = kwargs[ 'sys_path' ]
  167. interpreter_path = kwargs[ 'interpreter_path' ]
  168. major_version = subprocess.check_output( [
  169. interpreter_path, '-c', 'import sys; print( sys.version_info[ 0 ] )' ]
  170. ).rstrip().decode( 'utf8' )
  171. sys_path[ 0:0 ] = [ p.join( DIR_OF_THIS_SCRIPT ),
  172. p.join( DIR_OF_THIRD_PARTY, 'bottle' ),
  173. p.join( DIR_OF_THIRD_PARTY, 'cregex',
  174. 'regex_{}'.format( major_version ) ),
  175. p.join( DIR_OF_THIRD_PARTY, 'frozendict' ),
  176. p.join( DIR_OF_THIRD_PARTY, 'jedi_deps', 'jedi' ),
  177. p.join( DIR_OF_THIRD_PARTY, 'jedi_deps', 'parso' ),
  178. p.join( DIR_OF_THIRD_PARTY, 'requests_deps', 'requests' ),
  179. p.join( DIR_OF_THIRD_PARTY, 'requests_deps',
  180. 'urllib3',
  181. 'src' ),
  182. p.join( DIR_OF_THIRD_PARTY, 'requests_deps',
  183. 'chardet' ),
  184. p.join( DIR_OF_THIRD_PARTY, 'requests_deps',
  185. 'certifi' ),
  186. p.join( DIR_OF_THIRD_PARTY, 'requests_deps',
  187. 'idna' ),
  188. p.join( DIR_OF_THIRD_PARTY, 'waitress' ) ]
  189. sys_path.append( p.join( DIR_OF_THIRD_PARTY, 'jedi_deps', 'numpydoc' ) )
  190. return sys_path