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