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