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 |
11 import os | 11 import os |
12 import re | |
12 import shutil | 13 import shutil |
13 import subprocess | 14 import subprocess |
14 import sys | 15 import sys |
15 import zipfile | 16 import zipfile |
16 | 17 |
17 _BUILD_ANDROID = os.path.join(os.path.dirname(__file__), os.pardir) | 18 _BUILD_ANDROID = os.path.join(os.path.dirname(__file__), os.pardir) |
18 sys.path.append(_BUILD_ANDROID) | 19 sys.path.append(_BUILD_ANDROID) |
19 import devil_chromium | 20 import devil_chromium |
20 from devil.utils import run_tests_helper | 21 from devil.utils import run_tests_helper |
21 from pylib import constants | 22 from pylib import constants |
22 from pylib.constants import host_paths | 23 from pylib.constants import host_paths |
23 | 24 |
24 sys.path.append(os.path.join(_BUILD_ANDROID, 'gyp')) | 25 sys.path.append(os.path.join(_BUILD_ANDROID, 'gyp')) |
25 import jinja_template | 26 import jinja_template |
26 from util import build_utils | 27 from util import build_utils |
27 | 28 |
28 | 29 |
29 _DEFAULT_ANDROID_MANIFEST_PATH = os.path.join( | 30 _DEFAULT_ANDROID_MANIFEST_PATH = os.path.join( |
30 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml') | 31 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml') |
31 _JINJA_TEMPLATE_PATH = os.path.join( | 32 _JINJA_TEMPLATE_PATH = os.path.join( |
32 os.path.dirname(__file__), 'build.gradle.jinja') | 33 os.path.dirname(__file__), 'build.gradle.jinja') |
33 | 34 |
34 _JAVA_SUBDIR = 'symlinked-java' | 35 _JAVA_SUBDIR = 'symlinked-java' |
35 _SRCJARS_SUBDIR = 'extracted-srcjars' | 36 _SRCJARS_SUBDIR = 'extracted-srcjars' |
36 | 37 |
38 _DEFAULT_TARGETS = [ | |
39 '//android_webview:system_webview_apk', | |
40 '//android_webview/test:android_webview_apk', | |
41 '//android_webview/test:android_webview_test_apk', | |
42 '//chrome/android:chrome_public_apk', | |
43 '//chrome/android:chrome_public_test_apk', | |
44 '//chrome/android:chrome_sync_shell_apk', | |
45 '//chrome/android:chrome_sync_shell_test_apk', | |
46 ] | |
37 | 47 |
38 def _RebasePath(path_or_list, new_cwd=None, old_cwd=None): | 48 def _RebasePath(path_or_list, new_cwd=None, old_cwd=None): |
39 """Makes the given path(s) relative to new_cwd, or absolute if not specified. | 49 """Makes the given path(s) relative to new_cwd, or absolute if not specified. |
40 | 50 |
41 If new_cwd is not specified, absolute paths are returned. | 51 If new_cwd is not specified, absolute paths are returned. |
42 If old_cwd is not specified, constants.GetOutDirectory() is assumed. | 52 If old_cwd is not specified, constants.GetOutDirectory() is assumed. |
43 """ | 53 """ |
44 if not isinstance(path_or_list, basestring): | 54 if not isinstance(path_or_list, basestring): |
45 return [_RebasePath(p, new_cwd, old_cwd) for p in path_or_list] | 55 return [_RebasePath(p, new_cwd, old_cwd) for p in path_or_list] |
46 if old_cwd is None: | 56 if old_cwd is None: |
(...skipping 13 matching lines...) Expand all Loading... | |
60 def _WriteFile(path, data): | 70 def _WriteFile(path, data): |
61 """Writes |data| to |path|, constucting parent directories if necessary.""" | 71 """Writes |data| to |path|, constucting parent directories if necessary.""" |
62 logging.info('Writing %s', path) | 72 logging.info('Writing %s', path) |
63 dirname = os.path.dirname(path) | 73 dirname = os.path.dirname(path) |
64 if not os.path.exists(dirname): | 74 if not os.path.exists(dirname): |
65 os.makedirs(dirname) | 75 os.makedirs(dirname) |
66 with codecs.open(path, 'w', 'utf-8') as output_file: | 76 with codecs.open(path, 'w', 'utf-8') as output_file: |
67 output_file.write(data) | 77 output_file.write(data) |
68 | 78 |
69 | 79 |
70 def _RunNinja(output_dir, ninja_targets): | 80 def _RunNinja(output_dir, args): |
71 cmd = ['ninja', '-C', output_dir, '-j50'] | 81 cmd = ['ninja', '-C', output_dir, '-j50'] |
72 cmd.extend(ninja_targets) | 82 cmd.extend(args) |
73 logging.info('Running: %r', cmd) | 83 logging.info('Running: %r', cmd) |
74 subprocess.check_call(cmd) | 84 subprocess.check_call(cmd) |
75 | 85 |
76 | 86 |
87 def _QueryForAllGnTargets(output_dir): | |
88 # Query ninja rather than GN since it's faster. | |
89 cmd = ['ninja', '-C', output_dir, '-t', 'targets'] | |
90 logging.info('Running: %r', cmd) | |
91 ninja_output = build_utils.CheckOutput(cmd) | |
92 ret = [] | |
93 SUFFIX_LEN = len('__build_config') | |
94 for line in ninja_output.splitlines(): | |
95 ninja_target = line.rsplit(':', 1)[0] | |
96 # Ignore root aliases by ensure a : exists. | |
97 if ':' in ninja_target and ninja_target.endswith('__build_config'): | |
98 ret.append('//' + ninja_target[:-SUFFIX_LEN]) | |
99 return ret | |
100 | |
101 | |
77 class _ProjectEntry(object): | 102 class _ProjectEntry(object): |
78 """Helper class for various path transformations.""" | 103 """Helper class for various path transformations.""" |
79 def __init__(self, gn_target): | 104 def __init__(self, gn_target): |
80 assert gn_target.startswith('//'), gn_target | 105 assert gn_target.startswith('//'), gn_target |
81 if ':' not in gn_target: | 106 if ':' not in gn_target: |
82 gn_target = '%s:%s' % (gn_target, os.path.basename(gn_target)) | 107 gn_target = '%s:%s' % (gn_target, os.path.basename(gn_target)) |
83 self._gn_target = gn_target | 108 self._gn_target = gn_target |
84 self._build_config = None | 109 self._build_config = None |
85 | 110 |
86 @classmethod | 111 @classmethod |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 subpath = os.path.relpath(target_path, prefix) | 182 subpath = os.path.relpath(target_path, prefix) |
158 symlinked_path = os.path.join(symlink_dir, subpath) | 183 symlinked_path = os.path.join(symlink_dir, subpath) |
159 symlinked_dir = os.path.dirname(symlinked_path) | 184 symlinked_dir = os.path.dirname(symlinked_path) |
160 if not os.path.exists(symlinked_dir): | 185 if not os.path.exists(symlinked_dir): |
161 os.makedirs(symlinked_dir) | 186 os.makedirs(symlinked_dir) |
162 relpath = os.path.relpath(target_path, symlinked_dir) | 187 relpath = os.path.relpath(target_path, symlinked_dir) |
163 logging.debug('Creating symlink %s -> %s', symlinked_path, relpath) | 188 logging.debug('Creating symlink %s -> %s', symlinked_path, relpath) |
164 os.symlink(relpath, symlinked_path) | 189 os.symlink(relpath, symlinked_path) |
165 | 190 |
166 | 191 |
167 def _CreateJavaSourceDir(entry_output_dir, java_sources_file): | 192 def _CreateJavaSourceDir(output_dir, entry_output_dir, java_sources_file): |
168 """Computes and constructs when necessary the list of java source directories. | 193 """Computes and constructs when necessary the list of java source directories. |
169 | 194 |
170 1. Computes the root java source directories from the list of files. | 195 1. Computes the root java source directories from the list of files. |
171 2. Determines whether there are any .java files in them that are not included | 196 2. Determines whether there are any .java files in them that are not included |
172 in |java_sources_file|. | 197 in |java_sources_file|. |
173 3. If not, returns the list of java source directories. If so, constructs a | 198 3. If not, returns the list of java source directories. If so, constructs a |
174 tree of symlinks within |entry_output_dir| of all files in | 199 tree of symlinks within |entry_output_dir| of all files in |
175 |java_sources_file|. | 200 |java_sources_file|. |
176 """ | 201 """ |
177 java_dirs = [] | 202 java_dirs = [] |
178 if java_sources_file: | 203 if java_sources_file: |
179 java_files = _RebasePath(build_utils.ReadSourcesList(java_sources_file)) | 204 java_files = _RebasePath(build_utils.ReadSourcesList(java_sources_file)) |
180 java_dirs = _ComputeJavaSourceDirs(java_files) | 205 java_dirs = _ComputeJavaSourceDirs(java_files) |
181 | 206 |
182 found_java_files = build_utils.FindInDirectories(java_dirs, '*.java') | 207 found_java_files = build_utils.FindInDirectories(java_dirs, '*.java') |
183 unwanted_java_files = set(found_java_files) - set(java_files) | 208 unwanted_java_files = set(found_java_files) - set(java_files) |
184 missing_java_files = set(java_files) - set(found_java_files) | 209 missing_java_files = set(java_files) - set(found_java_files) |
210 # Warn only about non-generated files that are missing. | |
211 missing_java_files = [p for p in missing_java_files | |
212 if not p.startswith(output_dir)] | |
185 if unwanted_java_files: | 213 if unwanted_java_files: |
186 logging.debug('Target requires .java symlinks: %s', entry_output_dir) | 214 logging.debug('Target requires .java symlinks: %s', entry_output_dir) |
187 symlink_dir = os.path.join(entry_output_dir, _JAVA_SUBDIR) | 215 symlink_dir = os.path.join(entry_output_dir, _JAVA_SUBDIR) |
188 _CreateSymlinkTree(entry_output_dir, symlink_dir, java_files, java_dirs) | 216 _CreateSymlinkTree(entry_output_dir, symlink_dir, java_files, java_dirs) |
189 java_dirs = [symlink_dir] | 217 java_dirs = [symlink_dir] |
218 | |
190 if missing_java_files: | 219 if missing_java_files: |
191 logging.warning('Some java files were not found: %s', missing_java_files) | 220 logging.warning('Some java files were not found: %s', missing_java_files) |
192 | 221 |
193 return java_dirs | 222 return java_dirs |
194 | 223 |
195 | 224 |
196 def _GenerateLocalProperties(sdk_dir): | 225 def _GenerateLocalProperties(sdk_dir): |
197 """Returns the data for project.properties as a string.""" | 226 """Returns the data for project.properties as a string.""" |
198 return '\n'.join([ | 227 return '\n'.join([ |
199 '# Generated by //build/android/gradle/generate_gradle.py', | 228 '# Generated by //build/android/gradle/generate_gradle.py', |
200 'sdk.dir=%s' % sdk_dir, | 229 'sdk.dir=%s' % sdk_dir, |
201 '']) | 230 '']) |
202 | 231 |
203 | 232 |
204 def _GenerateGradleFile(build_config, config_json, java_dirs, relativize, | 233 def _GenerateGradleFile(build_config, config_json, java_dirs, relativize, |
205 use_gradle_process_resources): | 234 use_gradle_process_resources, jinja_processor): |
206 """Returns the data for a project's build.gradle.""" | 235 """Returns the data for a project's build.gradle.""" |
207 deps_info = build_config['deps_info'] | 236 deps_info = build_config['deps_info'] |
208 gradle = build_config['gradle'] | 237 gradle = build_config['gradle'] |
209 | 238 |
210 if deps_info['type'] == 'android_apk': | 239 if deps_info['type'] == 'android_apk': |
211 target_type = 'android_apk' | 240 target_type = 'android_apk' |
212 elif deps_info['type'] == 'java_library' and not deps_info['is_prebuilt']: | 241 elif deps_info['type'] == 'java_library' and not deps_info['is_prebuilt']: |
213 if deps_info['requires_android']: | 242 if deps_info['requires_android']: |
214 target_type = 'android_library' | 243 target_type = 'android_library' |
215 else: | 244 else: |
(...skipping 12 matching lines...) Expand all Loading... | |
228 variables['java_dirs'] = relativize(java_dirs) | 257 variables['java_dirs'] = relativize(java_dirs) |
229 variables['prebuilts'] = relativize(gradle['dependent_prebuilt_jars']) | 258 variables['prebuilts'] = relativize(gradle['dependent_prebuilt_jars']) |
230 deps = [_ProjectEntry.FromBuildConfigPath(p) | 259 deps = [_ProjectEntry.FromBuildConfigPath(p) |
231 for p in gradle['dependent_android_projects']] | 260 for p in gradle['dependent_android_projects']] |
232 | 261 |
233 variables['android_project_deps'] = [d.ProjectName() for d in deps] | 262 variables['android_project_deps'] = [d.ProjectName() for d in deps] |
234 deps = [_ProjectEntry.FromBuildConfigPath(p) | 263 deps = [_ProjectEntry.FromBuildConfigPath(p) |
235 for p in gradle['dependent_java_projects']] | 264 for p in gradle['dependent_java_projects']] |
236 variables['java_project_deps'] = [d.ProjectName() for d in deps] | 265 variables['java_project_deps'] = [d.ProjectName() for d in deps] |
237 | 266 |
238 processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) | 267 return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables) |
239 return processor.Render(_JINJA_TEMPLATE_PATH, variables) | |
240 | 268 |
241 | 269 |
242 def _GenerateRootGradle(): | 270 def _GenerateRootGradle(jinja_processor): |
243 """Returns the data for the root project's build.gradle.""" | 271 """Returns the data for the root project's build.gradle.""" |
244 variables = {'template_type': 'root'} | 272 variables = {'template_type': 'root'} |
245 processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) | 273 return jinja_processor.Render(_JINJA_TEMPLATE_PATH, variables) |
246 return processor.Render(_JINJA_TEMPLATE_PATH, variables) | |
247 | 274 |
248 | 275 |
249 def _GenerateSettingsGradle(project_entries): | 276 def _GenerateSettingsGradle(project_entries): |
250 """Returns the data for settings.gradle.""" | 277 """Returns the data for settings.gradle.""" |
251 project_name = os.path.basename(os.path.dirname(host_paths.DIR_SOURCE_ROOT)) | 278 project_name = os.path.basename(os.path.dirname(host_paths.DIR_SOURCE_ROOT)) |
252 lines = [] | 279 lines = [] |
253 lines.append('// Generated by //build/android/gradle/generate_gradle.py') | 280 lines.append('// Generated by //build/android/gradle/generate_gradle.py') |
254 lines.append('rootProject.name = "%s"' % project_name) | 281 lines.append('rootProject.name = "%s"' % project_name) |
255 lines.append('rootProject.projectDir = settingsDir') | 282 lines.append('rootProject.projectDir = settingsDir') |
256 lines.append('') | 283 lines.append('') |
(...skipping 13 matching lines...) Expand all Loading... | |
270 assert _IsSubpathOf(extracted_path, entry_output_dir) | 297 assert _IsSubpathOf(extracted_path, entry_output_dir) |
271 if os.path.exists(extracted_path): | 298 if os.path.exists(extracted_path): |
272 shutil.rmtree(extracted_path) | 299 shutil.rmtree(extracted_path) |
273 | 300 |
274 for srcjar_path, extracted_path in srcjar_tuples: | 301 for srcjar_path, extracted_path in srcjar_tuples: |
275 logging.info('Extracting %s to %s', srcjar_path, extracted_path) | 302 logging.info('Extracting %s to %s', srcjar_path, extracted_path) |
276 with zipfile.ZipFile(srcjar_path) as z: | 303 with zipfile.ZipFile(srcjar_path) as z: |
277 z.extractall(extracted_path) | 304 z.extractall(extracted_path) |
278 | 305 |
279 | 306 |
280 def _FindAllProjectEntries(main_entry): | 307 def _FindAllProjectEntries(main_entries): |
281 """Returns the list of all _ProjectEntry instances given the root project.""" | 308 """Returns the list of all _ProjectEntry instances given the root project.""" |
282 found = set() | 309 found = set() |
283 to_scan = [main_entry] | 310 to_scan = list(main_entries) |
284 while to_scan: | 311 while to_scan: |
285 cur_entry = to_scan.pop() | 312 cur_entry = to_scan.pop() |
286 if cur_entry in found: | 313 if cur_entry in found: |
287 continue | 314 continue |
288 found.add(cur_entry) | 315 found.add(cur_entry) |
289 build_config = cur_entry.BuildConfig() | 316 build_config = cur_entry.BuildConfig() |
290 sub_config_paths = build_config['deps_info']['deps_configs'] | 317 sub_config_paths = build_config['deps_info']['deps_configs'] |
291 to_scan.extend( | 318 to_scan.extend( |
292 _ProjectEntry.FromBuildConfigPath(p) for p in sub_config_paths) | 319 _ProjectEntry.FromBuildConfigPath(p) for p in sub_config_paths) |
293 return list(found) | 320 return list(found) |
294 | 321 |
295 | 322 |
296 def main(): | 323 def main(): |
297 parser = argparse.ArgumentParser() | 324 parser = argparse.ArgumentParser() |
298 parser.add_argument('--output-directory', | 325 parser.add_argument('--output-directory', |
299 help='Path to the root build directory.') | 326 help='Path to the root build directory.') |
300 parser.add_argument('-v', | 327 parser.add_argument('-v', |
301 '--verbose', | 328 '--verbose', |
302 dest='verbose_count', | 329 dest='verbose_count', |
303 default=0, | 330 default=0, |
304 action='count', | 331 action='count', |
305 help='Verbose level') | 332 help='Verbose level') |
306 parser.add_argument('--target', | 333 parser.add_argument('--target', |
307 help='GN target to generate project for.', | 334 dest='targets', |
308 default='//chrome/android:chrome_public_test_apk') | 335 action='append', |
336 help='GN target to generate project for. ' | |
337 'May be repeated.') | |
309 parser.add_argument('--project-dir', | 338 parser.add_argument('--project-dir', |
310 help='Root of the output project.', | 339 help='Root of the output project.', |
311 default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle')) | 340 default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle')) |
341 parser.add_argument('--all', | |
342 action='store_true', | |
343 help='Generate all java targets (slows down IDE)') | |
312 parser.add_argument('--use-gradle-process-resources', | 344 parser.add_argument('--use-gradle-process-resources', |
313 action='store_true', | 345 action='store_true', |
314 help='Have gradle generate R.java rather than ninja') | 346 help='Have gradle generate R.java rather than ninja') |
315 args = parser.parse_args() | 347 args = parser.parse_args() |
316 if args.output_directory: | 348 if args.output_directory: |
317 constants.SetOutputDirectory(args.output_directory) | 349 constants.SetOutputDirectory(args.output_directory) |
318 constants.CheckOutputDirectory() | 350 constants.CheckOutputDirectory() |
319 output_dir = constants.GetOutDirectory() | 351 output_dir = constants.GetOutDirectory() |
320 devil_chromium.Initialize(output_directory=output_dir) | 352 devil_chromium.Initialize(output_directory=output_dir) |
321 run_tests_helper.SetLogLevel(args.verbose_count) | 353 run_tests_helper.SetLogLevel(args.verbose_count) |
322 | 354 |
323 gradle_output_dir = os.path.abspath( | 355 gradle_output_dir = os.path.abspath( |
324 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) | 356 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) |
325 logging.warning('Creating project at: %s', gradle_output_dir) | 357 logging.warning('Creating project at: %s', gradle_output_dir) |
326 | 358 |
327 target = args.target | 359 if args.all: |
328 # TODO(agrieve): See if it makes sense to utilize Gradle's test constructs for | 360 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). |
329 # our instrumentation tests. | 361 _RunNinja(output_dir, ['build.ninja']) |
330 if target.endswith('_test_apk'): | 362 # Query ninja for all __build_config targets. |
331 target += '__apk' | 363 targets = _QueryForAllGnTargets(output_dir) |
332 main_entry = _ProjectEntry(target) | 364 else: |
365 targets = args.targets or _DEFAULT_TARGETS | |
366 # TODO(agrieve): See if it makes sense to utilize Gradle's test constructs | |
367 # for our instrumentation tests. | |
368 targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] | |
jbudorick
2016/09/22 15:57:44
just curious -- why the __apk target?
agrieve
2016/09/22 16:58:15
That's the name of the android_apk() target forins
| |
369 | |
370 main_entries = [_ProjectEntry(t) for t in targets] | |
333 logging.warning('Building .build_config files...') | 371 logging.warning('Building .build_config files...') |
334 _RunNinja(output_dir, [main_entry.NinjaBuildConfigTarget()]) | 372 _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) |
335 | 373 |
336 all_entries = _FindAllProjectEntries(main_entry) | 374 all_entries = _FindAllProjectEntries(main_entries) |
337 logging.info('Found %d dependent build_config targets.', len(all_entries)) | 375 logging.info('Found %d dependent build_config targets.', len(all_entries)) |
338 | 376 |
377 logging.warning('Writing .gradle files...') | |
378 jinja_processor = jinja_template.JinjaProcessor(host_paths.DIR_SOURCE_ROOT) | |
339 config_json = build_utils.ReadJson( | 379 config_json = build_utils.ReadJson( |
340 os.path.join(output_dir, 'gradle', 'config.json')) | 380 os.path.join(output_dir, 'gradle', 'config.json')) |
341 project_entries = [] | 381 project_entries = [] |
342 srcjar_tuples = [] | 382 srcjar_tuples = [] |
343 for entry in all_entries: | 383 for entry in all_entries: |
344 build_config = entry.BuildConfig() | 384 build_config = entry.BuildConfig() |
345 if build_config['deps_info']['type'] not in ('android_apk', 'java_library'): | 385 if build_config['deps_info']['type'] not in ('android_apk', 'java_library'): |
346 continue | 386 continue |
347 | 387 |
348 entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir()) | 388 entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir()) |
349 relativize = lambda x, d=entry_output_dir: _RebasePath(x, d) | 389 relativize = lambda x, d=entry_output_dir: _RebasePath(x, d) |
350 | 390 |
351 srcjars = _RebasePath(build_config['gradle'].get('bundled_srcjars', [])) | 391 srcjars = _RebasePath(build_config['gradle'].get('bundled_srcjars', [])) |
352 if not args.use_gradle_process_resources: | 392 if not args.use_gradle_process_resources: |
353 srcjars += _RebasePath(build_config['javac']['srcjars']) | 393 srcjars += _RebasePath(build_config['javac']['srcjars']) |
354 | 394 |
355 java_sources_file = build_config['gradle'].get('java_sources_file') | 395 java_sources_file = build_config['gradle'].get('java_sources_file') |
356 if java_sources_file: | 396 if java_sources_file: |
357 java_sources_file = _RebasePath(java_sources_file) | 397 java_sources_file = _RebasePath(java_sources_file) |
358 | 398 |
359 java_dirs = _CreateJavaSourceDir(entry_output_dir, java_sources_file) | 399 java_dirs = _CreateJavaSourceDir(output_dir, entry_output_dir, |
400 java_sources_file) | |
360 if srcjars: | 401 if srcjars: |
361 java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) | 402 java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) |
362 | 403 |
363 data = _GenerateGradleFile(build_config, config_json, java_dirs, relativize, | 404 data = _GenerateGradleFile(build_config, config_json, java_dirs, relativize, |
364 args.use_gradle_process_resources) | 405 args.use_gradle_process_resources, |
406 jinja_processor) | |
365 if data: | 407 if data: |
366 project_entries.append(entry) | 408 project_entries.append(entry) |
367 srcjar_tuples.extend( | 409 srcjar_tuples.extend( |
368 (s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) for s in srcjars) | 410 (s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) for s in srcjars) |
369 _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data) | 411 _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data) |
370 | 412 |
371 _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'), | 413 _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'), |
372 _GenerateRootGradle()) | 414 _GenerateRootGradle(jinja_processor)) |
373 | 415 |
374 _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'), | 416 _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'), |
375 _GenerateSettingsGradle(project_entries)) | 417 _GenerateSettingsGradle(project_entries)) |
376 | 418 |
377 sdk_path = _RebasePath(config_json['android_sdk_root']) | 419 sdk_path = _RebasePath(config_json['android_sdk_root']) |
378 _WriteFile(os.path.join(gradle_output_dir, 'local.properties'), | 420 _WriteFile(os.path.join(gradle_output_dir, 'local.properties'), |
379 _GenerateLocalProperties(sdk_path)) | 421 _GenerateLocalProperties(sdk_path)) |
380 | 422 |
381 if srcjar_tuples: | 423 if srcjar_tuples: |
382 logging.warning('Building all .srcjar files...') | 424 logging.warning('Building all .srcjar files...') |
383 targets = _RebasePath([s[0] for s in srcjar_tuples], output_dir) | 425 targets = _RebasePath([s[0] for s in srcjar_tuples], output_dir) |
384 _RunNinja(output_dir, targets) | 426 _RunNinja(output_dir, targets) |
385 _ExtractSrcjars(gradle_output_dir, srcjar_tuples) | 427 _ExtractSrcjars(gradle_output_dir, srcjar_tuples) |
386 logging.warning('Project created successfully!') | 428 logging.warning('Project created successfully!') |
387 logging.warning('Generated projects work best with Android Studio 2.2') | 429 logging.warning('Generated projects work best with Android Studio 2.2') |
388 logging.warning('For more tips: https://chromium.googlesource.com/chromium' | 430 logging.warning('For more tips: https://chromium.googlesource.com/chromium' |
389 '/src.git/+/master/docs/android_studio.md') | 431 '/src.git/+/master/docs/android_studio.md') |
390 | 432 |
391 | 433 |
392 if __name__ == '__main__': | 434 if __name__ == '__main__': |
393 main() | 435 main() |
OLD | NEW |