[ycm] Fix YouCompleteMe config

The .ycm_extra_conf.py is out of date with the current build settings
and ycm versions. In particular, ycm expects a `Settings` function,
a couple of more flags need to be passed and some includes are marked
-isystem now. Also, we can use the C++ standard from the ninja files
instead of hard-coding it.

Change-Id: Ibaed29eb341346a86b6b736f95c97b41957f62de
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3980257
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Michael Achenbach <machenbach@chromium.org>
Auto-Submit: Olivier Flückiger <olivf@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84013}
This commit is contained in:
Olivier Flückiger 2022-10-26 08:19:31 +00:00 committed by V8 LUCI CQ
parent cecd01ac18
commit 5a2eb4a2aa

View File

@ -42,7 +42,6 @@ import sys
# Flags from YCM's default config. # Flags from YCM's default config.
flags = [ flags = [
'-DUSE_CLANG_COMPLETER', '-DUSE_CLANG_COMPLETER',
'-std=gnu++14',
'-x', '-x',
'c++', 'c++',
] ]
@ -143,25 +142,27 @@ def GetClangCommandFromNinjaForFilename(v8_root, filename):
# Parse flags that are important for YCM's purposes. # Parse flags that are important for YCM's purposes.
for flag in clang_line.split(' '): for flag in clang_line.split(' '):
if flag.startswith('-I'): if flag.startswith('-I'):
# Relative paths need to be resolved, because they're relative to the v8_flags.append(MakeIncludePathAbsolute(flag, "-I", out_dir))
# output dir, not the source. elif flag.startswith('-isystem'):
if flag[2] == '/': v8_flags.append(MakeIncludePathAbsolute(flag, "-isystem", out_dir))
v8_flags.append(flag) elif flag.startswith('-std') or flag.startswith(
else: '-pthread') or flag.startswith('-no'):
abs_path = os.path.normpath(os.path.join(out_dir, flag[2:]))
v8_flags.append('-I' + abs_path)
elif flag.startswith('-std'):
v8_flags.append(flag) v8_flags.append(flag)
elif flag.startswith('-') and flag[1] in 'DWFfmO': elif flag.startswith('-') and flag[1] in 'DWFfmgOX':
if flag == '-Wno-deprecated-register' or flag == '-Wno-header-guard':
# These flags causes libclang (3.3) to crash. Remove it until things
# are fixed.
continue
v8_flags.append(flag) v8_flags.append(flag)
return v8_flags return v8_flags
def MakeIncludePathAbsolute(flag, prefix, out_dir):
# Relative paths need to be resolved, because they're relative to the
# output dir, not the source.
if flag[len(prefix)] == '/':
return flag
else:
abs_path = os.path.normpath(os.path.join(out_dir, flag[len(prefix):]))
return prefix + abs_path
def FlagsForFile(filename): def FlagsForFile(filename):
"""This is the main entry point for YCM. Its interface is fixed. """This is the main entry point for YCM. Its interface is fixed.
@ -180,3 +181,9 @@ def FlagsForFile(filename):
'flags': final_flags, 'flags': final_flags,
'do_cache': True 'do_cache': True
} }
def Settings(**kwargs):
if kwargs['language'] == 'cfamily':
return FlagsForFile(kwargs['filename'])
return {}