Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: build/android/gradle/generate_gradle.py

Issue 2724513003: Make generate_gradle.py work with preview SDKs. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/gradle/android.jinja ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 _ReadBuildVars(output_dir): 95 def _ReadPropertiesFile(path):
96 with open(os.path.join(output_dir, 'build_vars.txt')) as f: 96 with open(path) as f:
97 return dict(l.rstrip().split('=', 1) for l in f) 97 return dict(l.rstrip().split('=', 1) for l in f if '=' in l)
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
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 variables['build_tools_version'] = ( 517 source_properties = _ReadPropertiesFile(
518 build_vars['android_sdk_build_tools_version']) 518 os.path.join(build_vars['android_sdk_build_tools'], 'source.properties'))
nyquist 2017/03/01 01:22:12 In my local checkout, os.getcwd() ends up being sr
agrieve 2017/03/01 01:24:16 Doh! Clearly wrong. I'll revert & reland.
519 variables['compile_sdk_version'] = build_vars['android_sdk_version'] 519 variables['build_tools_version'] = source_properties['Pkg.Revision']
520 variables['compile_sdk_version'] = (
521 'android-%s' % build_vars['android_sdk_version'])
520 variables['main'] = generator.Generate(entry) 522 variables['main'] = generator.Generate(entry)
521 bootclasspath = gradle.get('bootclasspath') 523 bootclasspath = gradle.get('bootclasspath')
522 if bootclasspath: 524 if bootclasspath:
523 # Must use absolute path here. 525 # Must use absolute path here.
524 variables['bootclasspath'] = _RebasePath(bootclasspath) 526 variables['bootclasspath'] = _RebasePath(bootclasspath)
525 if entry.android_test_entry: 527 if entry.android_test_entry:
526 variables['android_test'] = generator.Generate( 528 variables['android_test'] = generator.Generate(
527 entry.android_test_entry) 529 entry.android_test_entry)
528 for key, value in variables['android_test'].iteritems(): 530 for key, value in variables['android_test'].iteritems():
529 if isinstance(value, list): 531 if isinstance(value, list):
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 run_tests_helper.SetLogLevel(args.verbose_count) 655 run_tests_helper.SetLogLevel(args.verbose_count)
654 656
655 # TODO(wnwen): Fix packaging so that gradle resources work in this case. 657 # TODO(wnwen): Fix packaging so that gradle resources work in this case.
656 if args.use_gradle_process_resources: 658 if args.use_gradle_process_resources:
657 assert args.split_projects, ( 659 assert args.split_projects, (
658 'Gradle resources does not yet work without --split-projects.') 660 'Gradle resources does not yet work without --split-projects.')
659 661
660 _gradle_output_dir = os.path.abspath( 662 _gradle_output_dir = os.path.abspath(
661 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) 663 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
662 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) 664 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
663 build_vars = _ReadBuildVars(output_dir) 665 build_vars = _ReadPropertiesFile(os.path.join(output_dir, 'build_vars.txt'))
664 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars, 666 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars,
665 args.use_gradle_process_resources, jinja_processor, args.split_projects) 667 args.use_gradle_process_resources, jinja_processor, args.split_projects)
666 logging.warning('Creating project at: %s', generator.project_dir) 668 logging.warning('Creating project at: %s', generator.project_dir)
667 669
668 if args.all: 670 if args.all:
669 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). 671 # Run GN gen if necessary (faster than running "gn gen" in the no-op case).
670 _RunNinja(constants.GetOutDirectory(), ['build.ninja']) 672 _RunNinja(constants.GetOutDirectory(), ['build.ninja'])
671 # Query ninja for all __build_config targets. 673 # Query ninja for all __build_config targets.
672 targets = _QueryForAllGnTargets(output_dir) 674 targets = _QueryForAllGnTargets(output_dir)
673 else: 675 else:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 _ExtractZips(generator.project_dir, zip_tuples) 736 _ExtractZips(generator.project_dir, zip_tuples)
735 737
736 logging.warning('Project created! (%d subprojects)', len(project_entries)) 738 logging.warning('Project created! (%d subprojects)', len(project_entries))
737 logging.warning('Generated projects work best with Android Studio 2.2') 739 logging.warning('Generated projects work best with Android Studio 2.2')
738 logging.warning('For more tips: https://chromium.googlesource.com/chromium' 740 logging.warning('For more tips: https://chromium.googlesource.com/chromium'
739 '/src.git/+/master/docs/android_studio.md') 741 '/src.git/+/master/docs/android_studio.md')
740 742
741 743
742 if __name__ == '__main__': 744 if __name__ == '__main__':
743 main() 745 main()
OLDNEW
« no previous file with comments | « build/android/gradle/android.jinja ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698