Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: build/android/gyp/process_resources.py

Issue 1370643002: Revert of Make use of md5_check within process_resources.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@md5-check-1
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Process Android resources to generate R.java, and prepare for packaging. 7 """Process Android resources to generate R.java, and prepare for packaging.
8 8
9 This will crunch images and generate v14 compatible resources 9 This will crunch images and generate v14 compatible resources
10 (see generate_v14_compatible_resources.py). 10 (see generate_v14_compatible_resources.py).
(...skipping 15 matching lines...) Expand all
26 sys.path.insert(1, 26 sys.path.insert(1,
27 os.path.join(os.path.dirname(__file__), '../../../third_party')) 27 os.path.join(os.path.dirname(__file__), '../../../third_party'))
28 from jinja2 import Template # pylint: disable=F0401 28 from jinja2 import Template # pylint: disable=F0401
29 29
30 30
31 # Represents a line from a R.txt file. 31 # Represents a line from a R.txt file.
32 TextSymbolsEntry = collections.namedtuple('RTextEntry', 32 TextSymbolsEntry = collections.namedtuple('RTextEntry',
33 ('java_type', 'resource_type', 'name', 'value')) 33 ('java_type', 'resource_type', 'name', 'value'))
34 34
35 35
36 def _ParseArgs(args): 36 def ParseArgs(args):
37 """Parses command line options. 37 """Parses command line options.
38 38
39 Returns: 39 Returns:
40 An options object as from optparse.OptionsParser.parse_args() 40 An options object as from optparse.OptionsParser.parse_args()
41 """ 41 """
42 parser = optparse.OptionParser() 42 parser = optparse.OptionParser()
43 build_utils.AddDepfileOption(parser) 43 build_utils.AddDepfileOption(parser)
44 44
45 parser.add_option('--android-sdk', help='path to the Android SDK folder') 45 parser.add_option('--android-sdk', help='path to the Android SDK folder')
46 parser.add_option('--aapt-path', 46 parser.add_option('--aapt-path',
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 help='Include every resource ID in every generated R.java file ' 96 help='Include every resource ID in every generated R.java file '
97 '(ignoring R.txt).') 97 '(ignoring R.txt).')
98 98
99 parser.add_option( 99 parser.add_option(
100 '--all-resources-zip-out', 100 '--all-resources-zip-out',
101 help='Path for output of all resources. This includes resources in ' 101 help='Path for output of all resources. This includes resources in '
102 'dependencies.') 102 'dependencies.')
103 103
104 parser.add_option('--stamp', help='File to touch on success') 104 parser.add_option('--stamp', help='File to touch on success')
105 105
106 options, positional_args = parser.parse_args(args) 106 (options, args) = parser.parse_args(args)
107 107
108 if positional_args: 108 if args:
109 parser.error('No positional arguments should be given.') 109 parser.error('No positional arguments should be given.')
110 110
111 # Check that required options have been provided. 111 # Check that required options have been provided.
112 required_options = ( 112 required_options = (
113 'android_sdk', 113 'android_sdk',
114 'aapt_path', 114 'aapt_path',
115 'android_manifest', 115 'android_manifest',
116 'dependencies_res_zips', 116 'dependencies_res_zips',
117 'resource_dirs', 117 'resource_dirs',
118 'resource_zip_out', 118 'resource_zip_out',
119 ) 119 )
120 build_utils.CheckOptions(options, parser, required=required_options) 120 build_utils.CheckOptions(options, parser, required=required_options)
121 121
122 if (options.R_dir is None) == (options.srcjar_out is None): 122 if (options.R_dir is None) == (options.srcjar_out is None):
123 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.') 123 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.')
124 124
125 options.resource_dirs = build_utils.ParseGypList(options.resource_dirs)
126 options.dependencies_res_zips = (
127 build_utils.ParseGypList(options.dependencies_res_zips))
128
129 # Don't use [] as default value since some script explicitly pass "".
130 if options.extra_res_packages:
131 options.extra_res_packages = (
132 build_utils.ParseGypList(options.extra_res_packages))
133 else:
134 options.extra_res_packages = []
135
136 if options.extra_r_text_files:
137 options.extra_r_text_files = (
138 build_utils.ParseGypList(options.extra_r_text_files))
139 else:
140 options.extra_r_text_files = []
141
142 return options 125 return options
143 126
144 127
145 def CreateExtraRJavaFiles( 128 def CreateExtraRJavaFiles(
146 r_dir, extra_packages, extra_r_text_files, shared_resources, include_all): 129 r_dir, extra_packages, extra_r_text_files, shared_resources, include_all):
147 if include_all: 130 if include_all:
148 java_files = build_utils.FindInDirectory(r_dir, "R.java") 131 java_files = build_utils.FindInDirectory(r_dir, "R.java")
149 if len(java_files) != 1: 132 if len(java_files) != 1:
150 return 133 return
151 r_java_file = java_files[0] 134 r_java_file = java_files[0]
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 # of the form 0, 1, ..., then each subdirectory will be passed to aapt as a 316 # of the form 0, 1, ..., then each subdirectory will be passed to aapt as a
334 # resources directory. While some resources just clobber others (image files, 317 # resources directory. While some resources just clobber others (image files,
335 # etc), other resources (particularly .xml files) need to be more 318 # etc), other resources (particularly .xml files) need to be more
336 # intelligently merged. That merging is left up to aapt. 319 # intelligently merged. That merging is left up to aapt.
337 def path_transform(name, src_zip): 320 def path_transform(name, src_zip):
338 return '%d/%s' % (zip_files.index(src_zip), name) 321 return '%d/%s' % (zip_files.index(src_zip), name)
339 322
340 build_utils.MergeZips(output_path, zip_files, path_transform=path_transform) 323 build_utils.MergeZips(output_path, zip_files, path_transform=path_transform)
341 324
342 325
343 def _OnStaleMd5(options): 326 def main():
327 args = build_utils.ExpandFileArgs(sys.argv[1:])
328
329 options = ParseArgs(args)
344 android_jar = os.path.join(options.android_sdk, 'android.jar') 330 android_jar = os.path.join(options.android_sdk, 'android.jar')
345 aapt = options.aapt_path 331 aapt = options.aapt_path
332
333 input_files = []
334
346 with build_utils.TempDir() as temp_dir: 335 with build_utils.TempDir() as temp_dir:
347 deps_dir = os.path.join(temp_dir, 'deps') 336 deps_dir = os.path.join(temp_dir, 'deps')
348 build_utils.MakeDirectory(deps_dir) 337 build_utils.MakeDirectory(deps_dir)
349 v14_dir = os.path.join(temp_dir, 'v14') 338 v14_dir = os.path.join(temp_dir, 'v14')
350 build_utils.MakeDirectory(v14_dir) 339 build_utils.MakeDirectory(v14_dir)
351 340
352 gen_dir = os.path.join(temp_dir, 'gen') 341 gen_dir = os.path.join(temp_dir, 'gen')
353 build_utils.MakeDirectory(gen_dir) 342 build_utils.MakeDirectory(gen_dir)
354 343
355 input_resource_dirs = options.resource_dirs 344 input_resource_dirs = build_utils.ParseGypList(options.resource_dirs)
356 345
357 if not options.v14_skip: 346 if not options.v14_skip:
358 for resource_dir in input_resource_dirs: 347 for resource_dir in input_resource_dirs:
359 generate_v14_compatible_resources.GenerateV14Resources( 348 generate_v14_compatible_resources.GenerateV14Resources(
360 resource_dir, 349 resource_dir,
361 v14_dir) 350 v14_dir)
362 351
363 dep_zips = options.dependencies_res_zips 352 dep_zips = build_utils.ParseGypList(options.dependencies_res_zips)
353 input_files += dep_zips
364 dep_subdirs = [] 354 dep_subdirs = []
365 for z in dep_zips: 355 for z in dep_zips:
366 subdir = os.path.join(deps_dir, os.path.basename(z)) 356 subdir = os.path.join(deps_dir, os.path.basename(z))
367 if os.path.exists(subdir): 357 if os.path.exists(subdir):
368 raise Exception('Resource zip name conflict: ' + os.path.basename(z)) 358 raise Exception('Resource zip name conflict: ' + os.path.basename(z))
369 build_utils.ExtractAll(z, path=subdir) 359 build_utils.ExtractAll(z, path=subdir)
370 dep_subdirs.append(subdir) 360 dep_subdirs.append(subdir)
371 361
372 # Generate R.java. This R.java contains non-final constants and is used only 362 # Generate R.java. This R.java contains non-final constants and is used only
373 # while compiling the library jar (e.g. chromium_content.jar). When building 363 # while compiling the library jar (e.g. chromium_content.jar). When building
(...skipping 24 matching lines...) Expand all
398 package_command += ['-G', options.proguard_file] 388 package_command += ['-G', options.proguard_file]
399 if options.shared_resources: 389 if options.shared_resources:
400 package_command.append('--shared-lib') 390 package_command.append('--shared-lib')
401 if options.app_as_shared_lib: 391 if options.app_as_shared_lib:
402 package_command.append('--app-as-shared-lib') 392 package_command.append('--app-as-shared-lib')
403 build_utils.CheckOutput(package_command, print_stderr=False) 393 build_utils.CheckOutput(package_command, print_stderr=False)
404 394
405 if options.extra_res_packages: 395 if options.extra_res_packages:
406 CreateExtraRJavaFiles( 396 CreateExtraRJavaFiles(
407 gen_dir, 397 gen_dir,
408 options.extra_res_packages, 398 build_utils.ParseGypList(options.extra_res_packages),
409 options.extra_r_text_files, 399 build_utils.ParseGypList(options.extra_r_text_files),
410 options.shared_resources, 400 options.shared_resources,
411 options.include_all_resources) 401 options.include_all_resources)
412 402
413 # This is the list of directories with resources to put in the final .zip 403 # This is the list of directories with resources to put in the final .zip
414 # file. The order of these is important so that crunched/v14 resources 404 # file. The order of these is important so that crunched/v14 resources
415 # override the normal ones. 405 # override the normal ones.
416 zip_resource_dirs = input_resource_dirs + [v14_dir] 406 zip_resource_dirs = input_resource_dirs + [v14_dir]
417 407
418 base_crunch_dir = os.path.join(temp_dir, 'crunch') 408 base_crunch_dir = os.path.join(temp_dir, 'crunch')
419 409
(...skipping 18 matching lines...) Expand all
438 else: 428 else:
439 build_utils.ZipDir(options.srcjar_out, gen_dir) 429 build_utils.ZipDir(options.srcjar_out, gen_dir)
440 430
441 if options.r_text_out: 431 if options.r_text_out:
442 r_text_path = os.path.join(gen_dir, 'R.txt') 432 r_text_path = os.path.join(gen_dir, 'R.txt')
443 if os.path.exists(r_text_path): 433 if os.path.exists(r_text_path):
444 shutil.copyfile(r_text_path, options.r_text_out) 434 shutil.copyfile(r_text_path, options.r_text_out)
445 else: 435 else:
446 open(options.r_text_out, 'w').close() 436 open(options.r_text_out, 'w').close()
447 437
438 if options.depfile:
439 input_files += build_utils.GetPythonDependencies()
440 build_utils.WriteDepfile(options.depfile, input_files)
448 441
449 def main(args): 442 if options.stamp:
450 args = build_utils.ExpandFileArgs(args) 443 build_utils.Touch(options.stamp)
451 options = _ParseArgs(args)
452
453 possible_output_paths = [
454 options.resource_zip_out,
455 options.all_resources_zip_out,
456 options.r_text_out,
457 options.srcjar_out,
458 ]
459 output_paths = [x for x in possible_output_paths if x]
460
461 # List python deps in input_strings rather than input_paths since the contents
462 # of them does not change what gets written to the depsfile.
463 input_strings = options.extra_res_packages + [
464 options.aapt_path,
465 options.android_sdk,
466 options.app_as_shared_lib,
467 options.custom_package,
468 options.include_all_resources,
469 options.non_constant_id,
470 options.shared_resources,
471 options.v14_skip,
472 ]
473
474 input_paths = [ options.android_manifest ]
475 input_paths.extend(options.dependencies_res_zips)
476 input_paths.extend(options.extra_r_text_files)
477
478 if options.proguard_file:
479 input_paths.append(options.proguard_file)
480
481 for d in options.resource_dirs:
482 for root, _, filenames in os.walk(d):
483 input_paths.extend(os.path.join(root, f) for f in filenames)
484
485 build_utils.CallAndWriteDepfileIfStale(
486 lambda: _OnStaleMd5(options),
487 options,
488 input_paths=input_paths,
489 input_strings=input_strings,
490 output_paths=output_paths,
491 # TODO(agrieve): Remove R_dir when it's no longer used (used only by GYP).
492 force=options.R_dir)
493 444
494 445
495 if __name__ == '__main__': 446 if __name__ == '__main__':
496 main(sys.argv[1:]) 447 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698