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 library resources to generate R.java and crunched images.""" |
8 | |
9 This will crunch images and generate v14 compatible resources | |
10 (see generate_v14_compatible_resources.py). | |
11 """ | |
12 | 8 |
13 import optparse | 9 import optparse |
14 import os | 10 import os |
15 import re | 11 import re |
16 import shlex | 12 import shlex |
17 import shutil | 13 import shutil |
18 | 14 |
19 import generate_v14_compatible_resources | |
20 | |
21 from util import build_utils | 15 from util import build_utils |
22 | 16 |
23 def ParseArgs(): | 17 def ParseArgs(): |
24 """Parses command line options. | 18 """Parses command line options. |
25 | 19 |
26 Returns: | 20 Returns: |
27 An options object as from optparse.OptionsParser.parse_args() | 21 An options object as from optparse.OptionsParser.parse_args() |
28 """ | 22 """ |
29 parser = optparse.OptionParser() | 23 parser = optparse.OptionParser() |
30 parser.add_option('--android-sdk', help='path to the Android SDK folder') | 24 parser.add_option('--android-sdk', help='path to the Android SDK folder') |
31 parser.add_option('--android-sdk-tools', | 25 parser.add_option('--android-sdk-tools', |
32 help='path to the Android SDK build tools folder') | 26 help='path to the Android SDK build tools folder') |
33 parser.add_option('--R-dir', help='directory to hold generated R.java') | 27 parser.add_option('--R-dir', help='directory to hold generated R.java') |
34 parser.add_option('--dependencies-res-dirs', | 28 parser.add_option('--dependencies-res-dirs', |
35 help='directories containing resources to be packaged') | 29 help='directories containing resources to be packaged') |
36 parser.add_option('--resource-dir', | 30 parser.add_option('--resource-dir', |
37 help='directory containing this target\'s resources.') | 31 help='directory containing this target\'s resources.') |
38 parser.add_option('--crunch-output-dir', | 32 parser.add_option('--crunch-output-dir', |
39 help='directory to hold crunched resources') | 33 help='directory to hold crunched resources') |
40 parser.add_option('--non-constant-id', action='store_true') | 34 parser.add_option('--non-constant-id', action='store_true') |
41 parser.add_option('--custom-package', help='Java package for R.java') | 35 parser.add_option('--custom-package', help='Java package for R.java') |
42 parser.add_option('--android-manifest', help='AndroidManifest.xml path') | 36 parser.add_option('--android-manifest', help='AndroidManifest.xml path') |
43 parser.add_option('--proguard-file', | 37 parser.add_option('--proguard-file', |
44 help='Path to proguard.txt generated file') | 38 help='Path to proguard.txt generated file') |
45 | 39 parser.add_option('--stamp', help='File to touch on success') |
46 parser.add_option('--res-v14-compatibility-dir', | |
47 help='output directory into which ' | |
48 'v14 compatible resources will be generated') | |
49 parser.add_option( | |
50 '--v14-verify-only', | |
51 action='store_true', | |
52 help='Do not generate v14 resources. Instead, just verify that the ' | |
53 'resources are already compatible with v14, i.e. they don\'t use ' | |
54 'attributes that cause crashes on certain devices.') | |
55 | 40 |
56 parser.add_option( | 41 parser.add_option( |
57 '--extra-res-packages', | 42 '--extra-res-packages', |
58 help='Additional package names to generate R.java files for') | 43 help='Additional package names to generate R.java files for') |
59 parser.add_option( | 44 parser.add_option( |
60 '--extra-r-text-files', | 45 '--extra-r-text-files', |
61 help='For each additional package, the R.txt file should contain a ' | 46 help='For each additional package, the R.txt file should contain a ' |
62 'list of resources to be included in the R.java file in the format ' | 47 'list of resources to be included in the R.java file in the format ' |
63 'generated by aapt') | 48 'generated by aapt') |
64 | 49 |
65 parser.add_option('--stamp', help='File to touch on success') | |
66 | |
67 (options, args) = parser.parse_args() | 50 (options, args) = parser.parse_args() |
68 | 51 |
69 if args: | 52 if args: |
70 parser.error('No positional arguments should be given.') | 53 parser.error('No positional arguments should be given.') |
71 | 54 |
72 # Check that required options have been provided. | 55 # Check that required options have been provided. |
73 required_options = ( | 56 required_options = ( |
74 'android_sdk', | 57 'android_sdk', |
75 'android_sdk_tools', | 58 'android_sdk_tools', |
76 'android_manifest', | 59 'android_manifest', |
77 'dependencies_res_dirs', | 60 'dependencies_res_dirs', |
78 'resource_dir', | 61 'resource_dir', |
79 'crunch_output_dir', | 62 'crunch_output_dir', |
80 'R_dir', | 63 'R_dir', |
81 'res_v14_compatibility_dir', | |
82 ) | 64 ) |
83 build_utils.CheckOptions(options, parser, required=required_options) | 65 build_utils.CheckOptions(options, parser, required=required_options) |
84 | 66 |
85 return options | 67 return options |
86 | 68 |
87 | 69 |
88 def CreateExtraRJavaFiles( | 70 def CreateExtraRJavaFiles( |
89 r_dir, extra_packages, extra_r_text_files): | 71 r_dir, extra_packages, extra_r_text_files): |
90 if len(extra_packages) != len(extra_r_text_files): | 72 if len(extra_packages) != len(extra_r_text_files): |
91 raise Exception('--extra-res-packages and --extra-r-text-files' | 73 raise Exception('--extra-res-packages and --extra-r-text-files' |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 135 |
154 | 136 |
155 def main(): | 137 def main(): |
156 options = ParseArgs() | 138 options = ParseArgs() |
157 android_jar = os.path.join(options.android_sdk, 'android.jar') | 139 android_jar = os.path.join(options.android_sdk, 'android.jar') |
158 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 140 aapt = os.path.join(options.android_sdk_tools, 'aapt') |
159 | 141 |
160 build_utils.DeleteDirectory(options.R_dir) | 142 build_utils.DeleteDirectory(options.R_dir) |
161 build_utils.MakeDirectory(options.R_dir) | 143 build_utils.MakeDirectory(options.R_dir) |
162 | 144 |
163 generate_v14_compatible_resources.GenerateV14Resources( | |
164 options.resource_dir, | |
165 options.res_v14_compatibility_dir, | |
166 options.v14_verify_only) | |
167 | |
168 # Generate R.java. This R.java contains non-final constants and is used only | 145 # Generate R.java. This R.java contains non-final constants and is used only |
169 # while compiling the library jar (e.g. chromium_content.jar). When building | 146 # while compiling the library jar (e.g. chromium_content.jar). When building |
170 # an apk, a new R.java file with the correct resource -> ID mappings will be | 147 # an apk, a new R.java file with the correct resource -> ID mappings will be |
171 # generated by merging the resources from all libraries and the main apk | 148 # generated by merging the resources from all libraries and the main apk |
172 # project. | 149 # project. |
173 package_command = [aapt, | 150 package_command = [aapt, |
174 'package', | 151 'package', |
175 '-m', | 152 '-m', |
176 '-M', options.android_manifest, | 153 '-M', options.android_manifest, |
177 '--auto-add-overlay', | 154 '--auto-add-overlay', |
(...skipping 30 matching lines...) Expand all Loading... |
208 build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail) | 185 build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail) |
209 | 186 |
210 MoveImagesToNonMdpiFolders(options.crunch_output_dir) | 187 MoveImagesToNonMdpiFolders(options.crunch_output_dir) |
211 | 188 |
212 if options.stamp: | 189 if options.stamp: |
213 build_utils.Touch(options.stamp) | 190 build_utils.Touch(options.stamp) |
214 | 191 |
215 | 192 |
216 if __name__ == '__main__': | 193 if __name__ == '__main__': |
217 main() | 194 main() |
OLD | NEW |