OLD | NEW |
1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. 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 """GYP backend that generates Eclipse CDT settings files. | 5 """GYP backend that generates Eclipse CDT settings files. |
6 | 6 |
7 This backend DOES NOT generate Eclipse CDT projects. Instead, it generates XML | 7 This backend DOES NOT generate Eclipse CDT projects. Instead, it generates XML |
8 files that can be imported into an Eclipse CDT project. The XML file contains a | 8 files that can be imported into an Eclipse CDT project. The XML file contains a |
9 list of include paths and symbols (i.e. defines). | 9 list of include paths and symbols (i.e. defines). |
10 | 10 |
11 Because a full .cproject definition is not created by this generator, it's not | 11 Because a full .cproject definition is not created by this generator, it's not |
12 possible to properly define the include dirs and symbols for each file | 12 possible to properly define the include dirs and symbols for each file |
13 individually. Instead, one set of includes/symbols is generated for the entire | 13 individually. Instead, one set of includes/symbols is generated for the entire |
14 project. This works fairly well (and is a vast improvement in general), but may | 14 project. This works fairly well (and is a vast improvement in general), but may |
15 still result in a few indexer issues here and there. | 15 still result in a few indexer issues here and there. |
16 | 16 |
17 This generator has no automated tests, so expect it to be broken. | 17 This generator has no automated tests, so expect it to be broken. |
18 """ | 18 """ |
19 | 19 |
| 20 from xml.sax.saxutils import escape |
20 import os.path | 21 import os.path |
21 import subprocess | 22 import subprocess |
22 import gyp | 23 import gyp |
23 import gyp.common | 24 import gyp.common |
24 import shlex | 25 import shlex |
25 | 26 |
26 generator_wants_static_library_dependencies_adjusted = False | 27 generator_wants_static_library_dependencies_adjusted = False |
27 | 28 |
28 generator_default_variables = { | 29 generator_default_variables = { |
29 } | 30 } |
30 | 31 |
31 for dirname in ['INTERMEDIATE_DIR', 'PRODUCT_DIR', 'LIB_DIR', 'SHARED_LIB_DIR']: | 32 for dirname in ['INTERMEDIATE_DIR', 'PRODUCT_DIR', 'LIB_DIR', 'SHARED_LIB_DIR']: |
32 # Some gyp steps fail if these are empty(!). | 33 # Some gyp steps fail if these are empty(!). |
33 generator_default_variables[dirname] = 'dir' | 34 generator_default_variables[dirname] = 'dir' |
34 | 35 |
35 for unused in ['RULE_INPUT_PATH', 'RULE_INPUT_ROOT', 'RULE_INPUT_NAME', | 36 for unused in ['RULE_INPUT_PATH', 'RULE_INPUT_ROOT', 'RULE_INPUT_NAME', |
36 'RULE_INPUT_DIRNAME', 'RULE_INPUT_EXT', | 37 'RULE_INPUT_DIRNAME', 'RULE_INPUT_EXT', |
37 'EXECUTABLE_PREFIX', 'EXECUTABLE_SUFFIX', | 38 'EXECUTABLE_PREFIX', 'EXECUTABLE_SUFFIX', |
38 'STATIC_LIB_PREFIX', 'STATIC_LIB_SUFFIX', | 39 'STATIC_LIB_PREFIX', 'STATIC_LIB_SUFFIX', |
39 'SHARED_LIB_PREFIX', 'SHARED_LIB_SUFFIX']: | 40 'SHARED_LIB_PREFIX', 'SHARED_LIB_SUFFIX', |
| 41 'CONFIGURATION_NAME']: |
40 generator_default_variables[unused] = '' | 42 generator_default_variables[unused] = '' |
41 | 43 |
42 # Include dirs will occasionaly use the SHARED_INTERMEDIATE_DIR variable as | 44 # Include dirs will occasionaly use the SHARED_INTERMEDIATE_DIR variable as |
43 # part of the path when dealing with generated headers. This value will be | 45 # part of the path when dealing with generated headers. This value will be |
44 # replaced dynamically for each configuration. | 46 # replaced dynamically for each configuration. |
45 generator_default_variables['SHARED_INTERMEDIATE_DIR'] = \ | 47 generator_default_variables['SHARED_INTERMEDIATE_DIR'] = \ |
46 '$SHARED_INTERMEDIATES_DIR' | 48 '$SHARED_INTERMEDIATES_DIR' |
47 | 49 |
48 | 50 |
49 def CalculateVariables(default_variables, params): | 51 def CalculateVariables(default_variables, params): |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 def WriteMacros(out, eclipse_langs, defines): | 211 def WriteMacros(out, eclipse_langs, defines): |
210 """Write the macros section of a CDT settings export file.""" | 212 """Write the macros section of a CDT settings export file.""" |
211 | 213 |
212 out.write(' <section name="org.eclipse.cdt.internal.ui.wizards.' \ | 214 out.write(' <section name="org.eclipse.cdt.internal.ui.wizards.' \ |
213 'settingswizards.Macros">\n') | 215 'settingswizards.Macros">\n') |
214 out.write(' <language name="holder for library settings"></language>\n') | 216 out.write(' <language name="holder for library settings"></language>\n') |
215 for lang in eclipse_langs: | 217 for lang in eclipse_langs: |
216 out.write(' <language name="%s">\n' % lang) | 218 out.write(' <language name="%s">\n' % lang) |
217 for key in sorted(defines.iterkeys()): | 219 for key in sorted(defines.iterkeys()): |
218 out.write(' <macro><name>%s</name><value>%s</value></macro>\n' % | 220 out.write(' <macro><name>%s</name><value>%s</value></macro>\n' % |
219 (key, defines[key])) | 221 (escape(key), escape(defines[key]))) |
220 out.write(' </language>\n') | 222 out.write(' </language>\n') |
221 out.write(' </section>\n') | 223 out.write(' </section>\n') |
222 | 224 |
223 | 225 |
224 def GenerateOutputForConfig(target_list, target_dicts, data, params, | 226 def GenerateOutputForConfig(target_list, target_dicts, data, params, |
225 config_name): | 227 config_name): |
226 options = params['options'] | 228 options = params['options'] |
227 generator_flags = params.get('generator_flags', {}) | 229 generator_flags = params.get('generator_flags', {}) |
228 | 230 |
229 # build_dir: relative path from source root to our output files. | 231 # build_dir: relative path from source root to our output files. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 user_config = params.get('generator_flags', {}).get('config', None) | 264 user_config = params.get('generator_flags', {}).get('config', None) |
263 if user_config: | 265 if user_config: |
264 GenerateOutputForConfig(target_list, target_dicts, data, params, | 266 GenerateOutputForConfig(target_list, target_dicts, data, params, |
265 user_config) | 267 user_config) |
266 else: | 268 else: |
267 config_names = target_dicts[target_list[0]]['configurations'].keys() | 269 config_names = target_dicts[target_list[0]]['configurations'].keys() |
268 for config_name in config_names: | 270 for config_name in config_names: |
269 GenerateOutputForConfig(target_list, target_dicts, data, params, | 271 GenerateOutputForConfig(target_list, target_dicts, data, params, |
270 config_name) | 272 config_name) |
271 | 273 |
OLD | NEW |