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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 SUFFIX_LEN = len('__build_config') | 108 SUFFIX_LEN = len('__build_config') |
109 for line in ninja_output.splitlines(): | 109 for line in ninja_output.splitlines(): |
110 ninja_target = line.rsplit(':', 1)[0] | 110 ninja_target = line.rsplit(':', 1)[0] |
111 # Ignore root aliases by ensure a : exists. | 111 # Ignore root aliases by ensure a : exists. |
112 if ':' in ninja_target and ninja_target.endswith('__build_config'): | 112 if ':' in ninja_target and ninja_target.endswith('__build_config'): |
113 ret.append('//' + ninja_target[:-SUFFIX_LEN]) | 113 ret.append('//' + ninja_target[:-SUFFIX_LEN]) |
114 return ret | 114 return ret |
115 | 115 |
116 | 116 |
117 class _ProjectEntry(object): | 117 class _ProjectEntry(object): |
118 """Helper class for various path transformations.""" | 118 """Helper class for project entries.""" |
119 def __init__(self, gn_target): | 119 def __init__(self, gn_target): |
120 assert gn_target.startswith('//'), gn_target | 120 assert gn_target.startswith('//'), gn_target |
121 if ':' not in gn_target: | 121 if ':' not in gn_target: |
122 gn_target = '%s:%s' % (gn_target, os.path.basename(gn_target)) | 122 gn_target = '%s:%s' % (gn_target, os.path.basename(gn_target)) |
123 self._gn_target = gn_target | 123 self._gn_target = gn_target |
124 self._build_config = None | 124 self._build_config = None |
125 self.android_test_entry = None | |
125 | 126 |
126 @classmethod | 127 @classmethod |
127 def FromBuildConfigPath(cls, path): | 128 def FromBuildConfigPath(cls, path): |
128 prefix = 'gen/' | 129 prefix = 'gen/' |
129 suffix = '.build_config' | 130 suffix = '.build_config' |
130 assert path.startswith(prefix) and path.endswith(suffix), path | 131 assert path.startswith(prefix) and path.endswith(suffix), path |
131 subdir = path[len(prefix):-len(suffix)] | 132 subdir = path[len(prefix):-len(suffix)] |
132 return cls('//%s:%s' % (os.path.split(subdir))) | 133 return cls('//%s:%s' % (os.path.split(subdir))) |
133 | 134 |
134 def __hash__(self): | 135 def __hash__(self): |
(...skipping 22 matching lines...) Expand all Loading... | |
157 """Returns the Gradle project name.""" | 158 """Returns the Gradle project name.""" |
158 return self.GradleSubdir().replace(os.path.sep, '>') | 159 return self.GradleSubdir().replace(os.path.sep, '>') |
159 | 160 |
160 def BuildConfig(self): | 161 def BuildConfig(self): |
161 """Reads and returns the project's .build_config JSON.""" | 162 """Reads and returns the project's .build_config JSON.""" |
162 if not self._build_config: | 163 if not self._build_config: |
163 path = os.path.join('gen', self.GradleSubdir() + '.build_config') | 164 path = os.path.join('gen', self.GradleSubdir() + '.build_config') |
164 self._build_config = build_utils.ReadJson(_RebasePath(path)) | 165 self._build_config = build_utils.ReadJson(_RebasePath(path)) |
165 return self._build_config | 166 return self._build_config |
166 | 167 |
168 def DepsInfo(self): | |
169 return self.BuildConfig()['deps_info'] | |
170 | |
171 def Gradle(self): | |
172 return self.BuildConfig()['gradle'] | |
173 | |
167 def GetType(self): | 174 def GetType(self): |
168 """Returns the target type from its .build_config.""" | 175 """Returns the target type from its .build_config.""" |
169 return self.BuildConfig()['deps_info']['type'] | 176 return self.DepsInfo()['type'] |
177 | |
178 def JavaFiles(self): | |
179 java_sources_file = self.Gradle().get('java_sources_file') | |
180 java_files = [] | |
181 if java_sources_file: | |
182 java_sources_file = _RebasePath(java_sources_file) | |
183 java_files = build_utils.ReadSourcesList(java_sources_file) | |
agrieve
2017/01/18 21:58:10
nit: cache this value.
Peter Wen
2017/01/19 16:43:07
Done.
| |
184 return java_files | |
185 | |
186 | |
187 class _GradleGenerator(object): | |
agrieve
2017/01/18 21:58:10
nit: this doesn't actuall generate gradle files. H
Peter Wen
2017/01/19 16:43:07
Done.
| |
188 """Helper class to generate gradle build files""" | |
189 def __init__(self, project_dir, use_gradle_process_resources): | |
190 self.project_dir = project_dir | |
191 self.use_gradle_process_resources = use_gradle_process_resources | |
192 | |
193 def _GenJniLibs(self, entry): | |
194 native_section = entry.BuildConfig().get('native') | |
195 if native_section: | |
196 jni_libs = _CreateJniLibsDir( | |
197 constants.GetOutDirectory(), self.OutputDir(entry), | |
198 native_section.get('libraries')) | |
199 else: | |
200 jni_libs = [] | |
201 return jni_libs | |
202 | |
203 def _GenJavaDirs(self, entry): | |
204 java_dirs = _CreateJavaSourceDir( | |
205 constants.GetOutDirectory(), self.OutputDir(entry), | |
206 entry.JavaFiles()) | |
207 if self.GenerateSrcjars(entry): | |
208 java_dirs.append(os.path.join(self.OutputDir(entry), _SRCJARS_SUBDIR)) | |
209 return java_dirs | |
210 | |
211 def _Relativize(self, entry, paths): | |
212 return _RebasePath(paths, self.OutputDir(entry)) | |
213 | |
214 def OutputDir(self, entry): | |
agrieve
2017/01/18 21:58:10
nit: conflicts with other output_dir. How about "E
Peter Wen
2017/01/19 16:43:07
Done.
| |
215 return os.path.join(self.project_dir, entry.GradleSubdir()) | |
216 | |
217 def GenerateSrcjars(self, entry): | |
agrieve
2017/01/18 21:58:10
this doesn't generate anything. How about jjust Sr
Peter Wen
2017/01/19 16:43:07
Done.
| |
218 srcjars = _RebasePath(entry.Gradle().get('bundled_srcjars', [])) | |
219 if not self.use_gradle_process_resources: | |
220 srcjars += _RebasePath(entry.BuildConfig()['javac']['srcjars']) | |
221 return srcjars | |
222 | |
223 def Generate(self, entry): | |
224 variables = {} | |
225 android_test_manifest = entry.Gradle().get( | |
226 'android_manifest', _DEFAULT_ANDROID_MANIFEST_PATH) | |
227 variables['android_manifest'] = self._Relativize( | |
228 entry, android_test_manifest) | |
229 variables['java_dirs'] = self._Relativize(entry, self._GenJavaDirs(entry)) | |
230 variables['jni_libs'] = self._Relativize(entry, self._GenJniLibs(entry)) | |
231 deps = [_ProjectEntry.FromBuildConfigPath(p) | |
232 for p in entry.Gradle()['dependent_android_projects']] | |
233 variables['android_project_deps'] = [d.ProjectName() for d in deps] | |
234 # TODO(agrieve): Add an option to use interface jars and see if that speeds | |
235 # things up at all. | |
236 variables['prebuilts'] = self._Relativize( | |
237 entry, entry.Gradle()['dependent_prebuilt_jars']) | |
238 deps = [_ProjectEntry.FromBuildConfigPath(p) | |
239 for p in entry.Gradle()['dependent_java_projects']] | |
240 variables['java_project_deps'] = [d.ProjectName() for d in deps] | |
241 return variables | |
242 | |
243 def GeneratedInputs(self, entry): | |
agrieve
2017/01/18 21:58:10
nit: might make more sense to have this right besi
Peter Wen
2017/01/19 16:43:07
Done.
| |
244 generated_inputs = [] | |
245 generated_inputs.extend(self.GenerateSrcjars(entry)) | |
246 generated_inputs.extend( | |
247 p for p in entry.JavaFiles() if not p.startswith('..')) | |
248 generated_inputs.extend(entry.Gradle()['dependent_prebuilt_jars']) | |
249 return generated_inputs | |
170 | 250 |
171 | 251 |
172 def _ComputeJavaSourceDirs(java_files): | 252 def _ComputeJavaSourceDirs(java_files): |
173 """Returns the list of source directories for the given files.""" | 253 """Returns the list of source directories for the given files.""" |
174 found_roots = set() | 254 found_roots = set() |
175 for path in java_files: | 255 for path in java_files: |
176 path_root = path | 256 path_root = path |
177 # Recognize these tokens as top-level. | 257 # Recognize these tokens as top-level. |
178 while True: | 258 while True: |
179 path_root = os.path.dirname(path_root) | 259 path_root = os.path.dirname(path_root) |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 | 351 |
272 | 352 |
273 def _GenerateLocalProperties(sdk_dir): | 353 def _GenerateLocalProperties(sdk_dir): |
274 """Returns the data for project.properties as a string.""" | 354 """Returns the data for project.properties as a string.""" |
275 return '\n'.join([ | 355 return '\n'.join([ |
276 '# Generated by //build/android/gradle/generate_gradle.py', | 356 '# Generated by //build/android/gradle/generate_gradle.py', |
277 'sdk.dir=%s' % sdk_dir, | 357 'sdk.dir=%s' % sdk_dir, |
278 '']) | 358 '']) |
279 | 359 |
280 | 360 |
281 def _GenerateGradleFile(build_config, build_vars, java_dirs, jni_libs, | 361 def _GenerateGradleFile(entry, generator, build_vars, jinja_processor): |
282 relativize, use_gradle_process_resources, | |
283 jinja_processor): | |
284 """Returns the data for a project's build.gradle.""" | 362 """Returns the data for a project's build.gradle.""" |
285 deps_info = build_config['deps_info'] | 363 deps_info = entry.DepsInfo() |
286 gradle = build_config['gradle'] | 364 gradle = entry.Gradle() |
287 | 365 |
288 variables = { | 366 variables = { |
289 'sourceSetName': 'main', | 367 'sourceSetName': 'main', |
290 'depCompileName': 'compile', | 368 'depCompileName': 'compile', |
291 } | 369 } |
292 if deps_info['type'] == 'android_apk': | 370 if deps_info['type'] == 'android_apk': |
293 target_type = 'android_apk' | 371 target_type = 'android_apk' |
294 elif deps_info['type'] == 'java_library': | 372 elif deps_info['type'] == 'java_library': |
295 if deps_info['is_prebuilt'] or deps_info['gradle_treat_as_prebuilt']: | 373 if deps_info['is_prebuilt'] or deps_info['gradle_treat_as_prebuilt']: |
296 return None | 374 return None |
297 | 375 elif deps_info['requires_android']: |
298 if deps_info['requires_android']: | |
299 target_type = 'android_library' | 376 target_type = 'android_library' |
300 else: | 377 else: |
301 target_type = 'java_library' | 378 target_type = 'java_library' |
302 elif deps_info['type'] == 'java_binary': | 379 elif deps_info['type'] == 'java_binary': |
303 if gradle['main_class'] == 'org.chromium.testing.local.JunitTestMain': | 380 if gradle['main_class'] == 'org.chromium.testing.local.JunitTestMain': |
304 target_type = 'android_junit' | 381 target_type = 'android_junit' |
305 variables['sourceSetName'] = 'test' | 382 variables['sourceSetName'] = 'test' |
306 variables['depCompileName'] = 'testCompile' | 383 variables['depCompileName'] = 'testCompile' |
307 else: | 384 else: |
308 target_type = 'java_binary' | 385 target_type = 'java_binary' |
309 variables['main_class'] = gradle['main_class'] | 386 variables['main_class'] = gradle['main_class'] |
310 else: | 387 else: |
311 return None | 388 return None |
312 | 389 |
313 variables['target_name'] = os.path.splitext(deps_info['name'])[0] | 390 variables['target_name'] = os.path.splitext(deps_info['name'])[0] |
314 variables['template_type'] = target_type | 391 variables['template_type'] = target_type |
315 variables['use_gradle_process_resources'] = use_gradle_process_resources | 392 variables['use_gradle_process_resources'] = ( |
393 generator.use_gradle_process_resources) | |
316 variables['build_tools_version'] = ( | 394 variables['build_tools_version'] = ( |
317 build_vars['android_sdk_build_tools_version']) | 395 build_vars['android_sdk_build_tools_version']) |
318 variables['compile_sdk_version'] = build_vars['android_sdk_version'] | 396 variables['compile_sdk_version'] = build_vars['android_sdk_version'] |
319 android_manifest = gradle.get('android_manifest', | 397 variables['main'] = generator.Generate(entry) |
320 _DEFAULT_ANDROID_MANIFEST_PATH) | 398 if entry.android_test_entry: |
321 variables['android_manifest'] = relativize(android_manifest) | 399 variables['android_test'] = generator.Generate( |
322 variables['java_dirs'] = relativize(java_dirs) | 400 entry.android_test_entry) |
323 variables['jni_libs'] = relativize(jni_libs) | |
324 # TODO(agrieve): Add an option to use interface jars and see if that speeds | |
325 # things up at all. | |
326 variables['prebuilts'] = relativize(gradle['dependent_prebuilt_jars']) | |
327 deps = [_ProjectEntry.FromBuildConfigPath(p) | |
328 for p in gradle['dependent_android_projects']] | |
329 | |
330 variables['android_project_deps'] = [d.ProjectName() for d in deps] | |
331 deps = [_ProjectEntry.FromBuildConfigPath(p) | |
332 for p in gradle['dependent_java_projects']] | |
333 variables['java_project_deps'] = [d.ProjectName() for d in deps] | |
334 | 401 |
335 return jinja_processor.Render( | 402 return jinja_processor.Render( |
336 _TemplatePath(target_type.split('_')[0]), variables) | 403 _TemplatePath(target_type.split('_')[0]), variables) |
337 | 404 |
338 | 405 |
339 def _GenerateRootGradle(jinja_processor): | 406 def _GenerateRootGradle(jinja_processor): |
340 """Returns the data for the root project's build.gradle.""" | 407 """Returns the data for the root project's build.gradle.""" |
341 return jinja_processor.Render(_TemplatePath('root')) | 408 return jinja_processor.Render(_TemplatePath('root')) |
342 | 409 |
343 | 410 |
(...skipping 29 matching lines...) Expand all Loading... | |
373 | 440 |
374 def _FindAllProjectEntries(main_entries): | 441 def _FindAllProjectEntries(main_entries): |
375 """Returns the list of all _ProjectEntry instances given the root project.""" | 442 """Returns the list of all _ProjectEntry instances given the root project.""" |
376 found = set() | 443 found = set() |
377 to_scan = list(main_entries) | 444 to_scan = list(main_entries) |
378 while to_scan: | 445 while to_scan: |
379 cur_entry = to_scan.pop() | 446 cur_entry = to_scan.pop() |
380 if cur_entry in found: | 447 if cur_entry in found: |
381 continue | 448 continue |
382 found.add(cur_entry) | 449 found.add(cur_entry) |
383 build_config = cur_entry.BuildConfig() | 450 sub_config_paths = cur_entry.DepsInfo()['deps_configs'] |
384 sub_config_paths = build_config['deps_info']['deps_configs'] | |
385 to_scan.extend( | 451 to_scan.extend( |
386 _ProjectEntry.FromBuildConfigPath(p) for p in sub_config_paths) | 452 _ProjectEntry.FromBuildConfigPath(p) for p in sub_config_paths) |
387 return list(found) | 453 return list(found) |
388 | 454 |
389 | 455 |
456 def _CombineTestEntries(entries): | |
agrieve
2017/01/18 21:58:10
It would be great to add some comments to this met
Peter Wen
2017/01/19 16:43:07
Done.
| |
457 combined_entries = [] | |
458 android_test_entries = {} | |
459 for entry in entries: | |
460 target_name = entry.GnTarget() | |
461 if (target_name.endswith('_test_apk__apk') and | |
462 'apk_under_test' in entry.Gradle()): | |
463 apk_name = entry.Gradle()['apk_under_test'] | |
464 android_test_entries[apk_name] = entry | |
465 else: | |
466 combined_entries.append(entry) | |
467 for entry in combined_entries: | |
468 target_name = entry.DepsInfo()['name'] | |
469 if target_name in android_test_entries: | |
470 entry.android_test_entry = android_test_entries[target_name] | |
471 del android_test_entries[target_name] | |
472 # Add unmatched test entries as individual targets. | |
473 combined_entries.extend(android_test_entries.values()) | |
474 return combined_entries | |
475 | |
476 | |
390 def main(): | 477 def main(): |
391 parser = argparse.ArgumentParser() | 478 parser = argparse.ArgumentParser() |
392 parser.add_argument('--output-directory', | 479 parser.add_argument('--output-directory', |
480 default='out/Debug', | |
393 help='Path to the root build directory.') | 481 help='Path to the root build directory.') |
394 parser.add_argument('-v', | 482 parser.add_argument('-v', |
395 '--verbose', | 483 '--verbose', |
396 dest='verbose_count', | 484 dest='verbose_count', |
397 default=0, | 485 default=0, |
398 action='count', | 486 action='count', |
399 help='Verbose level') | 487 help='Verbose level') |
400 parser.add_argument('--target', | 488 parser.add_argument('--target', |
401 dest='targets', | 489 dest='targets', |
402 action='append', | 490 action='append', |
403 help='GN target to generate project for. ' | 491 help='GN target to generate project for. ' |
404 'May be repeated.') | 492 'May be repeated.') |
405 parser.add_argument('--project-dir', | 493 parser.add_argument('--project-dir', |
406 help='Root of the output project.', | 494 help='Root of the output project.', |
407 default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle')) | 495 default=os.path.join('$CHROMIUM_OUTPUT_DIR', 'gradle')) |
408 parser.add_argument('--all', | 496 parser.add_argument('--all', |
409 action='store_true', | 497 action='store_true', |
410 help='Generate all java targets (slows down IDE)') | 498 help='Generate all java targets (slows down IDE)') |
411 parser.add_argument('--use-gradle-process-resources', | 499 parser.add_argument('--use-gradle-process-resources', |
412 action='store_true', | 500 action='store_true', |
413 help='Have gradle generate R.java rather than ninja') | 501 help='Have gradle generate R.java rather than ninja') |
414 args = parser.parse_args() | 502 args = parser.parse_args() |
415 if args.output_directory: | 503 if args.output_directory: |
416 constants.SetOutputDirectory(args.output_directory) | 504 constants.SetOutputDirectory(args.output_directory) |
417 constants.CheckOutputDirectory() | 505 constants.CheckOutputDirectory() |
418 output_dir = constants.GetOutDirectory() | 506 output_dir = constants.GetOutDirectory() |
419 devil_chromium.Initialize(output_directory=output_dir) | 507 devil_chromium.Initialize(output_directory=output_dir) |
420 run_tests_helper.SetLogLevel(args.verbose_count) | 508 run_tests_helper.SetLogLevel(args.verbose_count) |
421 | 509 |
422 gradle_output_dir = os.path.abspath( | 510 _gradle_output_dir = os.path.abspath( |
423 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) | 511 args.project_dir.replace('$CHROMIUM_OUTPUT_DIR', output_dir)) |
424 logging.warning('Creating project at: %s', gradle_output_dir) | 512 generator = _GradleGenerator( |
513 _gradle_output_dir, args.use_gradle_process_resources) | |
514 logging.warning('Creating project at: %s', generator.project_dir) | |
425 | 515 |
426 if args.all: | 516 if args.all: |
427 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). | 517 # Run GN gen if necessary (faster than running "gn gen" in the no-op case). |
428 _RunNinja(output_dir, ['build.ninja']) | 518 _RunNinja(constants.GetOutDirectory(), ['build.ninja']) |
429 # Query ninja for all __build_config targets. | 519 # Query ninja for all __build_config targets. |
430 targets = _QueryForAllGnTargets(output_dir) | 520 targets = _QueryForAllGnTargets(output_dir) |
431 else: | 521 else: |
432 targets = args.targets or _DEFAULT_TARGETS | 522 targets = args.targets or _DEFAULT_TARGETS |
433 # TODO(agrieve): See if it makes sense to utilize Gradle's test constructs | |
434 # for our instrumentation tests. | |
435 targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] | 523 targets = [re.sub(r'_test_apk$', '_test_apk__apk', t) for t in targets] |
524 # TODO(wnwen): Utilize Gradle's test constructs for our junit tests? | |
436 targets = [re.sub(r'_junit_tests$', '_junit_tests__java_binary', t) | 525 targets = [re.sub(r'_junit_tests$', '_junit_tests__java_binary', t) |
437 for t in targets] | 526 for t in targets] |
438 | 527 |
439 main_entries = [_ProjectEntry(t) for t in targets] | 528 main_entries = [_ProjectEntry(t) for t in targets] |
440 | 529 |
441 logging.warning('Building .build_config files...') | 530 logging.warning('Building .build_config files...') |
442 _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) | 531 _RunNinja(output_dir, [e.NinjaBuildConfigTarget() for e in main_entries]) |
443 | 532 |
444 # There are many unused libraries, so restrict to those that are actually used | 533 # There are many unused libraries, so restrict to those that are actually used |
445 # when using --all. | 534 # when using --all. |
446 if args.all: | 535 if args.all: |
447 main_entries = [e for e in main_entries if e.GetType() == 'android_apk'] | 536 main_entries = [e for e in main_entries if e.GetType() == 'android_apk'] |
448 | 537 |
449 all_entries = _FindAllProjectEntries(main_entries) | 538 all_entries = _FindAllProjectEntries(main_entries) |
450 logging.info('Found %d dependent build_config targets.', len(all_entries)) | 539 logging.info('Found %d dependent build_config targets.', len(all_entries)) |
540 entries = _CombineTestEntries(all_entries) | |
541 logging.info('Creating %d projects for targets.', len(entries)) | |
451 | 542 |
452 logging.warning('Writing .gradle files...') | 543 logging.warning('Writing .gradle files...') |
453 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) | 544 jinja_processor = jinja_template.JinjaProcessor(_FILE_DIR) |
454 build_vars = _ReadBuildVars(output_dir) | 545 build_vars = _ReadBuildVars(output_dir) |
455 project_entries = [] | 546 project_entries = [] |
456 srcjar_tuples = [] | 547 srcjar_tuples = [] |
457 generated_inputs = [] | 548 generated_inputs = [] |
458 for entry in all_entries: | 549 for entry in entries: |
459 if entry.GetType() not in ('android_apk', 'java_library', 'java_binary'): | 550 if entry.GetType() not in ('android_apk', 'java_library', 'java_binary'): |
460 continue | 551 continue |
461 | 552 |
462 entry_output_dir = os.path.join(gradle_output_dir, entry.GradleSubdir()) | 553 data = _GenerateGradleFile(entry, generator, build_vars, jinja_processor) |
463 relativize = lambda x, d=entry_output_dir: _RebasePath(x, d) | |
464 build_config = entry.BuildConfig() | |
465 | |
466 srcjars = _RebasePath(build_config['gradle'].get('bundled_srcjars', [])) | |
467 if not args.use_gradle_process_resources: | |
468 srcjars += _RebasePath(build_config['javac']['srcjars']) | |
469 | |
470 java_sources_file = build_config['gradle'].get('java_sources_file') | |
471 java_files = [] | |
472 if java_sources_file: | |
473 java_sources_file = _RebasePath(java_sources_file) | |
474 java_files = build_utils.ReadSourcesList(java_sources_file) | |
475 | |
476 java_dirs = _CreateJavaSourceDir(output_dir, entry_output_dir, java_files) | |
477 if srcjars: | |
478 java_dirs.append(os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) | |
479 | |
480 native_section = build_config.get('native') | |
481 if native_section: | |
482 jni_libs = _CreateJniLibsDir( | |
483 output_dir, entry_output_dir, native_section.get('libraries')) | |
484 else: | |
485 jni_libs = [] | |
486 | |
487 data = _GenerateGradleFile(build_config, build_vars, java_dirs, jni_libs, | |
488 relativize, args.use_gradle_process_resources, | |
489 jinja_processor) | |
490 if data: | 554 if data: |
491 project_entries.append(entry) | 555 project_entries.append(entry) |
492 # Build all paths references by .gradle that exist within output_dir. | 556 # Build all paths references by .gradle that exist within output_dir. |
493 generated_inputs.extend(srcjars) | 557 generated_inputs.extend(generator.GeneratedInputs(entry)) |
494 generated_inputs.extend(p for p in java_files if not p.startswith('..')) | 558 srcjar_tuples.extend( |
495 generated_inputs.extend(build_config['gradle']['dependent_prebuilt_jars']) | 559 (s, os.path.join(generator.OutputDir(entry), _SRCJARS_SUBDIR)) |
560 for s in generator.GenerateSrcjars(entry)) | |
561 _WriteFile(os.path.join(generator.OutputDir(entry), 'build.gradle'), data) | |
496 | 562 |
497 srcjar_tuples.extend( | 563 _WriteFile(os.path.join(generator.project_dir, 'build.gradle'), |
498 (s, os.path.join(entry_output_dir, _SRCJARS_SUBDIR)) for s in srcjars) | |
499 _WriteFile(os.path.join(entry_output_dir, 'build.gradle'), data) | |
500 | |
501 _WriteFile(os.path.join(gradle_output_dir, 'build.gradle'), | |
502 _GenerateRootGradle(jinja_processor)) | 564 _GenerateRootGradle(jinja_processor)) |
503 | 565 |
504 _WriteFile(os.path.join(gradle_output_dir, 'settings.gradle'), | 566 _WriteFile(os.path.join(generator.project_dir, 'settings.gradle'), |
505 _GenerateSettingsGradle(project_entries)) | 567 _GenerateSettingsGradle(project_entries)) |
506 | 568 |
507 sdk_path = _RebasePath(build_vars['android_sdk_root']) | 569 sdk_path = _RebasePath(build_vars['android_sdk_root']) |
508 _WriteFile(os.path.join(gradle_output_dir, 'local.properties'), | 570 _WriteFile(os.path.join(generator.project_dir, 'local.properties'), |
509 _GenerateLocalProperties(sdk_path)) | 571 _GenerateLocalProperties(sdk_path)) |
510 | 572 |
511 if generated_inputs: | 573 if generated_inputs: |
512 logging.warning('Building generated source files...') | 574 logging.warning('Building generated source files...') |
513 targets = _RebasePath(generated_inputs, output_dir) | 575 targets = _RebasePath(generated_inputs, output_dir) |
514 _RunNinja(output_dir, targets) | 576 _RunNinja(output_dir, targets) |
515 | 577 |
516 if srcjar_tuples: | 578 if srcjar_tuples: |
517 _ExtractSrcjars(gradle_output_dir, srcjar_tuples) | 579 _ExtractSrcjars(generator.project_dir, srcjar_tuples) |
518 | 580 |
519 logging.warning('Project created! (%d subprojects)', len(project_entries)) | 581 logging.warning('Project created! (%d subprojects)', len(project_entries)) |
520 logging.warning('Generated projects work best with Android Studio 2.2') | 582 logging.warning('Generated projects work best with Android Studio 2.2') |
521 logging.warning('For more tips: https://chromium.googlesource.com/chromium' | 583 logging.warning('For more tips: https://chromium.googlesource.com/chromium' |
522 '/src.git/+/master/docs/android_studio.md') | 584 '/src.git/+/master/docs/android_studio.md') |
523 | 585 |
524 | 586 |
525 if __name__ == '__main__': | 587 if __name__ == '__main__': |
526 main() | 588 main() |
OLD | NEW |