| OLD | NEW |
| 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). |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import codecs |
| 13 import optparse | 14 import optparse |
| 14 import os | 15 import os |
| 15 import re | 16 import re |
| 16 import shutil | 17 import shutil |
| 17 import sys | 18 import sys |
| 18 import zipfile | 19 import zipfile |
| 19 | 20 |
| 20 import generate_v14_compatible_resources | 21 import generate_v14_compatible_resources |
| 21 | 22 |
| 22 from util import build_utils | 23 from util import build_utils |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.') | 106 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.') |
| 106 | 107 |
| 107 return options | 108 return options |
| 108 | 109 |
| 109 | 110 |
| 110 def CreateExtraRJavaFiles(r_dir, extra_packages): | 111 def CreateExtraRJavaFiles(r_dir, extra_packages): |
| 111 java_files = build_utils.FindInDirectory(r_dir, "R.java") | 112 java_files = build_utils.FindInDirectory(r_dir, "R.java") |
| 112 if len(java_files) != 1: | 113 if len(java_files) != 1: |
| 113 return | 114 return |
| 114 r_java_file = java_files[0] | 115 r_java_file = java_files[0] |
| 115 r_java_contents = open(r_java_file).read() | 116 r_java_contents = codecs.open(r_java_file, encoding='utf-8').read() |
| 116 | 117 |
| 117 for package in extra_packages: | 118 for package in extra_packages: |
| 118 package_r_java_dir = os.path.join(r_dir, *package.split('.')) | 119 package_r_java_dir = os.path.join(r_dir, *package.split('.')) |
| 119 build_utils.MakeDirectory(package_r_java_dir) | 120 build_utils.MakeDirectory(package_r_java_dir) |
| 120 package_r_java_path = os.path.join(package_r_java_dir, 'R.java') | 121 package_r_java_path = os.path.join(package_r_java_dir, 'R.java') |
| 121 open(package_r_java_path, 'w').write( | 122 new_r_java = re.sub(r'package [.\w]*;', u'package %s;' % package, |
| 122 re.sub(r'package [.\w]*;', 'package %s;' % package, r_java_contents)) | 123 r_java_contents) |
| 124 codecs.open(package_r_java_path, 'w', encoding='utf-8').write(new_r_java) |
| 123 # TODO(cjhopman): These extra package's R.java files should be filtered to | 125 # TODO(cjhopman): These extra package's R.java files should be filtered to |
| 124 # only contain the resources listed in their R.txt files. At this point, we | 126 # only contain the resources listed in their R.txt files. At this point, we |
| 125 # have already compiled those other libraries, so doing this would only | 127 # have already compiled those other libraries, so doing this would only |
| 126 # affect how the code in this .apk target could refer to the resources. | 128 # affect how the code in this .apk target could refer to the resources. |
| 127 | 129 |
| 128 | 130 |
| 129 def CrunchDirectory(aapt, input_dir, output_dir): | 131 def CrunchDirectory(aapt, input_dir, output_dir): |
| 130 """Crunches the images in input_dir and its subdirectories into output_dir. | 132 """Crunches the images in input_dir and its subdirectories into output_dir. |
| 131 | 133 |
| 132 If an image is already optimized, crunching often increases image size. In | 134 If an image is already optimized, crunching often increases image size. In |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 if options.depfile: | 313 if options.depfile: |
| 312 input_files += build_utils.GetPythonDependencies() | 314 input_files += build_utils.GetPythonDependencies() |
| 313 build_utils.WriteDepfile(options.depfile, input_files) | 315 build_utils.WriteDepfile(options.depfile, input_files) |
| 314 | 316 |
| 315 if options.stamp: | 317 if options.stamp: |
| 316 build_utils.Touch(options.stamp) | 318 build_utils.Touch(options.stamp) |
| 317 | 319 |
| 318 | 320 |
| 319 if __name__ == '__main__': | 321 if __name__ == '__main__': |
| 320 main() | 322 main() |
| OLD | NEW |