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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 Returns: | 123 Returns: |
124 (List of Strings) Command line arguments for clang. | 124 (List of Strings) Command line arguments for clang. |
125 """ | 125 """ |
126 if not chrome_root: | 126 if not chrome_root: |
127 return [] | 127 return [] |
128 | 128 |
129 # Generally, everyone benefits from including Chromium's src/, because all of | 129 # Generally, everyone benefits from including Chromium's src/, because all of |
130 # Chromium's includes are relative to that. | 130 # Chromium's includes are relative to that. |
131 chrome_flags = ['-I' + os.path.join(chrome_root)] | 131 chrome_flags = ['-I' + os.path.join(chrome_root)] |
132 | 132 |
| 133 # Default file to get a reasonable approximation of the flags for a Blink |
| 134 # file. |
| 135 blink_root = os.path.join(chrome_root, 'third_party', 'WebKit') |
| 136 default_blink_file = os.path.join(blink_root, 'Source', 'core', 'Init.cpp') |
| 137 |
133 # Header files can't be built. Instead, try to match a header file to its | 138 # Header files can't be built. Instead, try to match a header file to its |
134 # corresponding source file. | 139 # corresponding source file. |
135 if filename.endswith('.h'): | 140 if filename.endswith('.h'): |
| 141 # Add config.h to Blink headers, which won't have it by default. |
| 142 if filename.startswith(blink_root): |
| 143 chrome_flags.append('-include') |
| 144 chrome_flags.append(os.path.join(blink_root, 'Source', 'config.h')) |
| 145 |
136 alternates = ['.cc', '.cpp'] | 146 alternates = ['.cc', '.cpp'] |
137 for alt_extension in alternates: | 147 for alt_extension in alternates: |
138 alt_name = filename[:-2] + alt_extension | 148 alt_name = filename[:-2] + alt_extension |
139 if os.path.exists(alt_name): | 149 if os.path.exists(alt_name): |
140 filename = alt_name | 150 filename = alt_name |
141 break | 151 break |
142 else: | 152 else: |
143 # If this is a standalone .h file with no source, the best we can do is | 153 if filename.startswith(blink_root): |
144 # try to use the default flags. | 154 # If this is a Blink file, we can at least try to get a reasonable |
145 return chrome_flags | 155 # approximation. |
| 156 filename = default_blink_file |
| 157 else: |
| 158 # If this is a standalone .h file with no source, the best we can do is |
| 159 # try to use the default flags. |
| 160 return chrome_flags |
146 | 161 |
147 # Ninja needs the path to the source file from the output build directory. | 162 # Ninja needs the path to the source file from the output build directory. |
148 # Cut off the common part and /. | 163 # Cut off the common part and /. |
149 subdir_filename = filename[len(chrome_root)+1:] | 164 subdir_filename = filename[len(chrome_root)+1:] |
150 rel_filename = os.path.join('..', '..', subdir_filename) | 165 rel_filename = os.path.join('..', '..', subdir_filename) |
151 | 166 |
152 out_dir = GetNinjaOutputDirectory(chrome_root) | 167 out_dir = GetNinjaOutputDirectory(chrome_root) |
153 | 168 |
154 # Ask ninja how it would build our source file. | 169 # Ask ninja how it would build our source file. |
155 p = subprocess.Popen(['ninja', '-v', '-C', out_dir, '-t', | 170 p = subprocess.Popen(['ninja', '-v', '-C', out_dir, '-t', |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 """ | 219 """ |
205 chrome_root = FindChromeSrcFromFilename(filename) | 220 chrome_root = FindChromeSrcFromFilename(filename) |
206 chrome_flags = GetClangCommandFromNinjaForFilename(chrome_root, | 221 chrome_flags = GetClangCommandFromNinjaForFilename(chrome_root, |
207 filename) | 222 filename) |
208 final_flags = flags + chrome_flags | 223 final_flags = flags + chrome_flags |
209 | 224 |
210 return { | 225 return { |
211 'flags': final_flags, | 226 'flags': final_flags, |
212 'do_cache': True | 227 'do_cache': True |
213 } | 228 } |
OLD | NEW |