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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 """Helper class to generate gradle build files""" | 246 """Helper class to generate gradle build files""" |
247 def __init__(self, project_dir, build_vars, use_gradle_process_resources, | 247 def __init__(self, project_dir, build_vars, use_gradle_process_resources, |
248 jinja_processor, split_projects): | 248 jinja_processor, split_projects): |
249 self.project_dir = project_dir | 249 self.project_dir = project_dir |
250 self.build_vars = build_vars | 250 self.build_vars = build_vars |
251 self.use_gradle_process_resources = use_gradle_process_resources | 251 self.use_gradle_process_resources = use_gradle_process_resources |
252 self.jinja_processor = jinja_processor | 252 self.jinja_processor = jinja_processor |
253 self.split_projects = split_projects | 253 self.split_projects = split_projects |
254 self.processed_java_dirs = set() | 254 self.processed_java_dirs = set() |
255 self.processed_prebuilts = set() | 255 self.processed_prebuilts = set() |
| 256 self.processed_res_dirs = set() |
256 | 257 |
257 def _GenJniLibs(self, root_entry): | 258 def _GenJniLibs(self, root_entry): |
258 libraries = [] | 259 libraries = [] |
259 for entry in self._GetEntries(root_entry): | 260 for entry in self._GetEntries(root_entry): |
260 libraries += entry.BuildConfig().get('native', {}).get('libraries', []) | 261 libraries += entry.BuildConfig().get('native', {}).get('libraries', []) |
261 if libraries: | 262 if libraries: |
262 return _CreateJniLibsDir(constants.GetOutDirectory(), | 263 return _CreateJniLibsDir(constants.GetOutDirectory(), |
263 self.EntryOutputDir(root_entry), libraries) | 264 self.EntryOutputDir(root_entry), libraries) |
264 return [] | 265 return [] |
265 | 266 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 variables['java_dirs'] = self._Relativize(root_entry, java_dirs) | 350 variables['java_dirs'] = self._Relativize(root_entry, java_dirs) |
350 variables['java_excludes'] = excludes | 351 variables['java_excludes'] = excludes |
351 variables['jni_libs'] = self._Relativize( | 352 variables['jni_libs'] = self._Relativize( |
352 root_entry, set(self._GenJniLibs(root_entry))) | 353 root_entry, set(self._GenJniLibs(root_entry))) |
353 prebuilts = set( | 354 prebuilts = set( |
354 p for e in self._GetEntries(root_entry) for p in e.PrebuiltJars()) | 355 p for e in self._GetEntries(root_entry) for p in e.PrebuiltJars()) |
355 self.processed_prebuilts.update(prebuilts) | 356 self.processed_prebuilts.update(prebuilts) |
356 variables['prebuilts'] = self._Relativize(root_entry, prebuilts) | 357 variables['prebuilts'] = self._Relativize(root_entry, prebuilts) |
357 res_dirs = set( | 358 res_dirs = set( |
358 p for e in self._GetEntries(root_entry) for p in e.ResDirs()) | 359 p for e in self._GetEntries(root_entry) for p in e.ResDirs()) |
| 360 # Do not add generated resources for the all module since it creates many |
| 361 # duplicates, and currently resources are only used for editing. |
| 362 self.processed_res_dirs.update(res_dirs) |
359 res_dirs.add( | 363 res_dirs.add( |
360 os.path.join(self.EntryOutputDir(root_entry), _RES_SUBDIR)) | 364 os.path.join(self.EntryOutputDir(root_entry), _RES_SUBDIR)) |
361 variables['res_dirs'] = self._Relativize(root_entry, res_dirs) | 365 variables['res_dirs'] = self._Relativize(root_entry, res_dirs) |
362 android_manifest = root_entry.Gradle().get('android_manifest') | 366 android_manifest = root_entry.Gradle().get('android_manifest') |
363 if not android_manifest: | 367 if not android_manifest: |
364 android_manifest = self._GenCustomManifest(root_entry) | 368 android_manifest = self._GenCustomManifest(root_entry) |
365 variables['android_manifest'] = self._Relativize( | 369 variables['android_manifest'] = self._Relativize( |
366 root_entry, android_manifest) | 370 root_entry, android_manifest) |
367 if self.split_projects: | 371 if self.split_projects: |
368 deps = [_ProjectEntry.FromBuildConfigPath(p) | 372 deps = [_ProjectEntry.FromBuildConfigPath(p) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 source_properties, jinja_processor): | 563 source_properties, jinja_processor): |
560 """Returns the data for a pseudo build.gradle of all dirs. | 564 """Returns the data for a pseudo build.gradle of all dirs. |
561 | 565 |
562 See //docs/android_studio.md for more details.""" | 566 See //docs/android_studio.md for more details.""" |
563 variables = _GenerateBaseVars(generator, build_vars, source_properties) | 567 variables = _GenerateBaseVars(generator, build_vars, source_properties) |
564 target_type = 'android_apk' | 568 target_type = 'android_apk' |
565 variables['target_name'] = _MODULE_ALL | 569 variables['target_name'] = _MODULE_ALL |
566 variables['template_type'] = target_type | 570 variables['template_type'] = target_type |
567 java_dirs = sorted(generator.processed_java_dirs) | 571 java_dirs = sorted(generator.processed_java_dirs) |
568 prebuilts = sorted(generator.processed_prebuilts) | 572 prebuilts = sorted(generator.processed_prebuilts) |
| 573 res_dirs = sorted(generator.processed_res_dirs) |
569 def Relativize(paths): | 574 def Relativize(paths): |
570 return _RebasePath(paths, os.path.join(gradle_output_dir, _MODULE_ALL)) | 575 return _RebasePath(paths, os.path.join(gradle_output_dir, _MODULE_ALL)) |
571 main_java_dirs = [d for d in java_dirs if not _IsTestDir(d)] | 576 main_java_dirs = [d for d in java_dirs if not _IsTestDir(d)] |
572 test_java_dirs = [d for d in java_dirs if _IsTestDir(d)] | 577 test_java_dirs = [d for d in java_dirs if _IsTestDir(d)] |
573 variables['main'] = { | 578 variables['main'] = { |
574 'android_manifest': Relativize(_DEFAULT_ANDROID_MANIFEST_PATH), | 579 'android_manifest': Relativize(_DEFAULT_ANDROID_MANIFEST_PATH), |
575 'java_dirs': Relativize(main_java_dirs), | 580 'java_dirs': Relativize(main_java_dirs), |
576 'prebuilts': Relativize(prebuilts), | 581 'prebuilts': Relativize(prebuilts), |
577 'java_excludes': ['**/*.java'], | 582 'java_excludes': ['**/*.java'], |
| 583 'res_dirs': Relativize(res_dirs), |
578 } | 584 } |
579 variables['android_test'] = { | 585 variables['android_test'] = { |
580 'java_dirs': Relativize(test_java_dirs), | 586 'java_dirs': Relativize(test_java_dirs), |
581 'java_excludes': ['**/*.java'], | 587 'java_excludes': ['**/*.java'], |
582 } | 588 } |
583 data = jinja_processor.Render( | 589 data = jinja_processor.Render( |
584 _TemplatePath(target_type.split('_')[0]), variables) | 590 _TemplatePath(target_type.split('_')[0]), variables) |
585 _WriteFile( | 591 _WriteFile( |
586 os.path.join(gradle_output_dir, _MODULE_ALL, _GRADLE_BUILD_FILE), data) | 592 os.path.join(gradle_output_dir, _MODULE_ALL, _GRADLE_BUILD_FILE), data) |
587 | 593 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 _ExtractZips(generator.project_dir, zip_tuples) | 818 _ExtractZips(generator.project_dir, zip_tuples) |
813 | 819 |
814 logging.warning('Project created!') | 820 logging.warning('Project created!') |
815 logging.warning('Generated projects work with Android Studio 2.3') | 821 logging.warning('Generated projects work with Android Studio 2.3') |
816 logging.warning('For more tips: https://chromium.googlesource.com/chromium' | 822 logging.warning('For more tips: https://chromium.googlesource.com/chromium' |
817 '/src.git/+/master/docs/android_studio.md') | 823 '/src.git/+/master/docs/android_studio.md') |
818 | 824 |
819 | 825 |
820 if __name__ == '__main__': | 826 if __name__ == '__main__': |
821 main() | 827 main() |
OLD | NEW |