|
| 1 | +from distutils.sysconfig import get_python_inc |
| 2 | +import platform |
| 3 | +import os.path as p |
| 4 | +import subprocess |
| 5 | + |
| 6 | +DIR_OF_THIS_SCRIPT = p.abspath( p.dirname( __file__ ) ) |
| 7 | +DIR_OF_THIRD_PARTY = p.join( DIR_OF_THIS_SCRIPT, 'third_party' ) |
| 8 | +DIR_OF_WATCHDOG_DEPS = p.join( DIR_OF_THIRD_PARTY, 'watchdog_deps' ) |
| 9 | +SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] |
| 10 | + |
| 11 | +database = None |
| 12 | + |
| 13 | +# These are the compilation flags that will be used in case there's no |
| 14 | +# compilation database set (by default, one is not set). |
| 15 | +# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. |
| 16 | +flags = [ |
| 17 | +'-Wall', |
| 18 | +'-Wextra', |
| 19 | +'-Werror', |
| 20 | +'-Wno-long-long', |
| 21 | +'-Wno-variadic-macros', |
| 22 | +'-fexceptions', |
| 23 | +'-DNDEBUG', |
| 24 | +# You 100% do NOT need -DUSE_CLANG_COMPLETER and/or -DYCM_EXPORT in your flags; |
| 25 | +# only the YCM source code needs it. |
| 26 | +'-DUSE_CLANG_COMPLETER', |
| 27 | +'-DYCM_EXPORT=', |
| 28 | +'-DYCM_ABSEIL_SUPPORTED', |
| 29 | +# THIS IS IMPORTANT! Without the '-x' flag, Clang won't know which language to |
| 30 | +# use when compiling headers. So it will guess. Badly. So C++ headers will be |
| 31 | +# compiled as C headers. You don't want that so ALWAYS specify the '-x' flag. |
| 32 | +# For a C project, you would set this to 'c' instead of 'c++'. |
| 33 | +'-x', |
| 34 | +'c++', |
| 35 | +'-isystem', |
| 36 | +'cpp/absl', |
| 37 | +'-isystem', |
| 38 | +'cpp/pybind11', |
| 39 | +'-isystem', |
| 40 | +'cpp/whereami', |
| 41 | +'-isystem', |
| 42 | +'cpp/BoostParts', |
| 43 | +'-isystem', |
| 44 | +get_python_inc(), |
| 45 | +'-isystem', |
| 46 | +'cpp/llvm/include', |
| 47 | +'-isystem', |
| 48 | +'cpp/llvm/tools/clang/include', |
| 49 | +'-I', |
| 50 | +'cpp/ycm', |
| 51 | +'-I', |
| 52 | +'cpp/ycm/ClangCompleter', |
| 53 | +'-isystem', |
| 54 | +'cpp/ycm/tests/gmock/googlemock/include', |
| 55 | +'-isystem', |
| 56 | +'cpp/ycm/tests/gmock/googletest/include', |
| 57 | +'-isystem', |
| 58 | +'cpp/ycm/benchmarks/benchmark/include', |
| 59 | +'-isystem','/usr/include', |
| 60 | +'-isystem','/usr/local/include', |
| 61 | +'-isystem','/home/anlijiu/rti_connext_dds-6.1.0/include/ndds/hpp/dds/', |
| 62 | +'-isystem','/home/anlijiu/rti_connext_dds-6.1.0/include/ndds/hpp/rti/request/', |
| 63 | +'-isystem','/home/anlijiu/rti_connext_dds-6.1.0/include/ndds/hpp/rti/', |
| 64 | +'-isystem','/home/anlijiu/rti_connext_dds-6.1.0/include/ndds/hpp', |
| 65 | +'-std=c++11', |
| 66 | +] |
| 67 | + |
| 68 | +# Set this to the absolute path to the folder (NOT the file!) containing the |
| 69 | +# compile_commands.json file to use that instead of 'flags'. See here for |
| 70 | +# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html |
| 71 | +# |
| 72 | +# You can get CMake to generate this file for you by adding: |
| 73 | +# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) |
| 74 | +# to your CMakeLists.txt file. |
| 75 | +# |
| 76 | +# Most projects will NOT need to set this to anything; you can just change the |
| 77 | +# 'flags' list of compilation flags. Notice that YCM itself uses that approach. |
| 78 | +compilation_database_folder = '' |
| 79 | + |
| 80 | + |
| 81 | +def IsHeaderFile( filename ): |
| 82 | + extension = p.splitext( filename )[ 1 ] |
| 83 | + return extension in [ '.h', '.hxx', '.hpp', '.hh' ] |
| 84 | + |
| 85 | + |
| 86 | +def FindCorrespondingSourceFile( filename ): |
| 87 | + if IsHeaderFile( filename ): |
| 88 | + basename = p.splitext( filename )[ 0 ] |
| 89 | + for extension in SOURCE_EXTENSIONS: |
| 90 | + replacement_file = basename + extension |
| 91 | + if p.exists( replacement_file ): |
| 92 | + return replacement_file |
| 93 | + return filename |
| 94 | + |
| 95 | + |
| 96 | +def PathToPythonUsedDuringBuild(): |
| 97 | + try: |
| 98 | + filepath = p.join( DIR_OF_THIS_SCRIPT, 'PYTHON_USED_DURING_BUILDING' ) |
| 99 | + with open( filepath ) as f: |
| 100 | + return f.read().strip() |
| 101 | + except OSError: |
| 102 | + return None |
| 103 | + |
| 104 | + |
| 105 | +def Settings( **kwargs ): |
| 106 | + # Do NOT import ycm_core at module scope. |
| 107 | + import ycm_core |
| 108 | + |
| 109 | + global database |
| 110 | + if database is None and p.exists( compilation_database_folder ): |
| 111 | + database = ycm_core.CompilationDatabase( compilation_database_folder ) |
| 112 | + |
| 113 | + language = kwargs[ 'language' ] |
| 114 | + |
| 115 | + if language == 'cfamily': |
| 116 | + # If the file is a header, try to find the corresponding source file and |
| 117 | + # retrieve its flags from the compilation database if using one. This is |
| 118 | + # necessary since compilation databases don't have entries for header files. |
| 119 | + # In addition, use this source file as the translation unit. This makes it |
| 120 | + # possible to jump from a declaration in the header file to its definition |
| 121 | + # in the corresponding source file. |
| 122 | + filename = FindCorrespondingSourceFile( kwargs[ 'filename' ] ) |
| 123 | + |
| 124 | + if not database: |
| 125 | + return { |
| 126 | + 'flags': flags, |
| 127 | + 'include_paths_relative_to_dir': DIR_OF_THIS_SCRIPT, |
| 128 | + 'override_filename': filename |
| 129 | + } |
| 130 | + |
| 131 | + compilation_info = database.GetCompilationInfoForFile( filename ) |
| 132 | + if not compilation_info.compiler_flags_: |
| 133 | + return {} |
| 134 | + |
| 135 | + # Bear in mind that compilation_info.compiler_flags_ does NOT return a |
| 136 | + # python list, but a "list-like" StringVec object. |
| 137 | + final_flags = list( compilation_info.compiler_flags_ ) |
| 138 | + |
| 139 | + # NOTE: This is just for YouCompleteMe; it's highly likely that your project |
| 140 | + # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR |
| 141 | + # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT. |
| 142 | + try: |
| 143 | + final_flags.remove( '-stdlib=libc++' ) |
| 144 | + except ValueError: |
| 145 | + pass |
| 146 | + |
| 147 | + return { |
| 148 | + 'flags': final_flags, |
| 149 | + 'include_paths_relative_to_dir': compilation_info.compiler_working_dir_, |
| 150 | + 'override_filename': filename |
| 151 | + } |
| 152 | + |
| 153 | + if language == 'python': |
| 154 | + return { |
| 155 | + 'interpreter_path': PathToPythonUsedDuringBuild() |
| 156 | + } |
| 157 | + |
| 158 | + return {} |
| 159 | + |
| 160 | + |
| 161 | +def PythonSysPath( **kwargs ): |
| 162 | + sys_path = kwargs[ 'sys_path' ] |
| 163 | + |
| 164 | + interpreter_path = kwargs[ 'interpreter_path' ] |
| 165 | + major_version = subprocess.check_output( [ |
| 166 | + interpreter_path, '-c', 'import sys; print( sys.version_info[ 0 ] )' ] |
| 167 | + ).rstrip().decode( 'utf8' ) |
| 168 | + |
| 169 | + sys_path[ 0:0 ] = [ p.join( DIR_OF_THIS_SCRIPT ), |
| 170 | + p.join( DIR_OF_THIRD_PARTY, 'bottle' ), |
| 171 | + p.join( DIR_OF_THIRD_PARTY, 'regex-build' ), |
| 172 | + p.join( DIR_OF_THIRD_PARTY, 'frozendict' ), |
| 173 | + p.join( DIR_OF_THIRD_PARTY, 'jedi_deps', 'jedi' ), |
| 174 | + p.join( DIR_OF_THIRD_PARTY, 'jedi_deps', 'parso' ), |
| 175 | + p.join( DIR_OF_WATCHDOG_DEPS, 'watchdog', 'build', 'lib3' ), |
| 176 | + p.join( DIR_OF_WATCHDOG_DEPS, 'pathtools' ), |
| 177 | + p.join( DIR_OF_THIRD_PARTY, 'waitress' ) ] |
| 178 | + |
| 179 | + sys_path.append( p.join( DIR_OF_THIRD_PARTY, 'jedi_deps', 'numpydoc' ) ) |
| 180 | + return sys_path |
0 commit comments