Chromium Code Reviews| 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 library resources to generate R.java and crunched images.""" |
| 8 | 8 |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| 11 import shlex | 11 import shlex |
| 12 import shutil | |
| 12 | 13 |
| 13 from util import build_utils | 14 from util import build_utils |
| 14 | 15 |
| 15 def ParseArgs(): | 16 def ParseArgs(): |
| 16 """Parses command line options. | 17 """Parses command line options. |
| 17 | 18 |
| 18 Returns: | 19 Returns: |
| 19 An options object as from optparse.OptionsParser.parse_args() | 20 An options object as from optparse.OptionsParser.parse_args() |
| 20 """ | 21 """ |
| 21 parser = optparse.OptionParser() | 22 parser = optparse.OptionParser() |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 43 parser.error('No positional arguments should be given.') | 44 parser.error('No positional arguments should be given.') |
| 44 | 45 |
| 45 # Check that required options have been provided. | 46 # Check that required options have been provided. |
| 46 required_options = ('android_sdk', 'android_sdk_tools', 'R_dir', | 47 required_options = ('android_sdk', 'android_sdk_tools', 'R_dir', |
| 47 'res_dirs', 'crunch_input_dir', 'crunch_output_dir') | 48 'res_dirs', 'crunch_input_dir', 'crunch_output_dir') |
| 48 build_utils.CheckOptions(options, parser, required=required_options) | 49 build_utils.CheckOptions(options, parser, required=required_options) |
| 49 | 50 |
| 50 return options | 51 return options |
| 51 | 52 |
| 52 | 53 |
| 54 def MoveImagesToNonMdpiFolders(res_root): | |
| 55 """Move images from drawable-*-mdpi-* folders to drawable-* folders. | |
| 56 | |
| 57 Why? http://crbug.com/289843 | |
| 58 """ | |
| 59 for src_dir_name in os.listdir(res_root): | |
| 60 src_components = src_dir_name.split('-') | |
| 61 if src_components[0] != 'drawable' or 'mdpi' not in src_components: | |
| 62 continue | |
| 63 src_dir = os.path.join(res_root, src_dir_name) | |
| 64 if not os.path.isdir(src_dir): | |
| 65 continue | |
| 66 dst_components = src_components[:] | |
| 67 del dst_components[dst_components.index('mdpi')] | |
|
cjhopman
2013/09/16 16:06:24
Maybe dst_components = [c for c in src_components
| |
| 68 dst_dir_name = '-'.join(dst_components) | |
| 69 dst_dir = os.path.join(res_root, dst_dir_name) | |
| 70 build_utils.MakeDirectory(dst_dir) | |
| 71 for src_file_name in os.listdir(src_dir): | |
| 72 if not src_file_name.endswith('.png'): | |
| 73 continue | |
| 74 src_file = os.path.join(src_dir, src_file_name) | |
| 75 dst_file = os.path.join(dst_dir, src_file_name) | |
| 76 assert not os.path.lexists(dst_file) | |
| 77 shutil.move(src_file, dst_file) | |
| 78 | |
| 79 | |
| 53 def main(): | 80 def main(): |
| 54 options = ParseArgs() | 81 options = ParseArgs() |
| 55 android_jar = os.path.join(options.android_sdk, 'android.jar') | 82 android_jar = os.path.join(options.android_sdk, 'android.jar') |
| 56 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 83 aapt = os.path.join(options.android_sdk_tools, 'aapt') |
| 57 | 84 |
| 58 build_utils.MakeDirectory(options.R_dir) | 85 build_utils.MakeDirectory(options.R_dir) |
| 59 | 86 |
| 60 # Generate R.java. This R.java contains non-final constants and is used only | 87 # Generate R.java. This R.java contains non-final constants and is used only |
| 61 # while compiling the library jar (e.g. chromium_content.jar). When building | 88 # while compiling the library jar (e.g. chromium_content.jar). When building |
| 62 # an apk, a new R.java file with the correct resource -> ID mappings will be | 89 # an apk, a new R.java file with the correct resource -> ID mappings will be |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 75 package_command += ['-S', res_dir] | 102 package_command += ['-S', res_dir] |
| 76 if options.non_constant_id: | 103 if options.non_constant_id: |
| 77 package_command.append('--non-constant-id') | 104 package_command.append('--non-constant-id') |
| 78 if options.custom_package: | 105 if options.custom_package: |
| 79 package_command += ['--custom-package', options.custom_package] | 106 package_command += ['--custom-package', options.custom_package] |
| 80 build_utils.CheckCallDie(package_command) | 107 build_utils.CheckCallDie(package_command) |
| 81 | 108 |
| 82 # Crunch image resources. This shrinks png files and is necessary for 9-patch | 109 # Crunch image resources. This shrinks png files and is necessary for 9-patch |
| 83 # images to display correctly. | 110 # images to display correctly. |
| 84 build_utils.MakeDirectory(options.crunch_output_dir) | 111 build_utils.MakeDirectory(options.crunch_output_dir) |
| 85 | |
| 86 aapt_cmd = [aapt, | 112 aapt_cmd = [aapt, |
| 87 'crunch', | 113 'crunch', |
| 88 '-S', options.crunch_input_dir, | 114 '-S', options.crunch_input_dir, |
| 89 '-C', options.crunch_output_dir] | 115 '-C', options.crunch_output_dir] |
| 90 build_utils.CheckCallDie(aapt_cmd, suppress_output=True) | 116 build_utils.CheckCallDie(aapt_cmd, suppress_output=True) |
| 91 | 117 |
| 118 MoveImagesToNonMdpiFolders(options.crunch_output_dir) | |
| 119 | |
| 92 if options.stamp: | 120 if options.stamp: |
| 93 build_utils.Touch(options.stamp) | 121 build_utils.Touch(options.stamp) |
| 94 | 122 |
| 95 | 123 |
| 96 if __name__ == '__main__': | 124 if __name__ == '__main__': |
| 97 main() | 125 main() |
| OLD | NEW |