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