| 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 optparse | 13 import optparse |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import shutil | 16 import shutil |
| 17 import sys | 17 import sys |
| 18 import zipfile | 18 import zipfile |
| 19 | 19 |
| 20 import generate_v14_compatible_resources | 20 import generate_v14_compatible_resources |
| 21 | 21 |
| 22 from util import build_utils | 22 from util import build_utils |
| 23 | 23 |
| 24 |
| 24 def ParseArgs(args): | 25 def ParseArgs(args): |
| 25 """Parses command line options. | 26 """Parses command line options. |
| 26 | 27 |
| 27 Returns: | 28 Returns: |
| 28 An options object as from optparse.OptionsParser.parse_args() | 29 An options object as from optparse.OptionsParser.parse_args() |
| 29 """ | 30 """ |
| 30 parser = optparse.OptionParser() | 31 parser = optparse.OptionParser() |
| 31 build_utils.AddDepfileOption(parser) | 32 build_utils.AddDepfileOption(parser) |
| 32 | 33 |
| 33 parser.add_option('--android-sdk', help='path to the Android SDK folder') | 34 parser.add_option('--android-sdk', help='path to the Android SDK folder') |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 # an apk, a new R.java file with the correct resource -> ID mappings will be | 214 # an apk, a new R.java file with the correct resource -> ID mappings will be |
| 214 # generated by merging the resources from all libraries and the main apk | 215 # generated by merging the resources from all libraries and the main apk |
| 215 # project. | 216 # project. |
| 216 package_command = [aapt, | 217 package_command = [aapt, |
| 217 'package', | 218 'package', |
| 218 '-m', | 219 '-m', |
| 219 '-M', options.android_manifest, | 220 '-M', options.android_manifest, |
| 220 '--auto-add-overlay', | 221 '--auto-add-overlay', |
| 221 '-I', android_jar, | 222 '-I', android_jar, |
| 222 '--output-text-symbols', gen_dir, | 223 '--output-text-symbols', gen_dir, |
| 223 '-J', gen_dir] | 224 '-J', gen_dir, |
| 225 '--ignore-assets', build_utils.AAPT_IGNORE_PATTERN] |
| 224 | 226 |
| 225 for d in input_resource_dirs: | 227 for d in input_resource_dirs: |
| 226 package_command += ['-S', d] | 228 package_command += ['-S', d] |
| 227 | 229 |
| 228 for d in dep_subdirs: | 230 for d in dep_subdirs: |
| 229 package_command += ['-S', d] | 231 package_command += ['-S', d] |
| 230 | 232 |
| 231 if options.non_constant_id: | 233 if options.non_constant_id: |
| 232 package_command.append('--non-constant-id') | 234 package_command.append('--non-constant-id') |
| 233 if options.custom_package: | 235 if options.custom_package: |
| (...skipping 17 matching lines...) Expand all Loading... |
| 251 # Crunch image resources. This shrinks png files and is necessary for | 253 # Crunch image resources. This shrinks png files and is necessary for |
| 252 # 9-patch images to display correctly. 'aapt crunch' accepts only a single | 254 # 9-patch images to display correctly. 'aapt crunch' accepts only a single |
| 253 # directory at a time and deletes everything in the output directory. | 255 # directory at a time and deletes everything in the output directory. |
| 254 for idx, d in enumerate(input_resource_dirs): | 256 for idx, d in enumerate(input_resource_dirs): |
| 255 crunch_dir = os.path.join(base_crunch_dir, str(idx)) | 257 crunch_dir = os.path.join(base_crunch_dir, str(idx)) |
| 256 build_utils.MakeDirectory(crunch_dir) | 258 build_utils.MakeDirectory(crunch_dir) |
| 257 zip_resource_dirs.append(crunch_dir) | 259 zip_resource_dirs.append(crunch_dir) |
| 258 aapt_cmd = [aapt, | 260 aapt_cmd = [aapt, |
| 259 'crunch', | 261 'crunch', |
| 260 '-C', crunch_dir, | 262 '-C', crunch_dir, |
| 261 '-S', d] | 263 '-S', d, |
| 264 '--ignore-assets', build_utils.AAPT_IGNORE_PATTERN] |
| 262 build_utils.CheckOutput(aapt_cmd, stderr_filter=FilterCrunchStderr, | 265 build_utils.CheckOutput(aapt_cmd, stderr_filter=FilterCrunchStderr, |
| 263 fail_func=DidCrunchFail) | 266 fail_func=DidCrunchFail) |
| 264 | 267 |
| 265 ZipResources(zip_resource_dirs, options.resource_zip_out) | 268 ZipResources(zip_resource_dirs, options.resource_zip_out) |
| 266 | 269 |
| 267 if options.all_resources_zip_out: | 270 if options.all_resources_zip_out: |
| 268 CombineZips([options.resource_zip_out] + dep_zips, | 271 CombineZips([options.resource_zip_out] + dep_zips, |
| 269 options.all_resources_zip_out) | 272 options.all_resources_zip_out) |
| 270 | 273 |
| 271 if options.R_dir: | 274 if options.R_dir: |
| 272 build_utils.DeleteDirectory(options.R_dir) | 275 build_utils.DeleteDirectory(options.R_dir) |
| 273 shutil.copytree(gen_dir, options.R_dir) | 276 shutil.copytree(gen_dir, options.R_dir) |
| 274 else: | 277 else: |
| 275 build_utils.ZipDir(options.srcjar_out, gen_dir) | 278 build_utils.ZipDir(options.srcjar_out, gen_dir) |
| 276 | 279 |
| 277 if options.depfile: | 280 if options.depfile: |
| 278 input_files += build_utils.GetPythonDependencies() | 281 input_files += build_utils.GetPythonDependencies() |
| 279 build_utils.WriteDepfile(options.depfile, input_files) | 282 build_utils.WriteDepfile(options.depfile, input_files) |
| 280 | 283 |
| 281 if options.stamp: | 284 if options.stamp: |
| 282 build_utils.Touch(options.stamp) | 285 build_utils.Touch(options.stamp) |
| 283 | 286 |
| 284 | 287 |
| 285 if __name__ == '__main__': | 288 if __name__ == '__main__': |
| 286 main() | 289 main() |
| OLD | NEW |