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 sys | |
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() |
22 parser.add_option('--android-sdk', help='path to the Android SDK folder') | 23 parser.add_option('--android-sdk', help='path to the Android SDK folder') |
23 parser.add_option('--android-sdk-tools', | 24 parser.add_option('--android-sdk-tools', |
24 help='path to the Android SDK platform tools folder') | 25 help='path to the Android SDK platform tools folder') |
25 parser.add_option('--R-dir', help='directory to hold generated R.java') | 26 parser.add_option('--R-dir', help='directory to hold generated R.java') |
26 parser.add_option('--res-dirs', | 27 parser.add_option('--res-dirs', |
27 help='directories containing resources to be packaged') | 28 help='directories containing resources to be packaged') |
28 parser.add_option('--crunch-input-dir', | 29 parser.add_option('--crunch-and-mirror-input-dir', |
29 help='directory containing images to be crunched') | 30 help='directory containing images to be crunched and' \ |
newt (away)
2013/04/25 00:47:58
don't need \
http://google-styleguide.googlecode.
Kibeom Kim (inactive)
2013/04/25 01:49:35
Done.
| |
31 'LTR resources to be mirrored') | |
30 parser.add_option('--crunch-output-dir', | 32 parser.add_option('--crunch-output-dir', |
31 help='directory to hold crunched resources') | 33 help='directory to hold crunched resources') |
34 parser.add_option('--mirror-output-dir', | |
35 help='directory to hold mirrored, RTL resources') | |
32 parser.add_option('--non-constant-id', action='store_true') | 36 parser.add_option('--non-constant-id', action='store_true') |
33 parser.add_option('--custom-package', help='Java package for R.java') | 37 parser.add_option('--custom-package', help='Java package for R.java') |
34 parser.add_option('--android-manifest', help='AndroidManifest.xml path') | 38 parser.add_option('--android-manifest', help='AndroidManifest.xml path') |
35 parser.add_option('--stamp', help='File to touch on success') | 39 parser.add_option('--stamp', help='File to touch on success') |
36 | 40 |
37 # This is part of a temporary fix for crbug.com/177552. | 41 # This is part of a temporary fix for crbug.com/177552. |
38 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja. | 42 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja. |
39 parser.add_option('--ignore', help='this argument is ignored') | 43 parser.add_option('--ignore', help='this argument is ignored') |
40 (options, args) = parser.parse_args() | 44 (options, args) = parser.parse_args() |
41 | 45 |
42 if args: | 46 if args: |
43 parser.error('No positional arguments should be given.') | 47 parser.error('No positional arguments should be given.') |
44 | 48 |
45 # Check that required options have been provided. | 49 # Check that required options have been provided. |
46 required_options = ('android_sdk', 'android_sdk_tools', 'R_dir', 'res_dirs', | 50 required_options = ('android_sdk', 'android_sdk_tools', 'R_dir', 'res_dirs', |
47 'crunch_input_dir', 'crunch_output_dir') | 51 'crunch_and_mirror_input_dir', 'crunch_output_dir', |
52 'mirror_output_dir') | |
48 build_utils.CheckOptions(options, parser, required=required_options) | 53 build_utils.CheckOptions(options, parser, required=required_options) |
49 | 54 |
50 return options | 55 return options |
51 | 56 |
52 | 57 |
53 def main(): | 58 def main(): |
54 options = ParseArgs() | 59 options = ParseArgs() |
55 android_jar = os.path.join(options.android_sdk, 'android.jar') | 60 android_jar = os.path.join(options.android_sdk, 'android.jar') |
56 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 61 aapt = os.path.join(options.android_sdk_tools, 'aapt') |
57 | 62 |
(...skipping 20 matching lines...) Expand all Loading... | |
78 if options.custom_package: | 83 if options.custom_package: |
79 package_command += ['--custom-package', options.custom_package] | 84 package_command += ['--custom-package', options.custom_package] |
80 build_utils.CheckCallDie(package_command) | 85 build_utils.CheckCallDie(package_command) |
81 | 86 |
82 # Crunch image resources. This shrinks png files and is necessary for 9-patch | 87 # Crunch image resources. This shrinks png files and is necessary for 9-patch |
83 # images to display correctly. | 88 # images to display correctly. |
84 build_utils.MakeDirectory(options.crunch_output_dir) | 89 build_utils.MakeDirectory(options.crunch_output_dir) |
85 | 90 |
86 aapt_cmd = [aapt, | 91 aapt_cmd = [aapt, |
87 'crunch', | 92 'crunch', |
88 '-S', options.crunch_input_dir, | 93 '-S', options.crunch_and_mirror_input_dir, |
89 '-C', options.crunch_output_dir] | 94 '-C', options.crunch_output_dir] |
90 build_utils.CheckCallDie(aapt_cmd, suppress_output=True) | 95 build_utils.CheckCallDie(aapt_cmd, suppress_output=True) |
91 | 96 |
97 # Generate RTL versions of layouts and other XML resources. | |
98 build_utils.MakeDirectory(options.mirror_output_dir) | |
99 mirror_cmd = [sys.executable, | |
newt (away)
2013/04/25 00:47:58
Chris may know the best way to do this
cjhopman
2013/04/25 01:02:06
Haven't looked at the rest of the change yet, but
Kibeom Kim (inactive)
2013/04/25 01:49:35
OK I'll try to make this a separate gyp action aft
| |
100 os.path.join(os.path.dirname(__file__), 'mirror_resources.py'), | |
101 '--res-dir', options.crunch_and_mirror_input_dir, | |
102 '--res-mirrored-dir', options.mirror_output_dir] | |
103 build_utils.CheckCallDie(mirror_cmd, suppress_output=True) | |
104 | |
105 | |
92 if options.stamp: | 106 if options.stamp: |
93 build_utils.Touch(options.stamp) | 107 build_utils.Touch(options.stamp) |
94 | 108 |
95 | 109 |
96 if __name__ == '__main__': | 110 if __name__ == '__main__': |
97 main() | 111 main() |
OLD | NEW |