Chromium Code Reviews| 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 20 matching lines...) Expand all Loading... | |
| 31 # * Right now, we only pull the -I and -D flags. That seems to be sufficient | 31 # * Right now, we only pull the -I and -D flags. That seems to be sufficient |
| 32 # for everything I've used it for. | 32 # for everything I've used it for. |
| 33 # | 33 # |
| 34 # * That whole ninja & clang thing? We could support other configs if someone | 34 # * That whole ninja & clang thing? We could support other configs if someone |
| 35 # were willing to write the correct commands and a parser. | 35 # were willing to write the correct commands and a parser. |
| 36 # | 36 # |
| 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 subprocess | 42 import subprocess |
| 42 | 43 |
| 43 | 44 |
| 44 # Flags from YCM's default config. | 45 # Flags from YCM's default config. |
| 45 flags = [ | 46 flags = [ |
| 46 '-DUSE_CLANG_COMPLETER', | 47 '-DUSE_CLANG_COMPLETER', |
| 47 '-std=c++11', | 48 '-std=c++11', |
| 48 '-x', | 49 '-x', |
| 49 'c++', | 50 'c++', |
| 50 ] | 51 ] |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 else: | 159 else: |
| 159 if filename.startswith(blink_root): | 160 if filename.startswith(blink_root): |
| 160 # If this is a Blink file, we can at least try to get a reasonable | 161 # If this is a Blink file, we can at least try to get a reasonable |
| 161 # approximation. | 162 # approximation. |
| 162 filename = default_blink_file | 163 filename = default_blink_file |
| 163 else: | 164 else: |
| 164 # If this is a standalone .h file with no source, the best we can do is | 165 # If this is a standalone .h file with no source, the best we can do is |
| 165 # try to use the default flags. | 166 # try to use the default flags. |
| 166 return chrome_flags | 167 return chrome_flags |
| 167 | 168 |
| 168 # Ninja needs the path to the source file from the output build directory. | 169 out_dir = GetNinjaOutputDirectory(chrome_root) |
| 169 # Cut off the common part and /. | |
| 170 subdir_filename = filename[len(chrome_root)+1:] | |
| 171 rel_filename = os.path.join('..', '..', subdir_filename) | |
| 172 | 170 |
| 173 out_dir = GetNinjaOutputDirectory(chrome_root) | 171 # Ninja needs the path to the source file relative to the output build |
| 172 # directory. | |
| 173 rel_filename = os.path.relpath(os.path.realpath(filename), | |
|
eroman
2014/08/29 19:23:22
much nicer!
| |
| 174 os.path.realpath(out_dir)) | |
| 174 | 175 |
| 175 # Ask ninja how it would build our source file. | 176 # Ask ninja how it would build our source file. |
| 176 p = subprocess.Popen(['ninja', '-v', '-C', out_dir, '-t', | 177 p = subprocess.Popen(['ninja', '-v', '-C', out_dir, '-t', |
| 177 'commands', rel_filename + '^'], | 178 'commands', rel_filename + '^'], |
| 178 stdout=subprocess.PIPE) | 179 stdout=subprocess.PIPE) |
| 179 stdout, stderr = p.communicate() | 180 stdout, stderr = p.communicate() |
| 180 if p.returncode: | 181 if p.returncode: |
| 181 return chrome_flags | 182 return chrome_flags |
| 182 | 183 |
| 183 # Ninja might execute several commands to build something. We want the last | 184 # Ninja might execute several commands to build something. We want the last |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 """ | 226 """ |
| 226 chrome_root = FindChromeSrcFromFilename(filename) | 227 chrome_root = FindChromeSrcFromFilename(filename) |
| 227 chrome_flags = GetClangCommandFromNinjaForFilename(chrome_root, | 228 chrome_flags = GetClangCommandFromNinjaForFilename(chrome_root, |
| 228 filename) | 229 filename) |
| 229 final_flags = flags + chrome_flags | 230 final_flags = flags + chrome_flags |
| 230 | 231 |
| 231 return { | 232 return { |
| 232 'flags': final_flags, | 233 'flags': final_flags, |
| 233 'do_cache': True | 234 'do_cache': True |
| 234 } | 235 } |
| OLD | NEW |