OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 Simply checks parent directories until it finds .gclient and src/. | 74 Simply checks parent directories until it finds .gclient and src/. |
75 | 75 |
76 Args: | 76 Args: |
77 filename: (String) Path to source file being edited. | 77 filename: (String) Path to source file being edited. |
78 | 78 |
79 Returns: | 79 Returns: |
80 (String) Path of 'src/', or None if unable to find. | 80 (String) Path of 'src/', or None if unable to find. |
81 """ | 81 """ |
82 curdir = os.path.normpath(os.path.dirname(filename)) | 82 curdir = os.path.normpath(os.path.dirname(filename)) |
83 while not (os.path.basename(os.path.realpath(curdir)) == 'src' | 83 while not (os.path.basename(curdir) == 'src' |
84 and PathExists(curdir, 'DEPS') | 84 and PathExists(curdir, 'DEPS') |
85 and (PathExists(curdir, '..', '.gclient') | 85 and (PathExists(curdir, '..', '.gclient') |
86 or PathExists(curdir, '.git'))): | 86 or PathExists(curdir, '.git'))): |
87 nextdir = os.path.normpath(os.path.join(curdir, '..')) | 87 nextdir = os.path.normpath(os.path.join(curdir, '..')) |
88 if nextdir == curdir: | 88 if nextdir == curdir: |
89 return None | 89 return None |
90 curdir = nextdir | 90 curdir = nextdir |
91 return curdir | 91 return curdir |
92 | 92 |
93 | 93 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 Args: | 152 Args: |
153 out_dir: (String) Absolute path to ninja build output directory. | 153 out_dir: (String) Absolute path to ninja build output directory. |
154 filename: (String) Absolute path to source file. | 154 filename: (String) Absolute path to source file. |
155 | 155 |
156 Returns: | 156 Returns: |
157 (List of Strings) List of target names. Will return [] if |filename| doesn't | 157 (List of Strings) List of target names. Will return [] if |filename| doesn't |
158 yield any .o or .obj outputs. | 158 yield any .o or .obj outputs. |
159 """ | 159 """ |
160 # Ninja needs the path to the source file relative to the output build | 160 # Ninja needs the path to the source file relative to the output build |
161 # directory. | 161 # directory. |
162 rel_filename = os.path.relpath(os.path.realpath(filename), out_dir) | 162 rel_filename = os.path.relpath(filename, out_dir) |
163 | 163 |
164 p = subprocess.Popen(['ninja', '-C', out_dir, '-t', 'query', rel_filename], | 164 p = subprocess.Popen(['ninja', '-C', out_dir, '-t', 'query', rel_filename], |
165 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | 165 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, |
166 universal_newlines=True) | 166 universal_newlines=True) |
167 stdout, _ = p.communicate() | 167 stdout, _ = p.communicate() |
168 if p.returncode != 0: | 168 if p.returncode != 0: |
169 return [] | 169 return [] |
170 | 170 |
171 # The output looks like: | 171 # The output looks like: |
172 # ../../relative/path/to/source.cc: | 172 # ../../relative/path/to/source.cc: |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 additional_flags = ['-I' + os.path.join(chrome_root)] | 313 additional_flags = ['-I' + os.path.join(chrome_root)] |
314 | 314 |
315 # Version of Clang used to compile Chromium can be newer then version of | 315 # Version of Clang used to compile Chromium can be newer then version of |
316 # libclang that YCM uses for completion. So it's possible that YCM's libclang | 316 # libclang that YCM uses for completion. So it's possible that YCM's libclang |
317 # doesn't know about some used warning options, which causes compilation | 317 # doesn't know about some used warning options, which causes compilation |
318 # warnings (and errors, because of '-Werror'); | 318 # warnings (and errors, because of '-Werror'); |
319 additional_flags.append('-Wno-unknown-warning-option') | 319 additional_flags.append('-Wno-unknown-warning-option') |
320 | 320 |
321 sys.path.append(os.path.join(chrome_root, 'tools', 'vim')) | 321 sys.path.append(os.path.join(chrome_root, 'tools', 'vim')) |
322 from ninja_output import GetNinjaOutputDirectory | 322 from ninja_output import GetNinjaOutputDirectory |
323 out_dir = os.path.realpath(GetNinjaOutputDirectory(chrome_root)) | 323 out_dir = GetNinjaOutputDirectory(chrome_root) |
324 | 324 |
325 clang_line = GetClangCommandLineFromNinjaForSource( | 325 clang_line = GetClangCommandLineFromNinjaForSource( |
326 out_dir, GetBuildableSourceFile(chrome_root, filename)) | 326 out_dir, GetBuildableSourceFile(chrome_root, filename)) |
327 if not clang_line: | 327 if not clang_line: |
328 # If ninja didn't know about filename or it's companion files, then try a | 328 # If ninja didn't know about filename or it's companion files, then try a |
329 # default build target. It is possible that the file is new, or build.ninja | 329 # default build target. It is possible that the file is new, or build.ninja |
330 # is stale. | 330 # is stale. |
331 clang_line = GetClangCommandLineFromNinjaForSource( | 331 clang_line = GetClangCommandLineFromNinjaForSource( |
332 out_dir, GetDefaultSourceFile(chrome_root, filename)) | 332 out_dir, GetDefaultSourceFile(chrome_root, filename)) |
333 | 333 |
(...skipping 22 matching lines...) Expand all Loading... |
356 # transient failure. Preventing YCM from caching the flags allows us to try to | 356 # transient failure. Preventing YCM from caching the flags allows us to try to |
357 # determine the flags again. | 357 # determine the flags again. |
358 should_cache_flags_for_file = bool(clang_flags) | 358 should_cache_flags_for_file = bool(clang_flags) |
359 | 359 |
360 final_flags = _default_flags + clang_flags | 360 final_flags = _default_flags + clang_flags |
361 | 361 |
362 return { | 362 return { |
363 'flags': final_flags, | 363 'flags': final_flags, |
364 'do_cache': should_cache_flags_for_file | 364 'do_cache': should_cache_flags_for_file |
365 } | 365 } |
OLD | NEW |