OLD | NEW |
1 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 1 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
2 # | 2 # |
3 # Use of this source code is governed by a BSD-style license | 3 # Use of this source code is governed by a BSD-style license |
4 # that can be found in the LICENSE file in the root of the source | 4 # that can be found in the LICENSE file in the root of the source |
5 # tree. An additional intellectual property rights grant can be found | 5 # tree. An additional intellectual property rights grant can be found |
6 # in the file PATENTS. All contributing project authors may | 6 # in the file PATENTS. All contributing project authors may |
7 # be found in the AUTHORS file in the root of the source tree. | 7 # be found in the AUTHORS file in the root of the source tree. |
8 | 8 |
9 # Autocompletion config for YouCompleteMe in WebRTC. This is just copied from | 9 # Autocompletion config for YouCompleteMe in WebRTC. This is just copied from |
10 # tools/vim in chromium with very minor modifications. | 10 # tools/vim in chromium with very minor modifications. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 # * This has only been tested on gPrecise. | 54 # * This has only been tested on gPrecise. |
55 | 55 |
56 | 56 |
57 import os | 57 import os |
58 import os.path | 58 import os.path |
59 import shlex | 59 import shlex |
60 import subprocess | 60 import subprocess |
61 import sys | 61 import sys |
62 | 62 |
63 # Flags from YCM's default config. | 63 # Flags from YCM's default config. |
64 _default_flags = [ | 64 _DEFAULT_FLAGS = [ |
65 '-DUSE_CLANG_COMPLETER', | 65 '-DUSE_CLANG_COMPLETER', |
66 '-std=c++11', | 66 '-std=c++11', |
67 '-x', | 67 '-x', |
68 'c++', | 68 'c++', |
69 ] | 69 ] |
70 | 70 |
71 _header_alternates = ('.cc', '.cpp', '.c', '.mm', '.m') | 71 _HEADER_ALTERNATES = ('.cc', '.cpp', '.c', '.mm', '.m') |
72 | 72 |
73 _extension_flags = { | 73 _EXTENSION_FLAGS = { |
74 '.m': ['-x', 'objective-c'], | 74 '.m': ['-x', 'objective-c'], |
75 '.mm': ['-x', 'objective-c++'], | 75 '.mm': ['-x', 'objective-c++'], |
76 } | 76 } |
77 | 77 |
78 def PathExists(*args): | 78 def PathExists(*args): |
79 return os.path.exists(os.path.join(*args)) | 79 return os.path.exists(os.path.join(*args)) |
80 | 80 |
81 | 81 |
82 def FindWebrtcSrcFromFilename(filename): | 82 def FindWebrtcSrcFromFilename(filename): |
83 """Searches for the root of the WebRTC checkout. | 83 """Searches for the root of the WebRTC checkout. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 # doesn't know about some used warning options, which causes compilation | 295 # doesn't know about some used warning options, which causes compilation |
296 # warnings (and errors, because of '-Werror'); | 296 # warnings (and errors, because of '-Werror'); |
297 additional_flags.append('-Wno-unknown-warning-option') | 297 additional_flags.append('-Wno-unknown-warning-option') |
298 | 298 |
299 sys.path.append(os.path.join(webrtc_root, 'tools', 'vim')) | 299 sys.path.append(os.path.join(webrtc_root, 'tools', 'vim')) |
300 from ninja_output import GetNinjaOutputDirectory | 300 from ninja_output import GetNinjaOutputDirectory |
301 out_dir = GetNinjaOutputDirectory(webrtc_root) | 301 out_dir = GetNinjaOutputDirectory(webrtc_root) |
302 | 302 |
303 basename, extension = os.path.splitext(filename) | 303 basename, extension = os.path.splitext(filename) |
304 if extension == '.h': | 304 if extension == '.h': |
305 candidates = [basename + ext for ext in _header_alternates] | 305 candidates = [basename + ext for ext in _HEADER_ALTERNATES] |
306 else: | 306 else: |
307 candidates = [filename] | 307 candidates = [filename] |
308 | 308 |
309 clang_line = None | 309 clang_line = None |
310 buildable_extension = extension | 310 buildable_extension = extension |
311 for candidate in candidates: | 311 for candidate in candidates: |
312 clang_line = GetClangCommandLineFromNinjaForSource(out_dir, candidate) | 312 clang_line = GetClangCommandLineFromNinjaForSource(out_dir, candidate) |
313 if clang_line: | 313 if clang_line: |
314 buildable_extension = os.path.splitext(candidate)[1] | 314 buildable_extension = os.path.splitext(candidate)[1] |
315 break | 315 break |
316 | 316 |
317 additional_flags += _extension_flags.get(buildable_extension, []) | 317 additional_flags += _EXTENSION_FLAGS.get(buildable_extension, []) |
318 | 318 |
319 if not clang_line: | 319 if not clang_line: |
320 # If ninja didn't know about filename or it's companion files, then try a | 320 # If ninja didn't know about filename or it's companion files, then try a |
321 # default build target. It is possible that the file is new, or build.ninja | 321 # default build target. It is possible that the file is new, or build.ninja |
322 # is stale. | 322 # is stale. |
323 clang_line = GetClangCommandLineFromNinjaForSource( | 323 clang_line = GetClangCommandLineFromNinjaForSource( |
324 out_dir, GetDefaultSourceFile(webrtc_root, filename)) | 324 out_dir, GetDefaultSourceFile(webrtc_root, filename)) |
325 | 325 |
326 if not clang_line: | 326 if not clang_line: |
327 return additional_flags | 327 return additional_flags |
(...skipping 14 matching lines...) Expand all Loading... |
342 """ | 342 """ |
343 abs_filename = os.path.abspath(filename) | 343 abs_filename = os.path.abspath(filename) |
344 webrtc_root = FindWebrtcSrcFromFilename(abs_filename) | 344 webrtc_root = FindWebrtcSrcFromFilename(abs_filename) |
345 clang_flags = GetClangOptionsFromNinjaForFilename(webrtc_root, abs_filename) | 345 clang_flags = GetClangOptionsFromNinjaForFilename(webrtc_root, abs_filename) |
346 | 346 |
347 # If clang_flags could not be determined, then assume that was due to a | 347 # If clang_flags could not be determined, then assume that was due to a |
348 # transient failure. Preventing YCM from caching the flags allows us to try to | 348 # transient failure. Preventing YCM from caching the flags allows us to try to |
349 # determine the flags again. | 349 # determine the flags again. |
350 should_cache_flags_for_file = bool(clang_flags) | 350 should_cache_flags_for_file = bool(clang_flags) |
351 | 351 |
352 final_flags = _default_flags + clang_flags | 352 final_flags = _DEFAULT_FLAGS + clang_flags |
353 | 353 |
354 return { | 354 return { |
355 'flags': final_flags, | 355 'flags': final_flags, |
356 'do_cache': should_cache_flags_for_file | 356 'do_cache': should_cache_flags_for_file |
357 } | 357 } |
OLD | NEW |