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). |
(...skipping 20 matching lines...) Expand all Loading... |
31 def ParseArgs(args): | 31 def ParseArgs(args): |
32 """Parses command line options. | 32 """Parses command line options. |
33 | 33 |
34 Returns: | 34 Returns: |
35 An options object as from optparse.OptionsParser.parse_args() | 35 An options object as from optparse.OptionsParser.parse_args() |
36 """ | 36 """ |
37 parser = optparse.OptionParser() | 37 parser = optparse.OptionParser() |
38 build_utils.AddDepfileOption(parser) | 38 build_utils.AddDepfileOption(parser) |
39 | 39 |
40 parser.add_option('--android-sdk', help='path to the Android SDK folder') | 40 parser.add_option('--android-sdk', help='path to the Android SDK folder') |
41 parser.add_option('--android-sdk-tools', | 41 parser.add_option('--aapt-path', |
42 help='path to the Android SDK build tools folder') | 42 help='path to the Android aapt tool') |
43 parser.add_option('--non-constant-id', action='store_true') | 43 parser.add_option('--non-constant-id', action='store_true') |
44 | 44 |
45 parser.add_option('--android-manifest', help='AndroidManifest.xml path') | 45 parser.add_option('--android-manifest', help='AndroidManifest.xml path') |
46 parser.add_option('--custom-package', help='Java package for R.java') | 46 parser.add_option('--custom-package', help='Java package for R.java') |
47 parser.add_option( | 47 parser.add_option( |
48 '--shared-resources', | 48 '--shared-resources', |
49 action='store_true', | 49 action='store_true', |
50 help='Make a resource package that can be loaded by a different' | 50 help='Make a resource package that can be loaded by a different' |
51 'application at runtime to access the package\'s resources.') | 51 'application at runtime to access the package\'s resources.') |
52 | 52 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 parser.add_option('--stamp', help='File to touch on success') | 95 parser.add_option('--stamp', help='File to touch on success') |
96 | 96 |
97 (options, args) = parser.parse_args(args) | 97 (options, args) = parser.parse_args(args) |
98 | 98 |
99 if args: | 99 if args: |
100 parser.error('No positional arguments should be given.') | 100 parser.error('No positional arguments should be given.') |
101 | 101 |
102 # Check that required options have been provided. | 102 # Check that required options have been provided. |
103 required_options = ( | 103 required_options = ( |
104 'android_sdk', | 104 'android_sdk', |
105 'android_sdk_tools', | 105 'aapt_path', |
106 'android_manifest', | 106 'android_manifest', |
107 'dependencies_res_zips', | 107 'dependencies_res_zips', |
108 'resource_dirs', | 108 'resource_dirs', |
109 'resource_zip_out', | 109 'resource_zip_out', |
110 ) | 110 ) |
111 build_utils.CheckOptions(options, parser, required=required_options) | 111 build_utils.CheckOptions(options, parser, required=required_options) |
112 | 112 |
113 if (options.R_dir is None) == (options.srcjar_out is None): | 113 if (options.R_dir is None) == (options.srcjar_out is None): |
114 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.') | 114 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.') |
115 | 115 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 for name in inzip.namelist(): | 296 for name in inzip.namelist(): |
297 new_name = '%d/%s' % (i, name) | 297 new_name = '%d/%s' % (i, name) |
298 outzip.writestr(new_name, inzip.read(name)) | 298 outzip.writestr(new_name, inzip.read(name)) |
299 | 299 |
300 | 300 |
301 def main(): | 301 def main(): |
302 args = build_utils.ExpandFileArgs(sys.argv[1:]) | 302 args = build_utils.ExpandFileArgs(sys.argv[1:]) |
303 | 303 |
304 options = ParseArgs(args) | 304 options = ParseArgs(args) |
305 android_jar = os.path.join(options.android_sdk, 'android.jar') | 305 android_jar = os.path.join(options.android_sdk, 'android.jar') |
306 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 306 aapt = options.aapt_path |
307 | 307 |
308 input_files = [] | 308 input_files = [] |
309 | 309 |
310 with build_utils.TempDir() as temp_dir: | 310 with build_utils.TempDir() as temp_dir: |
311 deps_dir = os.path.join(temp_dir, 'deps') | 311 deps_dir = os.path.join(temp_dir, 'deps') |
312 build_utils.MakeDirectory(deps_dir) | 312 build_utils.MakeDirectory(deps_dir) |
313 v14_dir = os.path.join(temp_dir, 'v14') | 313 v14_dir = os.path.join(temp_dir, 'v14') |
314 build_utils.MakeDirectory(v14_dir) | 314 build_utils.MakeDirectory(v14_dir) |
315 | 315 |
316 gen_dir = os.path.join(temp_dir, 'gen') | 316 gen_dir = os.path.join(temp_dir, 'gen') |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 if options.depfile: | 411 if options.depfile: |
412 input_files += build_utils.GetPythonDependencies() | 412 input_files += build_utils.GetPythonDependencies() |
413 build_utils.WriteDepfile(options.depfile, input_files) | 413 build_utils.WriteDepfile(options.depfile, input_files) |
414 | 414 |
415 if options.stamp: | 415 if options.stamp: |
416 build_utils.Touch(options.stamp) | 416 build_utils.Touch(options.stamp) |
417 | 417 |
418 | 418 |
419 if __name__ == '__main__': | 419 if __name__ == '__main__': |
420 main() | 420 main() |
OLD | NEW |