Chromium Code Reviews| Index: build/android/gyp/process_resources.py |
| diff --git a/build/android/gyp/process_resources.py b/build/android/gyp/process_resources.py |
| index bf1317554e798209838650852bce3a8e90fcbea6..624ac4151ca412985711ec7e7f0d11d561fc1f06 100755 |
| --- a/build/android/gyp/process_resources.py |
| +++ b/build/android/gyp/process_resources.py |
| @@ -1,17 +1,20 @@ |
| #!/usr/bin/env python |
| # |
| -# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +# Copyright 2012 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| """Process Android library resources to generate R.java and crunched images.""" |
| +import multiprocessing.pool |
|
cjhopman
2013/12/06 17:28:23
unused?
newt (away)
2013/12/06 19:22:51
Done.
|
| import optparse |
| import os |
| import shlex |
| import shutil |
| +import tempfile |
| from util import build_utils |
| +import mirror_images |
| def ParseArgs(): |
| """Parses command line options. |
| @@ -26,10 +29,15 @@ def ParseArgs(): |
| parser.add_option('--R-dir', help='directory to hold generated R.java') |
| parser.add_option('--res-dirs', |
| help='directories containing resources to be packaged') |
| - parser.add_option('--crunch-input-dir', |
| - help='directory containing images to be crunched') |
| + parser.add_option('--image-input-dir', help='directory containing images to ' |
| + 'be crunched and possibly mirrored.') |
| parser.add_option('--crunch-output-dir', |
| help='directory to hold crunched resources') |
| + parser.add_option('--mirror-config', help='config file specifying which ' |
| + 'images should be mirrored. Images will be mirrored only ' |
| + 'if this is provided.') |
| + parser.add_option('--mirror-output-dir', |
| + help='directory where mirrored images should be saved') |
| parser.add_option('--non-constant-id', action='store_true') |
| parser.add_option('--custom-package', help='Java package for R.java') |
| parser.add_option('--android-manifest', help='AndroidManifest.xml path') |
| @@ -43,9 +51,13 @@ def ParseArgs(): |
| if args: |
| parser.error('No positional arguments should be given.') |
| + if (options.mirror_config is None) != (options.mirror_output_dir is None): |
| + parser.error('--mirror-config and --mirror-output-dir must both be present ' |
| + 'or neither present.') |
| + |
| # Check that required options have been provided. |
| required_options = ('android_sdk', 'android_sdk_tools', 'R_dir', |
| - 'res_dirs', 'crunch_input_dir', 'crunch_output_dir') |
| + 'res_dirs', 'image_input_dir', 'crunch_output_dir') |
| build_utils.CheckOptions(options, parser, required=required_options) |
| return options |
| @@ -77,6 +89,15 @@ def MoveImagesToNonMdpiFolders(res_root): |
| shutil.move(src_file, dst_file) |
| +def CrunchImages(aapt, input_res_dir, output_res_dir): |
| + build_utils.MakeDirectory(output_res_dir) |
| + aapt_cmd = [aapt, |
| + 'crunch', |
| + '-S', input_res_dir, |
| + '-C', output_res_dir] |
| + build_utils.CheckOutput(aapt_cmd, fail_if_stderr=True) |
| + |
| + |
| def main(): |
| options = ParseArgs() |
| android_jar = os.path.join(options.android_sdk, 'android.jar') |
| @@ -106,16 +127,22 @@ def main(): |
| package_command += ['--custom-package', options.custom_package] |
| build_utils.CheckOutput(package_command) |
| + # Mirror images if requested. |
| + if options.mirror_config: |
| + # Mirrored images are generated into a temp dir. Once these images are |
| + # crunched, they'll go in the desired mirror output dir. |
| + mirrored_uncrunched_dir = tempfile.mkdtemp() |
| + try: |
| + mirror_images.main(['--config', options.mirror_config, |
| + '--input-res-dir', options.image_input_dir, |
| + '--output-res-dir', mirrored_uncrunched_dir]) |
| + CrunchImages(aapt, mirrored_uncrunched_dir, options.mirror_output_dir) |
| + finally: |
| + shutil.rmtree(mirrored_uncrunched_dir) |
| + |
| # Crunch image resources. This shrinks png files and is necessary for 9-patch |
| # images to display correctly. |
| - build_utils.MakeDirectory(options.crunch_output_dir) |
| - aapt_cmd = [aapt, |
| - 'crunch', |
| - '-S', options.crunch_input_dir, |
| - '-C', options.crunch_output_dir] |
| - build_utils.CheckOutput(aapt_cmd, fail_if_stderr=True) |
| - |
| - MoveImagesToNonMdpiFolders(options.crunch_output_dir) |
| + CrunchImages(aapt, options.image_input_dir, options.crunch_output_dir) |
|
newt (away)
2013/12/05 19:33:22
Chris, do we ever delete the res_crunched director
cjhopman
2013/12/06 17:28:23
I don't think we do.
I think the correct approach
|
| if options.stamp: |
| build_utils.Touch(options.stamp) |