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 17 matching lines...) Expand all Loading... | |
28 from util import build_utils | 28 from util import build_utils |
29 | 29 |
30 | 30 |
31 _DEFAULT_ANDROID_MANIFEST_PATH = os.path.join( | 31 _DEFAULT_ANDROID_MANIFEST_PATH = os.path.join( |
32 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml') | 32 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml') |
33 _FILE_DIR = os.path.dirname(__file__) | 33 _FILE_DIR = os.path.dirname(__file__) |
34 _SRCJARS_SUBDIR = 'extracted-srcjars' | 34 _SRCJARS_SUBDIR = 'extracted-srcjars' |
35 _JNI_LIBS_SUBDIR = 'symlinked-libs' | 35 _JNI_LIBS_SUBDIR = 'symlinked-libs' |
36 _ARMEABI_SUBDIR = 'armeabi' | 36 _ARMEABI_SUBDIR = 'armeabi' |
37 _RES_SUBDIR = 'extracted-res' | 37 _RES_SUBDIR = 'extracted-res' |
38 _GRADLE_BUILD_FILE = 'build.gradle' | |
39 # This needs to come first alphabetically among all modules. | |
40 _MODULE_ALL = '_all' | |
38 | 41 |
39 _DEFAULT_TARGETS = [ | 42 _DEFAULT_TARGETS = [ |
40 # TODO(agrieve): .build_config seem not quite right for this target | 43 # TODO(agrieve): .build_config seem not quite right for this target |
41 # because it has resources as deps of android_apk() rather than using an | 44 # because it has resources as deps of android_apk() rather than using an |
42 # android_library() intermediate target. | 45 # android_library() intermediate target. |
43 # '//android_webview:system_webview_apk', | 46 # '//android_webview:system_webview_apk', |
44 '//android_webview/test:android_webview_apk', | 47 '//android_webview/test:android_webview_apk', |
45 '//android_webview/test:android_webview_test_apk', | 48 '//android_webview/test:android_webview_test_apk', |
46 '//base:base_junit_tests', | 49 '//base:base_junit_tests', |
47 '//chrome/android:chrome_junit_tests', | 50 '//chrome/android:chrome_junit_tests', |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 | 241 |
239 class _ProjectContextGenerator(object): | 242 class _ProjectContextGenerator(object): |
240 """Helper class to generate gradle build files""" | 243 """Helper class to generate gradle build files""" |
241 def __init__(self, project_dir, build_vars, use_gradle_process_resources, | 244 def __init__(self, project_dir, build_vars, use_gradle_process_resources, |
242 jinja_processor, split_projects): | 245 jinja_processor, split_projects): |
243 self.project_dir = project_dir | 246 self.project_dir = project_dir |
244 self.build_vars = build_vars | 247 self.build_vars = build_vars |
245 self.use_gradle_process_resources = use_gradle_process_resources | 248 self.use_gradle_process_resources = use_gradle_process_resources |
246 self.jinja_processor = jinja_processor | 249 self.jinja_processor = jinja_processor |
247 self.split_projects = split_projects | 250 self.split_projects = split_projects |
251 self.processed_java_dirs = set() | |
252 self.processed_prebuilts = set() | |
248 | 253 |
249 def _GenJniLibs(self, root_entry): | 254 def _GenJniLibs(self, root_entry): |
250 libraries = [] | 255 libraries = [] |
251 for entry in self._GetEntries(root_entry): | 256 for entry in self._GetEntries(root_entry): |
252 libraries += entry.BuildConfig().get('native', {}).get('libraries', []) | 257 libraries += entry.BuildConfig().get('native', {}).get('libraries', []) |
253 if libraries: | 258 if libraries: |
254 return _CreateJniLibsDir(constants.GetOutDirectory(), | 259 return _CreateJniLibsDir(constants.GetOutDirectory(), |
255 self.EntryOutputDir(root_entry), libraries) | 260 self.EntryOutputDir(root_entry), libraries) |
256 return [] | 261 return [] |
257 | 262 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 for entry in self._GetEntries(root_entry): | 332 for entry in self._GetEntries(root_entry): |
328 generated_inputs.update(entry.GeneratedJavaFiles()) | 333 generated_inputs.update(entry.GeneratedJavaFiles()) |
329 generated_inputs.update(entry.PrebuiltJars()) | 334 generated_inputs.update(entry.PrebuiltJars()) |
330 return set(generated_inputs) | 335 return set(generated_inputs) |
331 | 336 |
332 def Generate(self, root_entry): | 337 def Generate(self, root_entry): |
333 # TODO(agrieve): Add an option to use interface jars and see if that speeds | 338 # TODO(agrieve): Add an option to use interface jars and see if that speeds |
334 # things up at all. | 339 # things up at all. |
335 variables = {} | 340 variables = {} |
336 java_dirs, excludes = self._GenJavaDirs(root_entry) | 341 java_dirs, excludes = self._GenJavaDirs(root_entry) |
342 java_dirs.append( | |
343 os.path.join(self.EntryOutputDir(root_entry), _SRCJARS_SUBDIR)) | |
344 self.processed_java_dirs.update(java_dirs) | |
337 java_dirs.sort() | 345 java_dirs.sort() |
338 variables['java_dirs'] = self._Relativize(root_entry, java_dirs) | 346 variables['java_dirs'] = self._Relativize(root_entry, java_dirs) |
339 variables['java_dirs'].append(_SRCJARS_SUBDIR) | |
340 variables['java_excludes'] = excludes | 347 variables['java_excludes'] = excludes |
341 variables['jni_libs'] = self._Relativize( | 348 variables['jni_libs'] = self._Relativize( |
342 root_entry, set(self._GenJniLibs(root_entry))) | 349 root_entry, set(self._GenJniLibs(root_entry))) |
343 variables['prebuilts'] = [ | 350 prebuilts = set( |
344 p for e in self._GetEntries(root_entry) for p in e.PrebuiltJars()] | 351 p for e in self._GetEntries(root_entry) for p in e.PrebuiltJars()) |
345 variables['res_dirs'] = [ | 352 self.processed_prebuilts.update(prebuilts) |
346 p for e in self._GetEntries(root_entry) for p in e.ResDirs()] | 353 variables['prebuilts'] = self._Relativize(root_entry, prebuilts) |
347 for entry in self._GetEntries(root_entry): | 354 res_dirs = set( |
348 variables['prebuilts'] += entry.PrebuiltJars() | 355 p for e in self._GetEntries(root_entry) for p in e.ResDirs()) |
349 variables['res_dirs'] += entry.ResDirs() | 356 res_dirs.add( |
350 variables['prebuilts'] = self._Relativize( | 357 os.path.join(self.EntryOutputDir(root_entry), _RES_SUBDIR)) |
351 root_entry, set(variables['prebuilts'])) | 358 variables['res_dirs'] = self._Relativize(root_entry, res_dirs) |
352 variables['res_dirs'] = self._Relativize( | |
353 root_entry, set(variables['res_dirs'])) | |
354 variables['res_dirs'].append(_RES_SUBDIR) | |
355 android_manifest = root_entry.Gradle().get('android_manifest') | 359 android_manifest = root_entry.Gradle().get('android_manifest') |
356 if not android_manifest: | 360 if not android_manifest: |
357 android_manifest = self._GenCustomManifest(root_entry) | 361 android_manifest = self._GenCustomManifest(root_entry) |
358 variables['android_manifest'] = self._Relativize( | 362 variables['android_manifest'] = self._Relativize( |
359 root_entry, android_manifest) | 363 root_entry, android_manifest) |
360 if self.split_projects: | 364 if self.split_projects: |
361 deps = [_ProjectEntry.FromBuildConfigPath(p) | 365 deps = [_ProjectEntry.FromBuildConfigPath(p) |
362 for p in root_entry.Gradle()['dependent_android_projects']] | 366 for p in root_entry.Gradle()['dependent_android_projects']] |
363 variables['android_project_deps'] = [d.ProjectName() for d in deps] | 367 variables['android_project_deps'] = [d.ProjectName() for d in deps] |
364 deps = [_ProjectEntry.FromBuildConfigPath(p) | 368 deps = [_ProjectEntry.FromBuildConfigPath(p) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 | 479 |
476 | 480 |
477 def _GenerateLocalProperties(sdk_dir): | 481 def _GenerateLocalProperties(sdk_dir): |
478 """Returns the data for project.properties as a string.""" | 482 """Returns the data for project.properties as a string.""" |
479 return '\n'.join([ | 483 return '\n'.join([ |
480 '# Generated by //build/android/gradle/generate_gradle.py', | 484 '# Generated by //build/android/gradle/generate_gradle.py', |
481 'sdk.dir=%s' % sdk_dir, | 485 'sdk.dir=%s' % sdk_dir, |
482 '']) | 486 '']) |
483 | 487 |
484 | 488 |
485 def _GenerateGradleFile(entry, generator, build_vars, jinja_processor): | 489 def _GenerateBaseVars(generator, build_vars, source_properties): |
490 variables = { | |
491 'sourceSetName': 'main', | |
492 'depCompileName': 'compile', | |
493 } | |
494 variables['build_tools_version'] = source_properties['Pkg.Revision'] | |
495 variables['compile_sdk_version'] = ( | |
496 'android-%s' % build_vars['android_sdk_version']) | |
497 variables['use_gradle_process_resources'] = ( | |
498 generator.use_gradle_process_resources) | |
499 return variables | |
500 | |
501 | |
502 def _GenerateGradleFile(entry, generator, build_vars, source_properties, | |
503 jinja_processor): | |
486 """Returns the data for a project's build.gradle.""" | 504 """Returns the data for a project's build.gradle.""" |
487 deps_info = entry.DepsInfo() | 505 deps_info = entry.DepsInfo() |
488 gradle = entry.Gradle() | 506 gradle = entry.Gradle() |
489 | 507 |
490 variables = { | 508 variables = _GenerateBaseVars(generator, build_vars, source_properties) |
491 'sourceSetName': 'main', | |
492 'depCompileName': 'compile', | |
493 } | |
494 if deps_info['type'] == 'android_apk': | 509 if deps_info['type'] == 'android_apk': |
495 target_type = 'android_apk' | 510 target_type = 'android_apk' |
496 elif deps_info['type'] == 'java_library': | 511 elif deps_info['type'] == 'java_library': |
497 if deps_info['is_prebuilt'] or deps_info['gradle_treat_as_prebuilt']: | 512 if deps_info['is_prebuilt'] or deps_info['gradle_treat_as_prebuilt']: |
498 return None | 513 return None |
499 elif deps_info['requires_android']: | 514 elif deps_info['requires_android']: |
500 target_type = 'android_library' | 515 target_type = 'android_library' |
501 else: | 516 else: |
502 target_type = 'java_library' | 517 target_type = 'java_library' |
503 elif deps_info['type'] == 'java_binary': | 518 elif deps_info['type'] == 'java_binary': |
504 if gradle['main_class'] == 'org.chromium.testing.local.JunitTestMain': | 519 if gradle['main_class'] == 'org.chromium.testing.local.JunitTestMain': |
505 target_type = 'android_junit' | 520 target_type = 'android_junit' |
506 variables['sourceSetName'] = 'test' | 521 variables['sourceSetName'] = 'test' |
507 variables['depCompileName'] = 'testCompile' | 522 variables['depCompileName'] = 'testCompile' |
508 else: | 523 else: |
509 target_type = 'java_binary' | 524 target_type = 'java_binary' |
510 variables['main_class'] = gradle['main_class'] | 525 variables['main_class'] = gradle['main_class'] |
511 else: | 526 else: |
512 return None | 527 return None |
513 | 528 |
514 variables['target_name'] = os.path.splitext(deps_info['name'])[0] | 529 variables['target_name'] = os.path.splitext(deps_info['name'])[0] |
515 variables['template_type'] = target_type | 530 variables['template_type'] = target_type |
516 variables['use_gradle_process_resources'] = ( | |
517 generator.use_gradle_process_resources) | |
518 source_properties = _ReadPropertiesFile( | |
519 _RebasePath(os.path.join(build_vars['android_sdk_build_tools'], | |
520 'source.properties'))) | |
521 variables['build_tools_version'] = source_properties['Pkg.Revision'] | |
522 variables['compile_sdk_version'] = ( | |
523 'android-%s' % build_vars['android_sdk_version']) | |
524 variables['main'] = generator.Generate(entry) | 531 variables['main'] = generator.Generate(entry) |
525 bootclasspath = gradle.get('bootclasspath') | 532 bootclasspath = gradle.get('bootclasspath') |
526 if bootclasspath: | 533 if bootclasspath: |
527 # Must use absolute path here. | 534 # Must use absolute path here. |
528 variables['bootclasspath'] = _RebasePath(bootclasspath) | 535 variables['bootclasspath'] = _RebasePath(bootclasspath) |
529 if entry.android_test_entry: | 536 if entry.android_test_entry: |
530 variables['android_test'] = generator.Generate( | 537 variables['android_test'] = generator.Generate( |
531 entry.android_test_entry) | 538 entry.android_test_entry) |
532 for key, value in variables['android_test'].iteritems(): | 539 for key, value in variables['android_test'].iteritems(): |
533 if isinstance(value, list): | 540 if isinstance(value, list): |
534 variables['android_test'][key] = list( | 541 variables['android_test'][key] = sorted( |
535 set(value) - set(variables['main'][key])) | 542 set(value) - set(variables['main'][key])) |
536 | 543 |
537 return jinja_processor.Render( | 544 return jinja_processor.Render( |
538 _TemplatePath(target_type.split('_')[0]), variables) | 545 _TemplatePath(target_type.split('_')[0]), variables) |
539 | 546 |
540 | 547 |
548 def _GenerateModuleAll(gradle_output_dir, generator, build_vars, | |
549 source_properties, jinja_processor): | |
550 """Returns the data for a pseudo build.gradle of all dirs. | |
551 | |
552 See //docs/android_studio.md for more details.""" | |
553 variables = _GenerateBaseVars(generator, build_vars, source_properties) | |
554 target_type = 'android_apk' | |
555 variables['target_name'] = _MODULE_ALL | |
556 variables['template_type'] = target_type | |
557 java_dirs = sorted(generator.processed_java_dirs) | |
558 prebuilts = sorted(generator.processed_prebuilts) | |
559 def Relativize(paths): | |
560 return _RebasePath(paths, os.path.join(gradle_output_dir, _MODULE_ALL)) | |
561 variables['main'] = { | |
562 'android_manifest': Relativize(_DEFAULT_ANDROID_MANIFEST_PATH), | |
563 'java_dirs': Relativize(java_dirs), | |
564 'prebuilts': Relativize(prebuilts), | |
565 'java_excludes': ['**/*.java'], | |
566 } | |
567 data = jinja_processor.Render( | |
568 _TemplatePath(target_type.split('_')[0]), variables) | |
569 _WriteFile( | |
570 os.path.join(gradle_output_dir, _MODULE_ALL, _GRADLE_BUILD_FILE), data) | |
571 | |
572 | |
541 def _GenerateRootGradle(jinja_processor): | 573 def _GenerateRootGradle(jinja_processor): |
542 """Returns the data for the root project's build.gradle.""" | 574 """Returns the data for the root project's build.gradle.""" |
543 return jinja_processor.Render(_TemplatePath('root')) | 575 return jinja_processor.Render(_TemplatePath('root')) |
544 | 576 |
545 | 577 |
546 def _GenerateSettingsGradle(project_entries): | 578 def _GenerateSettingsGradle(project_entries): |
547 """Returns the data for settings.gradle.""" | 579 """Returns the data for settings.gradle.""" |
548 project_name = os.path.basename(os.path.dirname(host_paths.DIR_SOURCE_ROOT)) | 580 project_name = os.path.basename(os.path.dirname(host_paths.DIR_SOURCE_ROOT)) |
549 lines = [] | 581 lines = [] |
550 lines.append('// Generated by //build/android/gradle/generate_gradle.py') | 582 lines.append('// Generated by //build/android/gradle/generate_gradle.py') |
551 lines.append('rootProject.name = "%s"' % project_name) | 583 lines.append('rootProject.name = "%s"' % project_name) |
552 lines.append('rootProject.projectDir = settingsDir') | 584 lines.append('rootProject.projectDir = settingsDir') |
553 lines.append('') | 585 lines.append('') |
554 | 586 |
587 lines.append('include ":{0}"'.format(_MODULE_ALL)) | |
588 lines.append( | |
589 'project(":{0}").projectDir = new File(settingsDir, "{0}")'.format( | |
590 _MODULE_ALL)) | |
555 for entry in project_entries: | 591 for entry in project_entries: |
556 # Example target: android_webview:android_webview_java__build_config | 592 # Example target: android_webview:android_webview_java__build_config |
557 lines.append('include ":%s"' % entry.ProjectName()) | 593 lines.append('include ":%s"' % entry.ProjectName()) |
558 lines.append('project(":%s").projectDir = new File(settingsDir, "%s")' % | 594 lines.append('project(":%s").projectDir = new File(settingsDir, "%s")' % |
559 (entry.ProjectName(), entry.GradleSubdir())) | 595 (entry.ProjectName(), entry.GradleSubdir())) |
560 return '\n'.join(lines) | 596 return '\n'.join(lines) |
561 | 597 |
562 | 598 |
563 def _ExtractFile(zip_path, extracted_path): | 599 def _ExtractFile(zip_path, extracted_path): |
564 logging.info('Extracting %s to %s', zip_path, extracted_path) | 600 logging.info('Extracting %s to %s', zip_path, extracted_path) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 'combining all the dependencies of each target') | 691 'combining all the dependencies of each target') |
656 args = parser.parse_args() | 692 args = parser.parse_args() |
657 if args.output_directory: | 693 if args.output_directory: |
658 constants.SetOutputDirectory(args.output_directory) | 694 constants.SetOutputDirectory(args.output_directory) |
659 constants.CheckOutputDirectory() | 695 constants.CheckOutputDirectory() |
660 output_dir = constants.GetOutDirectory() | 696 output_dir = constants.GetOutDirectory() |
661 devil_chromium.Initialize(output_directory=output_dir) | 697 devil_chromium.Initialize(output_directory=output_dir) |
662 run_tests_helper.SetLogLevel(args.verbose_count) | 698 run_tests_helper.SetLogLevel(args.verbose_count) |
663 | 699 |
664 # TODO(wnwen): Fix packaging so that gradle resources work in this case. | 700 # TODO(wnwen): Fix packaging so that gradle resources work in this case. |
665 if args.use_gradle_process_resources: | 701 if args.split_projects: |
666 assert args.split_projects, ( | 702 assert not args.use_gradle_process_resources, ( |
sakal-chromium
2017/05/04 09:11:00
Why did the meaning of this check change? Now it a
Peter Wen
2017/05/04 10:19:58
Yes, you are correct, it's a bug. I'll fix it in a
| |
667 'Gradle resources does not yet work without --split-projects.') | 703 'Gradle resources does not work without --split-projects.') |
668 | 704 |
669 _gradle_output_dir = os.path.abspath( | 705 _gradle_output_dir = os.path.abspath( |
670 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) | 706 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) |
671 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) | 707 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) |
672 build_vars = _ReadPropertiesFile(os.path.join(output_dir, 'build_vars.txt')) | 708 build_vars = _ReadPropertiesFile(os.path.join(output_dir, 'build_vars.txt')) |
709 source_properties = _ReadPropertiesFile( | |
710 _RebasePath(os.path.join(build_vars['android_sdk_build_tools'], | |
711 'source.properties'))) | |
673 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars, | 712 generator = _ProjectContextGenerator(_gradle_output_dir, build_vars, |
674 args.use_gradle_process_resources, jinja_processor, args.split_projects) | 713 args.use_gradle_process_resources, jinja_processor, args.split_projects) |
675 logging.warning('Creating project at: %s', generator.project_dir) | 714 logging.warning('Creating project at: %s', generator.project_dir) |
676 | 715 |
677 if args.all: | 716 if args.all: |
678 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). | 717 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). |
679 _RunNinja(constants.GetOutDirectory(), ['build.ninja']) | 718 _RunNinja(constants.GetOutDirectory(), ['build.ninja']) |
680 # Query ninja for all __build_config targets. | 719 # Query ninja for all __build_config targets. |
681 targets = _QueryForAllGnTargets(output_dir) | 720 targets = _QueryForAllGnTargets(output_dir) |
682 else: | 721 else: |
683 targets = args.targets or _DEFAULT_TARGETS | 722 targets = args.targets or _DEFAULT_TARGETS |
684 if args.extra_targets: | 723 if args.extra_targets: |
685 targets.extend(args.extra_targets) | 724 targets.extend(args.extra_targets) |
686 targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] | 725 targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] |
687 # TODO(wnwen): Utilize Gradle's test constructs for our junit tests? | 726 # TODO(wnwen): Utilize Gradle's test constructs for our junit tests? |
688 targets = [re.sub(r'_junit_tests$', '_junit_tests__java_binary', t) | 727 targets = [re.sub(r'_junit_tests$', '_junit_tests__java_binary', t) |
689 for t in targets] | 728 for t in targets] |
690 | 729 |
691 main_entries = [_ProjectEntry.FromGnTarget(t) for t in targets] | 730 main_entries = [_ProjectEntry.FromGnTarget(t) for t in targets] |
692 | 731 |
693 logging.warning('Building .build_config files...') | 732 logging.warning('Building .build_config files...') |
694 _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) | 733 _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) |
695 | 734 |
696 # There are many unused libraries, so restrict to those that are actually used | 735 # There are many unused libraries, so restrict to those that are actually used |
697 # when using --all. | 736 # when using --all. |
698 if args.all: | 737 if args.all: |
699 main_entries = [e for e in main_entries if e.GetType() == 'android_apk'] | 738 main_entries = [e for e in main_entries if ( |
739 e.GetType() == 'android_apk' or | |
740 e.GnTarget().endswith('_test_apk__apk') or | |
741 e.GnTarget().endswith('_junit_tests__java_binary'))] | |
700 | 742 |
701 if args.split_projects: | 743 if args.split_projects: |
702 main_entries = _FindAllProjectEntries(main_entries) | 744 main_entries = _FindAllProjectEntries(main_entries) |
703 logging.info('Found %d dependent build_config targets.', len(main_entries)) | 745 logging.info('Found %d dependent build_config targets.', len(main_entries)) |
704 entries = _CombineTestEntries(main_entries) | 746 entries = _CombineTestEntries(main_entries) |
705 logging.info('Creating %d projects for targets.', len(entries)) | 747 logging.info('Creating %d projects for targets.', len(entries)) |
706 | 748 |
707 logging.warning('Writing .gradle files...') | 749 logging.warning('Writing .gradle files...') |
708 project_entries = [] | 750 project_entries = [] |
709 zip_tuples = [] | 751 zip_tuples = [] |
710 generated_inputs = [] | 752 generated_inputs = [] |
711 for entry in entries: | 753 for entry in entries: |
712 if entry.GetType() not in ('android_apk', 'java_library', 'java_binary'): | 754 if entry.GetType() not in ('android_apk', 'java_library', 'java_binary'): |
713 continue | 755 continue |
714 | 756 |
715 data = _GenerateGradleFile(entry, generator, build_vars, jinja_processor) | 757 data = _GenerateGradleFile(entry, generator, build_vars, source_properties, |
758 jinja_processor) | |
716 if data: | 759 if data: |
717 project_entries.append(entry) | 760 project_entries.append(entry) |
718 # Build all paths references by .gradle that exist within output_dir. | 761 # Build all paths references by .gradle that exist within output_dir. |
719 generated_inputs.extend(generator.GeneratedInputs(entry)) | 762 generated_inputs.extend(generator.GeneratedInputs(entry)) |
720 zip_tuples.extend( | 763 zip_tuples.extend( |
721 (s, os.path.join(generator.EntryOutputDir(entry), _SRCJARS_SUBDIR)) | 764 (s, os.path.join(generator.EntryOutputDir(entry), _SRCJARS_SUBDIR)) |
722 for s in generator.AllSrcjars(entry)) | 765 for s in generator.AllSrcjars(entry)) |
723 zip_tuples.extend( | 766 zip_tuples.extend( |
724 (s, os.path.join(generator.EntryOutputDir(entry), _RES_SUBDIR)) | 767 (s, os.path.join(generator.EntryOutputDir(entry), _RES_SUBDIR)) |
725 for s in generator.AllResZips(entry)) | 768 for s in generator.AllResZips(entry)) |
726 _WriteFile( | 769 _WriteFile( |
727 os.path.join(generator.EntryOutputDir(entry), 'build.gradle'), data) | 770 os.path.join(generator.EntryOutputDir(entry), _GRADLE_BUILD_FILE), |
771 data) | |
728 | 772 |
729 _WriteFile(os.path.join(generator.project_dir, 'build.gradle'), | 773 _GenerateModuleAll(_gradle_output_dir, generator, build_vars, |
774 source_properties, jinja_processor) | |
775 | |
776 _WriteFile(os.path.join(generator.project_dir, _GRADLE_BUILD_FILE), | |
730 _GenerateRootGradle(jinja_processor)) | 777 _GenerateRootGradle(jinja_processor)) |
731 | 778 |
732 _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'), | 779 _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'), |
733 _GenerateSettingsGradle(project_entries)) | 780 _GenerateSettingsGradle(project_entries)) |
734 | 781 |
735 sdk_path = _RebasePath(build_vars['android_sdk_root']) | 782 sdk_path = _RebasePath(build_vars['android_sdk_root']) |
736 _WriteFile(os.path.join(generator.project_dir, 'local.properties'), | 783 _WriteFile(os.path.join(generator.project_dir, 'local.properties'), |
737 _GenerateLocalProperties(sdk_path)) | 784 _GenerateLocalProperties(sdk_path)) |
738 | 785 |
739 if generated_inputs: | 786 if generated_inputs: |
740 logging.warning('Building generated source files...') | 787 logging.warning('Building generated source files...') |
741 targets = _RebasePath(generated_inputs, output_dir) | 788 targets = _RebasePath(generated_inputs, output_dir) |
742 _RunNinja(output_dir, targets) | 789 _RunNinja(output_dir, targets) |
743 | 790 |
744 if zip_tuples: | 791 if zip_tuples: |
745 _ExtractZips(generator.project_dir, zip_tuples) | 792 _ExtractZips(generator.project_dir, zip_tuples) |
746 | 793 |
747 logging.warning('Project created! (%d subprojects)', len(project_entries)) | 794 logging.warning('Project created! (%d subprojects)', len(project_entries)) |
748 logging.warning('Generated projects work with Android Studio 2.3') | 795 logging.warning('Generated projects work with Android Studio 2.3') |
749 logging.warning('For more tips: https://chromium.googlesource.com/chromium' | 796 logging.warning('For more tips: https://chromium.googlesource.com/chromium' |
750 '/src.git/+/master/docs/android_studio.md') | 797 '/src.git/+/master/docs/android_studio.md') |
751 | 798 |
752 | 799 |
753 if __name__ == '__main__': | 800 if __name__ == '__main__': |
754 main() | 801 main() |
OLD | NEW |