Chromium Code Reviews| Index: build/android/gradle/generate_gradle.py |
| diff --git a/build/android/gradle/generate_gradle.py b/build/android/gradle/generate_gradle.py |
| index 5564dfc5bb30f2f3c8052345aaf408d4d4996ffc..a7686a6208eeb12b417cfd7afe2d981076c91bb8 100755 |
| --- a/build/android/gradle/generate_gradle.py |
| +++ b/build/android/gradle/generate_gradle.py |
| @@ -67,13 +67,28 @@ def _WriteFile(path, data): |
| output_file.write(data) |
| -def _RunNinja(output_dir, ninja_targets): |
| +def _RunNinja(output_dir, args): |
| cmd = ['ninja', '-C', output_dir, '-j50'] |
| - cmd.extend(ninja_targets) |
| - logging.info('Running: %r', cmd) |
| + cmd.extend(args) |
| + if len(args) < 10: |
|
jbudorick
2016/09/22 02:34:46
Why < 10? What about only logging part of cmd if i
agrieve
2016/09/22 15:51:25
meh, removed the check. It shows only when running
|
| + logging.info('Running: %r', cmd) |
| subprocess.check_call(cmd) |
| +def _QueryForAllGnTargets(output_dir): |
| + cmd = ['ninja', '-C', output_dir, '-t', 'targets'] |
| + logging.info('Running: %r', cmd) |
| + ninja_output = build_utils.CheckOutput(cmd) |
| + ret = [] |
| + SUFFIX_LEN = len('__build_config') |
| + for line in ninja_output.splitlines(): |
| + ninja_target = line.rsplit(':', 1)[0] |
| + # Ignore root aliases by ensure a : exists. |
| + if ':' in ninja_target and ninja_target.endswith('__build_config'): |
|
jbudorick
2016/09/22 02:34:46
Why is this checking for ':'? We'd never hit a __b
agrieve
2016/09/22 15:51:25
It's because we're querying for ninja rather than
jbudorick
2016/09/22 15:57:43
Ah, yeah, I was thinking about the GN targets.
|
| + ret.append('//' + ninja_target[:-SUFFIX_LEN]) |
| + return ret |
| + |
| + |
| class _ProjectEntry(object): |
| """Helper class for various path transformations.""" |
| def __init__(self, gn_target): |
| @@ -164,7 +179,7 @@ def _CreateSymlinkTree(entry_output_dir, symlink_dir, desired_files, |
| os.symlink(relpath, symlinked_path) |
| -def _CreateJavaSourceDir(entry_output_dir, java_sources_file): |
| +def _CreateJavaSourceDir(output_dir, entry_output_dir, java_sources_file): |
| """Computes and constructs when necessary the list of java source directories. |
| 1. Computes the root java source directories from the list of files. |
| @@ -182,11 +197,15 @@ def _CreateJavaSourceDir(entry_output_dir, java_sources_file): |
| found_java_files = build_utils.FindInDirectories(java_dirs, '*.java') |
| unwanted_java_files = set(found_java_files) - set(java_files) |
| missing_java_files = set(java_files) - set(found_java_files) |
| + # Warn only about non-generated files that are missing. |
| + missing_java_files = [p for p in missing_java_files |
| + if not p.startswith(output_dir)] |
| if unwanted_java_files: |
| logging.debug('Target requires .java symlinks: %s', entry_output_dir) |
| symlink_dir = os.path.join(entry_output_dir, _JAVA_SUBDIR) |
| _CreateSymlinkTree(entry_output_dir, symlink_dir, java_files, java_dirs) |
| java_dirs = [symlink_dir] |
| + |
| if missing_java_files: |
| logging.warning('Some java files were not found: %s', missing_java_files) |
| @@ -202,7 +221,7 @@ def _GenerateLocalProperties(sdk_dir): |
| def _GenerateGradleFile(build_config, config_json, java_dirs, relativize, |
| - use_gradle_process_resources): |
| + use_gradle_process_resources, jinja_processor): |
| """Returns the data for a project's build.gradle.""" |
| deps_info = build_config['deps_info'] |
| gradle = build_config['gradle'] |
| @@ -235,15 +254,13 @@ def _GenerateGradleFile(build_config, config_json, java_dirs, relativize, |
| for p in gradle['dependent_java_projects']] |
| variables['java_project_deps'] = [d.ProjectName() for d in deps] |
| - processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) |
| - return processor.Render(_JINJA_TEMPLATE_PATH, variables) |
| + return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables) |
| -def _GenerateRootGradle(): |
| +def _GenerateRootGradle(jinja_processor): |
| """Returns the data for the root project's build.gradle.""" |
| variables = {'template_type': 'root'} |
| - processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) |
| - return processor.Render(_JINJA_TEMPLATE_PATH, variables) |
| + return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables) |
| def _GenerateSettingsGradle(project_entries): |
| @@ -277,10 +294,10 @@ def _ExtractSrcjars(entry_output_dir, srcjar_tuples): |
| z.extractall(extracted_path) |
| -def _FindAllProjectEntries(main_entry): |
| +def _FindAllProjectEntries(main_entries): |
| """Returns the list of all _ProjectEntry instances given the root project.""" |
| found = set() |
| - to_scan = [main_entry] |
| + to_scan = list(main_entries) |
| while to_scan: |
| cur_entry = to_scan.pop() |
| if cur_entry in found: |
| @@ -304,11 +321,17 @@ def main(): |
| action='count', |
| help='Verbose level') |
| parser.add_argument('--target', |
| - help='GN target to generate project for.', |
| - default='//chrome/android:chrome_public_apk') |
| + dest='targets', |
| + action='append', |
| + help='GN target to generate project for. ' |
| + 'May be repeated.', |
| + default=['//chrome/android:chrome_public_test_apk']) |
| parser.add_argument('--project-dir', |
| help='Root of the output project.', |
| default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle')) |
| + parser.add_argument('--all', |
| + action='store_true', |
| + help='Generate all java targets (slows down IDE)') |
| parser.add_argument('--use-gradle-process-resources', |
| action='store_true', |
| help='Have gradle generate R.java rather than ninja') |
| @@ -324,13 +347,22 @@ def main(): |
| args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) |
| logging.warning('Creating project at: %s', gradle_output_dir) |
| - main_entry = _ProjectEntry(args.target) |
| + if args.all: |
| + # Run GN gen if necessary. |
| + _RunNinja(output_dir, ['build.ninja']) |
|
jbudorick
2016/09/22 02:34:46
This is ... building build.ninja? I take it that's
agrieve
2016/09/22 15:51:25
Added a comment - it's faster than running gn gen
jbudorick
2016/09/22 15:57:43
ah, sgtm
|
| + # Query ninja for all __build_config targets. |
| + targets = _QueryForAllGnTargets(output_dir) |
| + else: |
| + targets = args.targets |
| + |
| + main_entries = [_ProjectEntry(t) for t in targets] |
| logging.warning('Building .build_config files...') |
| - _RunNinja(output_dir, [main_entry.NinjaBuildConfigTarget()]) |
| + _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) |
| - all_entries = _FindAllProjectEntries(main_entry) |
| + all_entries = _FindAllProjectEntries(main_entries) |
| logging.info('Found %d dependent build_config targets.', len(all_entries)) |
| + jinja_processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) |
| config_json = build_utils.ReadJson( |
| os.path.join(output_dir, 'gradle', 'config.json')) |
| project_entries = [] |
| @@ -351,12 +383,14 @@ def main(): |
| if java_sources_file: |
| java_sources_file = _RebasePath(java_sources_file) |
| - java_dirs = _CreateJavaSourceDir(entry_output_dir, java_sources_file) |
| + java_dirs = _CreateJavaSourceDir(output_dir, entry_output_dir, |
| + java_sources_file) |
| if srcjars: |
| java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) |
| data = _GenerateGradleFile(build_config, config_json, java_dirs, relativize, |
| - args.use_gradle_process_resources) |
| + args.use_gradle_process_resources, |
| + jinja_processor) |
| if data: |
| project_entries.append(entry) |
| srcjar_tuples.extend( |
| @@ -364,7 +398,7 @@ def main(): |
| _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data) |
| _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'), |
| - _GenerateRootGradle()) |
| + _GenerateRootGradle(jinja_processor)) |
| _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'), |
| _GenerateSettingsGradle(project_entries)) |