| 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 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 rel_paths.add(os.path.relpath(path, toplevel_dir)) | 351 rel_paths.add(os.path.relpath(path, toplevel_dir)) |
| 352 else: | 352 else: |
| 353 rel_paths.add(path) | 353 rel_paths.add(path) |
| 354 | 354 |
| 355 for path in sorted(rel_paths): | 355 for path in sorted(rel_paths): |
| 356 entry_element = ET.SubElement(result, 'classpathentry') | 356 entry_element = ET.SubElement(result, 'classpathentry') |
| 357 entry_element.set('kind', kind) | 357 entry_element.set('kind', kind) |
| 358 entry_element.set('path', path) | 358 entry_element.set('path', path) |
| 359 | 359 |
| 360 AddElements('lib', GetJavaJars(target_list, target_dicts, toplevel_dir)) | 360 AddElements('lib', GetJavaJars(target_list, target_dicts, toplevel_dir)) |
| 361 AddElements('src', GetJavaSourceDirs(target_list, target_dicts)) | 361 AddElements('src', GetJavaSourceDirs(target_list, target_dicts, toplevel_dir)) |
| 362 # Include the standard JRE container and a dummy out folder | 362 # Include the standard JRE container and a dummy out folder |
| 363 AddElements('con', ['org.eclipse.jdt.launching.JRE_CONTAINER']) | 363 AddElements('con', ['org.eclipse.jdt.launching.JRE_CONTAINER']) |
| 364 # Include a dummy out folder so that Eclipse doesn't use the default /bin | 364 # Include a dummy out folder so that Eclipse doesn't use the default /bin |
| 365 # folder in the root of the project. | 365 # folder in the root of the project. |
| 366 AddElements('output', [os.path.join(toplevel_build, '.eclipse-java-build')]) | 366 AddElements('output', [os.path.join(toplevel_build, '.eclipse-java-build')]) |
| 367 | 367 |
| 368 ET.ElementTree(result).write(out_name) | 368 ET.ElementTree(result).write(out_name) |
| 369 | 369 |
| 370 | 370 |
| 371 def GetJavaJars(target_list, target_dicts, toplevel_dir): | 371 def GetJavaJars(target_list, target_dicts, toplevel_dir): |
| 372 '''Generates a sequence of all .jars used as inputs.''' | 372 '''Generates a sequence of all .jars used as inputs.''' |
| 373 for target_name in target_list: | 373 for target_name in target_list: |
| 374 target = target_dicts[target_name] | 374 target = target_dicts[target_name] |
| 375 for action in target.get('actions', []): | 375 for action in target.get('actions', []): |
| 376 for input_ in action['inputs']: | 376 for input_ in action['inputs']: |
| 377 if os.path.splitext(input_)[1] == '.jar' and not input_.startswith('$'): | 377 if os.path.splitext(input_)[1] == '.jar' and not input_.startswith('$'): |
| 378 if os.path.isabs(input_): | 378 if os.path.isabs(input_): |
| 379 yield input_ | 379 yield input_ |
| 380 else: | 380 else: |
| 381 yield os.path.join(os.path.dirname(target_name), input_) | 381 yield os.path.join(os.path.dirname(target_name), input_) |
| 382 | 382 |
| 383 | 383 |
| 384 def GetJavaSourceDirs(target_list, target_dicts): | 384 def GetJavaSourceDirs(target_list, target_dicts, toplevel_dir): |
| 385 '''Generates a sequence of all likely java package root directories.''' | 385 '''Generates a sequence of all likely java package root directories.''' |
| 386 for target_name in target_list: | 386 for target_name in target_list: |
| 387 target = target_dicts[target_name] | 387 target = target_dicts[target_name] |
| 388 for action in target.get('actions', []): | 388 for action in target.get('actions', []): |
| 389 for input_ in action['inputs']: | 389 for input_ in action['inputs']: |
| 390 if (os.path.splitext(input_)[1] == '.java' and | 390 if (os.path.splitext(input_)[1] == '.java' and |
| 391 not input_.startswith('$')): | 391 not input_.startswith('$')): |
| 392 dir_ = os.path.dirname(os.path.join(os.path.dirname(target_name), | 392 dir_ = os.path.dirname(os.path.join(os.path.dirname(target_name), |
| 393 input_)) | 393 input_)) |
| 394 # If there is a parent 'src' or 'java' folder, navigate up to it - | 394 # If there is a parent 'src' or 'java' folder, navigate up to it - |
| 395 # these are canonical package root names in Chromium. This will | 395 # these are canonical package root names in Chromium. This will |
| 396 # break if 'src' or 'java' exists in the package structure. This | 396 # break if 'src' or 'java' exists in the package structure. This |
| 397 # could be further improved by inspecting the java file for the | 397 # could be further improved by inspecting the java file for the |
| 398 # package name if this proves to be too fragile in practice. | 398 # package name if this proves to be too fragile in practice. |
| 399 parent_search = dir_ | 399 parent_search = dir_ |
| 400 while os.path.basename(parent_search) not in ['src', 'java']: | 400 while os.path.basename(parent_search) not in ['src', 'java']: |
| 401 parent_search, _ = os.path.split(parent_search) | 401 parent_search, _ = os.path.split(parent_search) |
| 402 if not parent_search: | 402 if not parent_search or parent_search == toplevel_dir: |
| 403 # Didn't find a known root, just return the original path | 403 # Didn't find a known root, just return the original path |
| 404 yield dir_ | 404 yield dir_ |
| 405 break | 405 break |
| 406 else: | 406 else: |
| 407 yield parent_search | 407 yield parent_search |
| 408 | 408 |
| 409 | 409 |
| 410 def GenerateOutput(target_list, target_dicts, data, params): | 410 def GenerateOutput(target_list, target_dicts, data, params): |
| 411 """Generate an XML settings file that can be imported into a CDT project.""" | 411 """Generate an XML settings file that can be imported into a CDT project.""" |
| 412 | 412 |
| 413 if params['options'].generator_output: | 413 if params['options'].generator_output: |
| 414 raise NotImplementedError("--generator_output not implemented for eclipse") | 414 raise NotImplementedError("--generator_output not implemented for eclipse") |
| 415 | 415 |
| 416 user_config = params.get('generator_flags', {}).get('config', None) | 416 user_config = params.get('generator_flags', {}).get('config', None) |
| 417 if user_config: | 417 if user_config: |
| 418 GenerateOutputForConfig(target_list, target_dicts, data, params, | 418 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 419 user_config) | 419 user_config) |
| 420 else: | 420 else: |
| 421 config_names = target_dicts[target_list[0]]['configurations'].keys() | 421 config_names = target_dicts[target_list[0]]['configurations'].keys() |
| 422 for config_name in config_names: | 422 for config_name in config_names: |
| 423 GenerateOutputForConfig(target_list, target_dicts, data, params, | 423 GenerateOutputForConfig(target_list, target_dicts, data, params, |
| 424 config_name) | 424 config_name) |
| 425 | 425 |
| OLD | NEW |