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

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

Issue 2727523002: Reland of Make generate_gradle.py work with preview SDKs. (Closed)
Patch Set: make relative to output dir 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 _RebasePath(os.path.join(build_vars['android_sdk_build_tools'],
519 variables['compile_sdk_version'] = build_vars['android_sdk_version'] 519 'source.properties')))
520 variables['build_tools_version'] = source_properties['Pkg.Revision']
521 variables['compile_sdk_version'] = (
522 'android-%s' % build_vars['android_sdk_version'])
520 variables['main'] = generator.Generate(entry) 523 variables['main'] = generator.Generate(entry)
521 bootclasspath = gradle.get('bootclasspath') 524 bootclasspath = gradle.get('bootclasspath')
522 if bootclasspath: 525 if bootclasspath:
523 # Must use absolute path here. 526 # Must use absolute path here.
524 variables['bootclasspath'] = _RebasePath(bootclasspath) 527 variables['bootclasspath'] = _RebasePath(bootclasspath)
525 if entry.android_test_entry: 528 if entry.android_test_entry:
526 variables['android_test'] = generator.Generate( 529 variables['android_test'] = generator.Generate(
527 entry.android_test_entry) 530 entry.android_test_entry)
528 for key, value in variables['android_test'].iteritems(): 531 for key, value in variables['android_test'].iteritems():
529 if isinstance(value, list): 532 if isinstance(value, list):
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 run_tests_helper.SetLogLevel(args.verbose_count) 656 run_tests_helper.SetLogLevel(args.verbose_count)
654 657
655 # TODO(wnwen): Fix packaging so that gradle resources work in this case. 658 # TODO(wnwen): Fix packaging so that gradle resources work in this case.
656 if args.use_gradle_process_resources: 659 if args.use_gradle_process_resources:
657 assert args.split_projects, ( 660 assert args.split_projects, (
658 'Gradle resources does not yet work without --split-projects.') 661 'Gradle resources does not yet work without --split-projects.')
659 662
660 _gradle_output_dir = os.path.abspath( 663 _gradle_output_dir = os.path.abspath(
661 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) 664 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir))
662 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) 665 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR)
663 build_vars = _ReadBuildVars(output_dir) 666 build_vars = _ReadPropertiesFile(os.path.join(output_dir, 'build_vars.txt'))
664 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars, 667 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars,
665 args.use_gradle_process_resources, jinja_processor, args.split_projects) 668 args.use_gradle_process_resources, jinja_processor, args.split_projects)
666 logging.warning('Creating project at: %s', generator.project_dir) 669 logging.warning('Creating project at: %s', generator.project_dir)
667 670
668 if args.all: 671 if args.all:
669 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). 672 # Run GN gen if necessary (faster than running "gn gen" in the no-op case).
670 _RunNinja(constants.GetOutDirectory(), ['build.ninja']) 673 _RunNinja(constants.GetOutDirectory(), ['build.ninja'])
671 # Query ninja for all __build_config targets. 674 # Query ninja for all __build_config targets.
672 targets = _QueryForAllGnTargets(output_dir) 675 targets = _QueryForAllGnTargets(output_dir)
673 else: 676 else:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 _ExtractZips(generator.project_dir, zip_tuples) 737 _ExtractZips(generator.project_dir, zip_tuples)
735 738
736 logging.warning('Project created! (%d subprojects)', len(project_entries)) 739 logging.warning('Project created! (%d subprojects)', len(project_entries))
737 logging.warning('Generated projects work best with Android Studio 2.2') 740 logging.warning('Generated projects work best with Android Studio 2.2')
738 logging.warning('For more tips: https://chromium.googlesource.com/chromium' 741 logging.warning('For more tips: https://chromium.googlesource.com/chromium'
739 '/src.git/+/master/docs/android_studio.md') 742 '/src.git/+/master/docs/android_studio.md')
740 743
741 744
742 if __name__ == '__main__': 745 if __name__ == '__main__':
743 main() 746 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