| 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 logging | 10 import logging |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 deps_info = build_config['deps_info'] | 240 deps_info = build_config['deps_info'] |
| 241 gradle = build_config['gradle'] | 241 gradle = build_config['gradle'] |
| 242 | 242 |
| 243 if deps_info['type'] == 'android_apk': | 243 if deps_info['type'] == 'android_apk': |
| 244 target_type = 'android_apk' | 244 target_type = 'android_apk' |
| 245 elif deps_info['type'] == 'java_library' and not deps_info['is_prebuilt']: | 245 elif deps_info['type'] == 'java_library' and not deps_info['is_prebuilt']: |
| 246 if deps_info['requires_android']: | 246 if deps_info['requires_android']: |
| 247 target_type = 'android_library' | 247 target_type = 'android_library' |
| 248 else: | 248 else: |
| 249 target_type = 'java_library' | 249 target_type = 'java_library' |
| 250 elif deps_info['type'] == 'java_binary': |
| 251 target_type = 'android_library' |
| 250 else: | 252 else: |
| 251 return None | 253 return None |
| 252 | 254 |
| 255 dedup = lambda x: sorted(set(x)) |
| 256 |
| 253 variables = {} | 257 variables = {} |
| 254 variables['template_type'] = target_type | 258 variables['template_type'] = target_type |
| 255 variables['use_gradle_process_resources'] = use_gradle_process_resources | 259 variables['use_gradle_process_resources'] = use_gradle_process_resources |
| 256 variables['build_tools_version'] = config_json['build_tools_version'] | 260 variables['build_tools_version'] = config_json['build_tools_version'] |
| 257 variables['compile_sdk_version'] = config_json['compile_sdk_version'] | 261 variables['compile_sdk_version'] = config_json['compile_sdk_version'] |
| 258 android_manifest = gradle.get('android_manifest', | 262 android_manifest = gradle.get('android_manifest', |
| 259 _DEFAULT_ANDROID_MANIFEST_PATH) | 263 _DEFAULT_ANDROID_MANIFEST_PATH) |
| 260 variables['android_manifest'] = relativize(android_manifest) | 264 variables['android_manifest'] = relativize(android_manifest) |
| 261 variables['java_dirs'] = relativize(java_dirs) | 265 variables['java_dirs'] = relativize(java_dirs) |
| 262 variables['prebuilts'] = relativize(gradle['dependent_prebuilt_jars']) | 266 variables['prebuilts'] = dedup(relativize(gradle['dependent_prebuilt_jars'])) |
| 263 deps = [_ProjectEntry.FromBuildConfigPath(p) | 267 deps = [_ProjectEntry.FromBuildConfigPath(p) |
| 264 for p in gradle['dependent_android_projects']] | 268 for p in gradle['dependent_android_projects']] |
| 265 | 269 |
| 266 variables['android_project_deps'] = [d.ProjectName() for d in deps] | 270 variables['android_project_deps'] = [d.ProjectName() for d in deps] |
| 267 deps = [_ProjectEntry.FromBuildConfigPath(p) | 271 deps = [_ProjectEntry.FromBuildConfigPath(p) |
| 268 for p in gradle['dependent_java_projects']] | 272 for p in gradle['dependent_java_projects']] |
| 269 variables['java_project_deps'] = [d.ProjectName() for d in deps] | 273 variables['java_project_deps'] = [d.ProjectName() for d in deps] |
| 270 | 274 |
| 271 return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables) | 275 return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables) |
| 272 | 276 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 if args.all: | 367 if args.all: |
| 364 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). | 368 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). |
| 365 _RunNinja(output_dir, ['build.ninja']) | 369 _RunNinja(output_dir, ['build.ninja']) |
| 366 # Query ninja for all __build_config targets. | 370 # Query ninja for all __build_config targets. |
| 367 targets = _QueryForAllGnTargets(output_dir) | 371 targets = _QueryForAllGnTargets(output_dir) |
| 368 else: | 372 else: |
| 369 targets = args.targets or _DEFAULT_TARGETS | 373 targets = args.targets or _DEFAULT_TARGETS |
| 370 # TODO(agrieve): See if it makes sense to utilize Gradle's test constructs | 374 # TODO(agrieve): See if it makes sense to utilize Gradle's test constructs |
| 371 # for our instrumentation tests. | 375 # for our instrumentation tests. |
| 372 targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] | 376 targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] |
| 377 targets = [re.sub(r'_junit_tests$', '_junit_tests__java_binary', t) |
| 378 for t in targets] |
| 373 | 379 |
| 374 main_entries = [_ProjectEntry(t) for t in targets] | 380 main_entries = [_ProjectEntry(t) for t in targets] |
| 375 | 381 |
| 376 logging.warning('Building .build_config files...') | 382 logging.warning('Building .build_config files...') |
| 377 _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) | 383 _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) |
| 378 | 384 |
| 379 # There are many unused libraries, so restrict to those that are actually used | 385 # There are many unused libraries, so restrict to those that are actually used |
| 380 # when using --all. | 386 # when using --all. |
| 381 if args.all: | 387 if args.all: |
| 382 main_entries = [e for e in main_entries if e.GetType() == 'android_apk'] | 388 main_entries = [e for e in main_entries if e.GetType() == 'android_apk'] |
| 383 | 389 |
| 384 all_entries = _FindAllProjectEntries(main_entries) | 390 all_entries = _FindAllProjectEntries(main_entries) |
| 385 logging.info('Found %d dependent build_config targets.', len(all_entries)) | 391 logging.info('Found %d dependent build_config targets.', len(all_entries)) |
| 386 | 392 |
| 387 logging.warning('Writing .gradle files...') | 393 logging.warning('Writing .gradle files...') |
| 388 jinja_processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) | 394 jinja_processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) |
| 389 config_json = build_utils.ReadJson( | 395 config_json = build_utils.ReadJson( |
| 390 os.path.join(output_dir, 'gradle', 'config.json')) | 396 os.path.join(output_dir, 'gradle', 'config.json')) |
| 391 project_entries = [] | 397 project_entries = [] |
| 392 srcjar_tuples = [] | 398 srcjar_tuples = [] |
| 393 for entry in all_entries: | 399 for entry in all_entries: |
| 394 if entry.GetType() not in ('android_apk', 'java_library'): | 400 if entry.GetType() not in ('android_apk', 'java_library', 'java_binary'): |
| 395 continue | 401 continue |
| 396 | 402 |
| 397 entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir()) | 403 entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir()) |
| 398 relativize = lambda x, d=entry_output_dir: _RebasePath(x, d) | 404 relativize = lambda x, d=entry_output_dir: _RebasePath(x, d) |
| 399 build_config = entry.BuildConfig() | 405 build_config = entry.BuildConfig() |
| 400 | 406 |
| 401 srcjars = _RebasePath(build_config['gradle'].get('bundled_srcjars', [])) | 407 srcjars = _RebasePath(build_config['gradle'].get('bundled_srcjars', [])) |
| 402 if not args.use_gradle_process_resources: | 408 if not args.use_gradle_process_resources: |
| 403 srcjars += _RebasePath(build_config['javac']['srcjars']) | 409 srcjars += _RebasePath(build_config['javac']['srcjars']) |
| 404 | 410 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 _RunNinja(output_dir, targets) | 442 _RunNinja(output_dir, targets) |
| 437 _ExtractSrcjars(gradle_output_dir, srcjar_tuples) | 443 _ExtractSrcjars(gradle_output_dir, srcjar_tuples) |
| 438 logging.warning('Project created! (%d subprojects)', len(project_entries)) | 444 logging.warning('Project created! (%d subprojects)', len(project_entries)) |
| 439 logging.warning('Generated projects work best with Android Studio 2.2') | 445 logging.warning('Generated projects work best with Android Studio 2.2') |
| 440 logging.warning('For more tips: https://chromium.googlesource.com/chromium' | 446 logging.warning('For more tips: https://chromium.googlesource.com/chromium' |
| 441 '/src.git/+/master/docs/android_studio.md') | 447 '/src.git/+/master/docs/android_studio.md') |
| 442 | 448 |
| 443 | 449 |
| 444 if __name__ == '__main__': | 450 if __name__ == '__main__': |
| 445 main() | 451 main() |
| OLD | NEW |