Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: tools/vim/chromium.ycm_extra_conf.py

Issue 1137303005: [Vim/YCM] Calculate system library paths based on Clang++ binary path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # Autocompletion config for YouCompleteMe in Chromium. 5 # Autocompletion config for YouCompleteMe in Chromium.
6 # 6 #
7 # USAGE: 7 # USAGE:
8 # 8 #
9 # 1. Install YCM [https://github.com/Valloric/YouCompleteMe] 9 # 1. Install YCM [https://github.com/Valloric/YouCompleteMe]
10 # (Googlers should check out [go/ycm]) 10 # (Googlers should check out [go/ycm])
(...skipping 26 matching lines...) Expand all
37 # * This has only been tested on gPrecise. 37 # * This has only been tested on gPrecise.
38 38
39 39
40 import os 40 import os
41 import os.path 41 import os.path
42 import re 42 import re
43 import subprocess 43 import subprocess
44 import sys 44 import sys
45 45
46 46
47 def SystemIncludeDirectoryFlags(): 47 def SystemIncludeDirectoryFlags(clang_binary, clang_flags):
48 """Determines compile flags to include the system include directories. 48 """Determines compile flags to include the system include directories.
49 49
50 Use as a workaround for https://github.com/Valloric/YouCompleteMe/issues/303 50 Use as a workaround for https://github.com/Valloric/YouCompleteMe/issues/303
51 51
52 Args:
53 clang_binary: (String) Path to clang binary.
54 clang_flags: (List of Strings) List of additional flags to clang. It may
55 affect the choice of system include directories if -stdlib= is specified.
56
52 Returns: 57 Returns:
53 (List of Strings) Compile flags to append. 58 (List of Strings) Compile flags to append.
54 """ 59 """
60 all_flags = ['-v', '-E', '-x', 'c++'] + clang_flags + ['-']
55 try: 61 try:
56 with open(os.devnull, 'rb') as DEVNULL: 62 with open(os.devnull, 'rb') as DEVNULL:
57 output = subprocess.check_output(['clang', '-v', '-E', '-x', 'c++', '-'], 63 output = subprocess.check_output([clang_binary] + all_flags,
58 stdin=DEVNULL, stderr=subprocess.STDOUT) 64 stdin=DEVNULL, stderr=subprocess.STDOUT)
59 except: 65 except:
60 return [] 66 return []
61 includes_regex = r'#include <\.\.\.> search starts here:\s*' \ 67 includes_regex = r'#include <\.\.\.> search starts here:\s*' \
62 r'(.*?)End of search list\.' 68 r'(.*?)End of search list\.'
63 includes = re.search(includes_regex, output.decode(), re.DOTALL).group(1) 69 includes = re.search(includes_regex, output.decode(), re.DOTALL).group(1)
64 flags = [] 70 flags = []
65 for path in includes.splitlines(): 71 for path in includes.splitlines():
66 path = path.strip() 72 path = path.strip()
67 if os.path.isdir(path): 73 if os.path.isdir(path):
68 flags.append('-isystem') 74 flags.append('-isystem')
69 flags.append(path) 75 flags.append(path)
70 return flags 76 return flags
71 77
72
73 _system_include_flags = SystemIncludeDirectoryFlags()
74
75 # Flags from YCM's default config. 78 # Flags from YCM's default config.
76 flags = [ 79 _default_flags = [
77 '-DUSE_CLANG_COMPLETER', 80 '-DUSE_CLANG_COMPLETER',
78 '-std=c++11', 81 '-std=c++11',
79 '-x', 82 '-x',
80 'c++', 83 'c++',
81 ] 84 ]
82 85
83
84 def PathExists(*args): 86 def PathExists(*args):
85 return os.path.exists(os.path.join(*args)) 87 return os.path.exists(os.path.join(*args))
86 88
87 89
88 def FindChromeSrcFromFilename(filename): 90 def FindChromeSrcFromFilename(filename):
89 """Searches for the root of the Chromium checkout. 91 """Searches for the root of the Chromium checkout.
90 92
91 Simply checks parent directories until it finds .gclient and src/. 93 Simply checks parent directories until it finds .gclient and src/.
92 94
93 Args: 95 Args:
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 chrome_flags.append('-I' + abs_path) 203 chrome_flags.append('-I' + abs_path)
202 elif flag.startswith('-std'): 204 elif flag.startswith('-std'):
203 chrome_flags.append(flag) 205 chrome_flags.append(flag)
204 elif flag.startswith('-') and flag[1] in 'DWFfmO': 206 elif flag.startswith('-') and flag[1] in 'DWFfmO':
205 if flag == '-Wno-deprecated-register' or flag == '-Wno-header-guard': 207 if flag == '-Wno-deprecated-register' or flag == '-Wno-header-guard':
206 # These flags causes libclang (3.3) to crash. Remove it until things 208 # These flags causes libclang (3.3) to crash. Remove it until things
207 # are fixed. 209 # are fixed.
208 continue 210 continue
209 chrome_flags.append(flag) 211 chrome_flags.append(flag)
210 212
213 clang_path = clang_line.split(' ')[0]
eroman 2015/05/18 17:56:42 This is too simplistic, the "path" may contain spa
asanka 2015/05/18 19:36:48 That's also a no-go due to the gomacc wrapper not
214 if clang_path.endswith('clang++'):
215 chrome_flags += SystemIncludeDirectoryFlags(clang_path, chrome_flags)
216
211 return chrome_flags 217 return chrome_flags
212 218
213 219
214 def FlagsForFile(filename): 220 def FlagsForFile(filename):
215 """This is the main entry point for YCM. Its interface is fixed. 221 """This is the main entry point for YCM. Its interface is fixed.
216 222
217 Args: 223 Args:
218 filename: (String) Path to source file being edited. 224 filename: (String) Path to source file being edited.
219 225
220 Returns: 226 Returns:
221 (Dictionary) 227 (Dictionary)
222 'flags': (List of Strings) Command line flags. 228 'flags': (List of Strings) Command line flags.
223 'do_cache': (Boolean) True if the result should be cached. 229 'do_cache': (Boolean) True if the result should be cached.
224 """ 230 """
225 chrome_root = FindChromeSrcFromFilename(filename) 231 chrome_root = FindChromeSrcFromFilename(filename)
226 chrome_flags = GetClangCommandFromNinjaForFilename(chrome_root, 232 chrome_flags = GetClangCommandFromNinjaForFilename(chrome_root,
227 filename) 233 filename)
228 final_flags = flags + chrome_flags + _system_include_flags 234 final_flags = _default_flags + chrome_flags
229 235
230 return { 236 return {
231 'flags': final_flags, 237 'flags': final_flags,
232 'do_cache': True 238 'do_cache': True
233 } 239 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698