1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
|
Description: Use Debian's llvm and clang
While this patch is mostly about dropping the usage of the embedded clang
sources (which we strip from the upstream tarball as well) it also adapts
(so in effect mostly reverts) changes to the tests to have them support
multiple clang versions
Forwarded: not-needed
--- a/cpp/ycm/CMakeLists.txt
+++ b/cpp/ycm/CMakeLists.txt
@@ -172,7 +172,7 @@
endif()
# Need TEMP because find_library does not work with an option variable
- find_library( TEMP NAMES clang libclang
+ find_library( TEMP NAMES clang libclang.so.1
PATHS ${LIBCLANG_SEARCH_PATH}
NO_DEFAULT_PATH )
set( EXTERNAL_LIBCLANG_PATH ${TEMP} )
@@ -347,38 +347,6 @@
PUBLIC ${EXTRA_LIBS}
)
-if( LIBCLANG_TARGET )
- set( LIBCLANG_DIR "${CMAKE_SOURCE_DIR}/../third_party/clang/lib" )
- # add rpath to libclang and remove rpath to temporary directory
- if ( NOT MSVC )
- set_target_properties( ${PROJECT_NAME} PROPERTIES
- BUILD_WITH_INSTALL_RPATH ON
- SKIP_BUILD_RPATH FALSE
- INSTALL_RPATH ${LIBCLANG_DIR} )
- endif ()
- # Remove all previous libclang libraries.
- file( GLOB LIBCLANG_FILEPATHS "${LIBCLANG_DIR}/libclang*" )
- foreach( FILEPATH ${LIBCLANG_FILEPATHS} )
- file( REMOVE ${FILEPATH} )
- endforeach()
- # When building with MSVC, we need to copy libclang.dll instead of libclang.lib
- if( MSVC )
- add_custom_command(
- TARGET ${PROJECT_NAME}
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy "${PATH_TO_LLVM_ROOT}/bin/libclang.dll" "${LIBCLANG_DIR}"
- )
- else()
- foreach( LIBCLANG_FILE ${PATH_TO_LIBCLANG_WITH_SYMLINKS} )
- add_custom_command(
- TARGET ${PROJECT_NAME}
- POST_BUILD
- COMMAND cp -a ${LIBCLANG_FILE} "${LIBCLANG_DIR}"
- )
- endforeach()
- endif()
-endif()
-
#############################################################################
--- a/run_tests.py
+++ b/run_tests.py
@@ -14,7 +14,6 @@
DIR_OF_THIS_SCRIPT = p.dirname( p.abspath( __file__ ) )
DIR_OF_THIRD_PARTY = p.join( DIR_OF_THIS_SCRIPT, 'third_party' )
DIR_OF_WATCHDOG_DEPS = p.join( DIR_OF_THIRD_PARTY, 'watchdog_deps' )
-LIBCLANG_DIR = p.join( DIR_OF_THIRD_PARTY, 'clang', 'lib' )
python_path = [
p.join( DIR_OF_THIRD_PARTY, 'regex-build' ),
@@ -229,7 +228,6 @@
# unittest_args += [ '-m', 'not valgrind_skip' ]
new_env = os.environ.copy()
- new_env[ 'LD_LIBRARY_PATH' ] = LIBCLANG_DIR
new_env[ 'YCM_VALGRIND_RUN' ] = '1'
cmd = [ 'valgrind',
'--gen-suppressions=all',
@@ -273,13 +271,6 @@
# Useful for _writing_ tests
env[ 'YCM_TEST_NO_RETRY' ] = '1'
- if OnWindows():
- # We prepend the Clang third-party directory to the PATH instead of
- # overwriting it so that the executable is able to find the Python library.
- env[ 'PATH' ] = LIBCLANG_DIR + ';' + env[ 'PATH' ]
- else:
- env[ 'LD_LIBRARY_PATH' ] = LIBCLANG_DIR
-
if parsed_args.coverage:
executable = [ sys.executable, '-m', 'coverage', 'run' ]
else:
--- a/ycmd/utils.py
+++ b/ycmd/utils.py
@@ -28,10 +28,6 @@
LOGGER = logging.getLogger( 'ycmd' )
ROOT_DIR = os.path.normpath( os.path.join( os.path.dirname( __file__ ), '..' ) )
-DIR_OF_THIRD_PARTY = os.path.join( ROOT_DIR, 'third_party' )
-LIBCLANG_DIR = os.path.join( DIR_OF_THIRD_PARTY, 'clang', 'lib' )
-if hasattr( os, 'add_dll_directory' ):
- os.add_dll_directory( LIBCLANG_DIR )
from collections.abc import Mapping
@@ -477,16 +473,6 @@
return int( ReadFile( os.path.join( ROOT_DIR, 'CORE_VERSION' ) ) )
-def LoadYcmCoreDependencies():
- for name in ListDirectory( LIBCLANG_DIR ):
- if name.startswith( 'libclang' ):
- libclang_path = os.path.join( LIBCLANG_DIR, name )
- if os.path.isfile( libclang_path ):
- import ctypes
- ctypes.cdll.LoadLibrary( libclang_path )
- return
-
-
def ImportCore():
"""Imports and returns the ycm_core module. This function exists for easily
mocking this import in tests."""
@@ -498,11 +484,7 @@
"""Checks if ycm_core library is compatible and returns with an exit
status."""
try:
- try:
- ycm_core = ImportCore()
- except ImportError:
- LoadYcmCoreDependencies()
- ycm_core = ImportCore()
+ ycm_core = ImportCore()
except ImportError as error:
message = str( error )
if CORE_MISSING_ERROR_REGEX.match( message ):
@@ -525,11 +507,7 @@
def GetClangResourceDir():
- resource_dir = os.path.join( LIBCLANG_DIR, 'clang' )
- for version in ListDirectory( resource_dir ):
- return os.path.join( resource_dir, version )
-
- raise RuntimeError( 'Cannot find Clang resource directory.' )
+ return '/usr/lib/ycmd/clang_includes'
CLANG_RESOURCE_DIR = GetClangResourceDir()
--- a/ycmd/completers/cpp/clangd_completer.py
+++ b/ycmd/completers/cpp/clangd_completer.py
@@ -43,16 +43,6 @@
'(\\s*#\\s*(?:include|import)\\s*)(?:"[^"]*|<[^>]*)' )
NOT_CACHED = 'NOT_CACHED'
CLANGD_COMMAND = NOT_CACHED
-PRE_BUILT_CLANGD_DIR = os.path.abspath( os.path.join(
- os.path.dirname( __file__ ),
- '..',
- '..',
- '..',
- 'third_party',
- 'clangd',
- 'output',
- 'bin' ) )
-PRE_BUILT_CLANDG_PATH = os.path.join( PRE_BUILT_CLANGD_DIR, 'clangd' )
def ParseClangdVersion( version_str ):
@@ -79,51 +69,41 @@
return True
-def GetThirdPartyClangd():
- pre_built_clangd = GetExecutable( PRE_BUILT_CLANDG_PATH )
- if not pre_built_clangd:
- LOGGER.info( 'No Clangd executable found in %s', PRE_BUILT_CLANGD_DIR )
- return None
- if not CheckClangdVersion( pre_built_clangd ):
- LOGGER.error( 'Clangd executable at %s is out-of-date', pre_built_clangd )
- return None
- LOGGER.info( 'Clangd executable found at %s and up to date',
- PRE_BUILT_CLANGD_DIR )
- return pre_built_clangd
-
-
-def GetClangdExecutableAndResourceDir( user_options ):
+def GetClangdExecutable( user_options ):
"""Return the Clangd binary from the path specified in the
'clangd_binary_path' option. Let the binary find its resource directory in
- that case. If no binary is found or if it's out-of-date, return nothing. If
- 'clangd_binary_path' is empty, return the third-party Clangd and its resource
- directory if the user downloaded it and if it's up to date. Otherwise, return
- nothing."""
- clangd = user_options[ 'clangd_binary_path' ]
- resource_dir = None
-
- if clangd:
- clangd = FindExecutable( ExpandVariablesInPath( clangd ) )
+ that case. If no binary is found or if it's out-of-date, return nothing."""
+ clangd = None
+ if user_options[ 'clangd_binary_path' ]:
+ clangd = FindExecutable( ExpandVariablesInPath( user_options[ 'clangd_binary_path' ] ) )
if not clangd:
LOGGER.error( 'No Clangd executable found at %s',
user_options[ 'clangd_binary_path' ] )
- return None, None
-
- if not CheckClangdVersion( clangd ):
- LOGGER.error( 'Clangd at %s is out-of-date', clangd )
- return None, None
-
- # Try looking for the pre-built binary.
+ return None
else:
- third_party_clangd = GetThirdPartyClangd()
- if not third_party_clangd:
- return None, None
- clangd = third_party_clangd
- resource_dir = CLANG_RESOURCE_DIR
+ for exe in [ '/usr/bin/clangd', ]:
+ if os.path.exists(exe):
+ clangd = exe
+ break
+ if not clangd:
+ for ver in [ 19, 18, 17, 16, 15, 14, 13, 20, 21, 22 ]:
+ if ver < MIN_SUPPORTED_VERSION[0]:
+ continue
+ exe = '/usr/bin/clangd-%d' % ver
+ if os.path.exists(exe):
+ clangd = exe
+ break
+ if not clangd:
+ LOGGER.error( 'No Clangd executable found. Try `apt install clangd` or set path explicitly' )
+ return None
+
+ if not CheckClangdVersion( clangd ):
+ LOGGER.error( 'Clangd at %s is out-of-date', clangd )
+ return None
LOGGER.info( 'Using Clangd from %s', clangd )
- return clangd, resource_dir
+ return clangd
def GetClangdCommand( user_options ):
@@ -135,28 +115,23 @@
return CLANGD_COMMAND
CLANGD_COMMAND = None
- installed_clangd, resource_dir = GetClangdExecutableAndResourceDir(
- user_options )
+ installed_clangd = GetClangdExecutable( user_options )
if not installed_clangd:
return None
CLANGD_COMMAND = [ installed_clangd ]
clangd_args = user_options[ 'clangd_args' ]
- put_resource_dir = False
put_limit_results = False
put_header_insertion_decorators = False
put_log = False
for arg in clangd_args:
CLANGD_COMMAND.append( arg )
- put_resource_dir = put_resource_dir or arg.startswith( '-resource-dir' )
put_limit_results = put_limit_results or arg.startswith( '-limit-results' )
put_header_insertion_decorators = ( put_header_insertion_decorators or
arg.startswith( '-header-insertion-decorators' ) )
put_log = put_log or arg.startswith( '-log' )
if not put_header_insertion_decorators:
CLANGD_COMMAND.append( '-header-insertion-decorators=0' )
- if resource_dir and not put_resource_dir:
- CLANGD_COMMAND.append( '-resource-dir=' + resource_dir )
if user_options[ 'clangd_uses_ycmd_caching' ] and not put_limit_results:
CLANGD_COMMAND.append( '-limit-results=500' )
if LOGGER.isEnabledFor( logging.DEBUG ) and not put_log:
--- a/ycmd/tests/utils_test.py
+++ b/ycmd/tests/utils_test.py
@@ -33,7 +33,7 @@
from types import ModuleType
from unittest import TestCase
from ycmd import utils
-from ycmd.tests.test_utils import ( WindowsOnly, UnixOnly,
+from ycmd.tests.test_utils import ( WindowsOnly, UnixOnly, NotDebian,
CurrentWorkingDirectory,
TemporaryExecutable )
from ycmd.tests import PathToTestFile
@@ -517,6 +517,7 @@
'script. See the documentation for more details.' )
+ @NotDebian
@patch( 'ycmd.utils.ListDirectory', return_value = [] )
def test_GetClangResourceDir_NotFound( self, *args ):
assert_that(
--- a/ycmd/tests/clangd/utilities_test.py
+++ b/ycmd/tests/clangd/utilities_test.py
@@ -25,7 +25,7 @@
from ycmd.completers.language_server.language_server_completer import (
LanguageServerConnectionTimeout )
from ycmd.tests.clangd import IsolatedYcmd, PathToTestFile
-from ycmd.tests.test_utils import BuildRequest
+from ycmd.tests.test_utils import ( BuildRequest, NotDebian )
from ycmd.user_options_store import DefaultOptions
@@ -39,6 +39,7 @@
class UtilitiesTest( TestCase ):
+ @NotDebian
def test_ClangdCompleter_GetClangdCommand_NoCustomBinary( self ):
user_options = DefaultOptions()
@@ -123,8 +124,7 @@
user_options = DefaultOptions()
# Clangd not in third_party (or an old version).
- with patch( 'ycmd.completers.cpp.clangd_completer.GetThirdPartyClangd',
- return_value = None ):
+ if False:
# Default.
clangd_completer.CLANGD_COMMAND = clangd_completer.NOT_CACHED
assert_that( clangd_completer.ShouldEnableClangdCompleter( user_options ),
@@ -152,8 +152,7 @@
user_options = DefaultOptions()
# Clangd in third_party with a supported version.
- with patch( 'ycmd.completers.cpp.clangd_completer.GetThirdPartyClangd',
- return_value = 'third_party_clangd' ):
+ if True:
# Default.
clangd_completer.CLANGD_COMMAND = clangd_completer.NOT_CACHED
assert_that( clangd_completer.ShouldEnableClangdCompleter( user_options ),
@@ -213,6 +212,7 @@
shutdown_server.assert_called()
+ @NotDebian
def test_ClangdCompleter_GetThirdParty( self ):
with patch( 'ycmd.completers.cpp.clangd_completer.GetExecutable',
return_value = None ):
--- a/ycmd/tests/clangd/subcommands_test.py
+++ b/ycmd/tests/clangd/subcommands_test.py
@@ -23,6 +23,7 @@
equal_to,
has_entries,
has_entry,
+ is_in,
matches_regexp )
from unittest.mock import patch
from unittest import TestCase
@@ -1108,10 +1109,12 @@
requests.codes.ok ],
# from header
[ { 'line_num': 6, 'column_num': 10 },
- has_entry( 'detailed_info', equal_to(
+ has_entry( 'detailed_info', is_in( [
'function docstring_from_header_file\nprovided by "docstring.h"'
'\n\n→ void\ndocstring\n\n'
- 'void docstring_from_header_file()' ) ),
+ 'void docstring_from_header_file()',
+ 'function docstring_from_header_file\n\n→ void\ndocstring\n\n'
+ 'void docstring_from_header_file()'] ) ),
requests.codes.ok ],
# no docstring
[ { 'line_num': 7, 'column_num': 7 },
--- a/ycmd/tests/clangd/diagnostics_test.py
+++ b/ycmd/tests/clangd/diagnostics_test.py
@@ -567,30 +567,45 @@
# Assert diagnostics
for message in PollForMessages( app, messages_request ):
if 'diagnostics' in message:
- assert_that( message,
- has_entries( { 'diagnostics': contains_exactly(
- has_entries( {
- 'kind': equal_to( 'ERROR' ),
- 'text': "Use of undeclared identifier 'S' [undeclared_var_use]",
- 'ranges': contains_exactly( RangeMatcher(
- contains_string( source_file ), ( 2, 20 ), ( 2, 21 ) ) ),
- 'location': LocationMatcher(
- contains_string( source_file ), 2, 20 ),
- 'location_extent': RangeMatcher(
- contains_string( source_file ), ( 2, 20 ), ( 2, 21 ) )
- } ),
- has_entries( {
- 'kind': equal_to( 'WARNING' ),
- 'text': "Included header header.h is not used directly "
- "(fix available) [unused-includes]",
- 'ranges': contains_exactly( RangeMatcher(
- contains_string( source_file ), ( 1, 1 ), ( 1, 20 ) ) ),
- 'location': LocationMatcher(
- contains_string( source_file ), 1, 1 ),
- 'location_extent': RangeMatcher(
- contains_string( source_file ), ( 1, 1 ), ( 1, 20 ) )
- } ),
- ) } ) )
+ if len(message['diagnostics']) == 2:
+ assert_that( message,
+ has_entries( { 'diagnostics': contains_exactly(
+ has_entries( {
+ 'kind': equal_to( 'ERROR' ),
+ 'text': "Use of undeclared identifier 'S' [undeclared_var_use]",
+ 'ranges': contains_exactly( RangeMatcher(
+ contains_string( source_file ), ( 2, 20 ), ( 2, 21 ) ) ),
+ 'location': LocationMatcher(
+ contains_string( source_file ), 2, 20 ),
+ 'location_extent': RangeMatcher(
+ contains_string( source_file ), ( 2, 20 ), ( 2, 21 ) )
+ } ),
+ has_entries( {
+ 'kind': equal_to( 'WARNING' ),
+ 'text': "Included header header.h is not used directly "
+ "(fix available) [unused-includes]",
+ 'ranges': contains_exactly( RangeMatcher(
+ contains_string( source_file ), ( 1, 1 ), ( 1, 20 ) ) ),
+ 'location': LocationMatcher(
+ contains_string( source_file ), 1, 1 ),
+ 'location_extent': RangeMatcher(
+ contains_string( source_file ), ( 1, 1 ), ( 1, 20 ) )
+ } ),
+ ) } ) )
+ else:
+ assert_that( message,
+ has_entries( { 'diagnostics': contains_exactly(
+ has_entries( {
+ 'kind': equal_to( 'ERROR' ),
+ 'text': "Use of undeclared identifier 'S' [undeclared_var_use]",
+ 'ranges': contains_exactly( RangeMatcher(
+ contains_string( source_file ), ( 2, 20 ), ( 2, 21 ) ) ),
+ 'location': LocationMatcher(
+ contains_string( source_file ), 2, 20 ),
+ 'location_extent': RangeMatcher(
+ contains_string( source_file ), ( 2, 20 ), ( 2, 21 ) )
+ } ),
+ ) } ) )
break
# Restore original content
|