| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Generates an Android Studio project from a GN target.""" | 6 """Generates an Android Studio project from a GN target.""" |
| 7 | 7 |
| 8 import argparse | 8 import argparse |
| 9 import codecs | 9 import codecs |
| 10 import glob | 10 import glob |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 def _WriteFile(path, data): | 85 def _WriteFile(path, data): |
| 86 """Writes |data| to |path|, constucting parent directories if necessary.""" | 86 """Writes |data| to |path|, constucting parent directories if necessary.""" |
| 87 logging.info('Writing %s', path) | 87 logging.info('Writing %s', path) |
| 88 dirname = os.path.dirname(path) | 88 dirname = os.path.dirname(path) |
| 89 if not os.path.exists(dirname): | 89 if not os.path.exists(dirname): |
| 90 os.makedirs(dirname) | 90 os.makedirs(dirname) |
| 91 with codecs.open(path, 'w', 'utf-8') as output_file: | 91 with codecs.open(path, 'w', 'utf-8') as output_file: |
| 92 output_file.write(data) | 92 output_file.write(data) |
| 93 | 93 |
| 94 | 94 |
| 95 def _ReadPropertiesFile(path): | 95 def _ReadBuildVars(output_dir): |
| 96 with open(path) as f: | 96 with open(os.path.join(output_dir, 'build_vars.txt')) as f: |
| 97 return dict(l.rstrip().split('=', 1) for l in f if '=' in l) | 97 return dict(l.rstrip().split('=', 1) for l in f) |
| 98 | 98 |
| 99 | 99 |
| 100 def _RunNinja(output_dir, args): | 100 def _RunNinja(output_dir, args): |
| 101 cmd = ['ninja', '-C', output_dir, '-j1000'] | 101 cmd = ['ninja', '-C', output_dir, '-j1000'] |
| 102 cmd.extend(args) | 102 cmd.extend(args) |
| 103 logging.info('Running: %r', cmd) | 103 logging.info('Running: %r', cmd) |
| 104 subprocess.check_call(cmd) | 104 subprocess.check_call(cmd) |
| 105 | 105 |
| 106 | 106 |
| 107 def _QueryForAllGnTargets(output_dir): | 107 def _QueryForAllGnTargets(output_dir): |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 else: | 507 else: |
| 508 target_type = 'java_binary' | 508 target_type = 'java_binary' |
| 509 variables['main_class'] = gradle['main_class'] | 509 variables['main_class'] = gradle['main_class'] |
| 510 else: | 510 else: |
| 511 return None | 511 return None |
| 512 | 512 |
| 513 variables['target_name'] = os.path.splitext(deps_info['name'])[0] | 513 variables['target_name'] = os.path.splitext(deps_info['name'])[0] |
| 514 variables['template_type'] = target_type | 514 variables['template_type'] = target_type |
| 515 variables['use_gradle_process_resources'] = ( | 515 variables['use_gradle_process_resources'] = ( |
| 516 generator.use_gradle_process_resources) | 516 generator.use_gradle_process_resources) |
| 517 source_properties = _ReadPropertiesFile( | 517 variables['build_tools_version'] = ( |
| 518 os.path.join(build_vars['android_sdk_build_tools'], 'source.properties')) | 518 build_vars['android_sdk_build_tools_version']) |
| 519 variables['build_tools_version'] = source_properties['Pkg.Revision'] | 519 variables['compile_sdk_version'] = build_vars['android_sdk_version'] |
| 520 variables['compile_sdk_version'] = ( | |
| 521 'android-%s' % build_vars['android_sdk_version']) | |
| 522 variables['main'] = generator.Generate(entry) | 520 variables['main'] = generator.Generate(entry) |
| 523 bootclasspath = gradle.get('bootclasspath') | 521 bootclasspath = gradle.get('bootclasspath') |
| 524 if bootclasspath: | 522 if bootclasspath: |
| 525 # Must use absolute path here. | 523 # Must use absolute path here. |
| 526 variables['bootclasspath'] = _RebasePath(bootclasspath) | 524 variables['bootclasspath'] = _RebasePath(bootclasspath) |
| 527 if entry.android_test_entry: | 525 if entry.android_test_entry: |
| 528 variables['android_test'] = generator.Generate( | 526 variables['android_test'] = generator.Generate( |
| 529 entry.android_test_entry) | 527 entry.android_test_entry) |
| 530 for key, value in variables['android_test'].iteritems(): | 528 for key, value in variables['android_test'].iteritems(): |
| 531 if isinstance(value, list): | 529 if isinstance(value, list): |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 run_tests_helper.SetLogLevel(args.verbose_count) | 653 run_tests_helper.SetLogLevel(args.verbose_count) |
| 656 | 654 |
| 657 # TODO(wnwen): Fix packaging so that gradle resources work in this case. | 655 # TODO(wnwen): Fix packaging so that gradle resources work in this case. |
| 658 if args.use_gradle_process_resources: | 656 if args.use_gradle_process_resources: |
| 659 assert args.split_projects, ( | 657 assert args.split_projects, ( |
| 660 'Gradle resources does not yet work without --split-projects.') | 658 'Gradle resources does not yet work without --split-projects.') |
| 661 | 659 |
| 662 _gradle_output_dir = os.path.abspath( | 660 _gradle_output_dir = os.path.abspath( |
| 663 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) | 661 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) |
| 664 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) | 662 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) |
| 665 build_vars = _ReadPropertiesFile(os.path.join(output_dir, 'build_vars.txt')) | 663 build_vars = _ReadBuildVars(output_dir) |
| 666 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars, | 664 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars, |
| 667 args.use_gradle_process_resources, jinja_processor, args.split_projects) | 665 args.use_gradle_process_resources, jinja_processor, args.split_projects) |
| 668 logging.warning('Creating project at: %s', generator.project_dir) | 666 logging.warning('Creating project at: %s', generator.project_dir) |
| 669 | 667 |
| 670 if args.all: | 668 if args.all: |
| 671 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). | 669 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). |
| 672 _RunNinja(constants.GetOutDirectory(), ['build.ninja']) | 670 _RunNinja(constants.GetOutDirectory(), ['build.ninja']) |
| 673 # Query ninja for all __build_config targets. | 671 # Query ninja for all __build_config targets. |
| 674 targets = _QueryForAllGnTargets(output_dir) | 672 targets = _QueryForAllGnTargets(output_dir) |
| 675 else: | 673 else: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 _ExtractZips(generator.project_dir, zip_tuples) | 734 _ExtractZips(generator.project_dir, zip_tuples) |
| 737 | 735 |
| 738 logging.warning('Project created! (%d subprojects)', len(project_entries)) | 736 logging.warning('Project created! (%d subprojects)', len(project_entries)) |
| 739 logging.warning('Generated projects work best with Android Studio 2.2') | 737 logging.warning('Generated projects work best with Android Studio 2.2') |
| 740 logging.warning('For more tips: https://chromium.googlesource.com/chromium' | 738 logging.warning('For more tips: https://chromium.googlesource.com/chromium' |
| 741 '/src.git/+/master/docs/android_studio.md') | 739 '/src.git/+/master/docs/android_studio.md') |
| 742 | 740 |
| 743 | 741 |
| 744 if __name__ == '__main__': | 742 if __name__ == '__main__': |
| 745 main() | 743 main() |
| OLD | NEW |