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 codecs | 13 import codecs |
14 import optparse | 14 import optparse |
15 import os | 15 import os |
16 import re | 16 import re |
17 import shutil | 17 import shutil |
18 import sys | 18 import sys |
19 import zipfile | 19 import zipfile |
20 | 20 |
21 import generate_v14_compatible_resources | 21 import generate_v14_compatible_resources |
22 | 22 |
23 from util import build_utils | 23 from util import build_utils |
24 | 24 |
25 # Import jinja2 from third_party/jinja2 | 25 # Import jinja2 from third_party/jinja2 |
26 sys.path.append(os.path.join(os.path.dirname(__file__), '../../../third_party')) | 26 sys.path.insert(1, |
| 27 os.path.join(os.path.dirname(__file__), '../../../third_party')) |
27 from jinja2 import Template # pylint: disable=F0401 | 28 from jinja2 import Template # pylint: disable=F0401 |
28 | 29 |
29 | 30 |
30 def ParseArgs(args): | 31 def ParseArgs(args): |
31 """Parses command line options. | 32 """Parses command line options. |
32 | 33 |
33 Returns: | 34 Returns: |
34 An options object as from optparse.OptionsParser.parse_args() | 35 An options object as from optparse.OptionsParser.parse_args() |
35 """ | 36 """ |
36 parser = optparse.OptionParser() | 37 parser = optparse.OptionParser() |
37 build_utils.AddDepfileOption(parser) | 38 build_utils.AddDepfileOption(parser) |
38 | 39 |
39 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') |
40 parser.add_option('--android-sdk-tools', | 41 parser.add_option('--aapt-path', |
41 help='path to the Android SDK build tools folder') | 42 help='path to the Android aapt tool') |
42 parser.add_option('--non-constant-id', action='store_true') | 43 parser.add_option('--non-constant-id', action='store_true') |
43 | 44 |
44 parser.add_option('--android-manifest', help='AndroidManifest.xml path') | 45 parser.add_option('--android-manifest', help='AndroidManifest.xml path') |
45 parser.add_option('--custom-package', help='Java package for R.java') | 46 parser.add_option('--custom-package', help='Java package for R.java') |
46 parser.add_option( | 47 parser.add_option( |
47 '--shared-resources', | 48 '--shared-resources', |
48 action='store_true', | 49 action='store_true', |
49 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' |
50 'application at runtime to access the package\'s resources.') | 51 'application at runtime to access the package\'s resources.') |
51 | 52 |
52 parser.add_option('--resource-dirs', | 53 parser.add_option('--resource-dirs', |
53 help='Directories containing resources of this target.') | 54 help='Directories containing resources of this target.') |
54 parser.add_option('--dependencies-res-zips', | 55 parser.add_option('--dependencies-res-zips', |
55 help='Resources from dependents.') | 56 help='Resources from dependents.') |
56 | 57 |
57 parser.add_option('--resource-zip-out', | 58 parser.add_option('--resource-zip-out', |
58 help='Path for output zipped resources.') | 59 help='Path for output zipped resources.') |
59 | 60 |
60 parser.add_option('--R-dir', | 61 parser.add_option('--R-dir', |
61 help='directory to hold generated R.java.') | 62 help='directory to hold generated R.java.') |
62 parser.add_option('--srcjar-out', | 63 parser.add_option('--srcjar-out', |
63 help='Path to srcjar to contain generated R.java.') | 64 help='Path to srcjar to contain generated R.java.') |
64 parser.add_option('--r-text-out', | 65 parser.add_option('--r-text-out', |
65 help='Path to store the R.txt file generated by appt.') | 66 help='Path to store the R.txt file generated by appt.') |
66 | 67 |
67 parser.add_option('--proguard-file', | 68 parser.add_option('--proguard-file', |
68 help='Path to proguard.txt generated file') | 69 help='Path to proguard.txt generated file') |
69 | 70 |
70 parser.add_option( | 71 parser.add_option( |
71 '--v14-verify-only', | 72 '--v14-skip', |
72 action='store_true', | 73 action="store_true", |
73 help='Do not generate v14 resources. Instead, just verify that the ' | 74 help='Do not generate nor verify v14 resources') |
74 'resources are already compatible with v14, i.e. they don\'t use ' | |
75 'attributes that cause crashes on certain devices.') | |
76 | 75 |
77 parser.add_option( | 76 parser.add_option( |
78 '--extra-res-packages', | 77 '--extra-res-packages', |
79 help='Additional package names to generate R.java files for') | 78 help='Additional package names to generate R.java files for') |
80 parser.add_option( | 79 parser.add_option( |
81 '--extra-r-text-files', | 80 '--extra-r-text-files', |
82 help='For each additional package, the R.txt file should contain a ' | 81 help='For each additional package, the R.txt file should contain a ' |
83 'list of resources to be included in the R.java file in the format ' | 82 'list of resources to be included in the R.java file in the format ' |
84 'generated by aapt') | 83 'generated by aapt') |
85 parser.add_option( | 84 parser.add_option( |
(...skipping 10 matching lines...) Expand all Loading... |
96 parser.add_option('--stamp', help='File to touch on success') | 95 parser.add_option('--stamp', help='File to touch on success') |
97 | 96 |
98 (options, args) = parser.parse_args(args) | 97 (options, args) = parser.parse_args(args) |
99 | 98 |
100 if args: | 99 if args: |
101 parser.error('No positional arguments should be given.') | 100 parser.error('No positional arguments should be given.') |
102 | 101 |
103 # Check that required options have been provided. | 102 # Check that required options have been provided. |
104 required_options = ( | 103 required_options = ( |
105 'android_sdk', | 104 'android_sdk', |
106 'android_sdk_tools', | 105 'aapt_path', |
107 'android_manifest', | 106 'android_manifest', |
108 'dependencies_res_zips', | 107 'dependencies_res_zips', |
109 'resource_dirs', | 108 'resource_dirs', |
110 'resource_zip_out', | 109 'resource_zip_out', |
111 ) | 110 ) |
112 build_utils.CheckOptions(options, parser, required=required_options) | 111 build_utils.CheckOptions(options, parser, required=required_options) |
113 | 112 |
114 if (options.R_dir is None) == (options.srcjar_out is None): | 113 if (options.R_dir is None) == (options.srcjar_out is None): |
115 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.') |
116 | 115 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 for name in inzip.namelist(): | 296 for name in inzip.namelist(): |
298 new_name = '%d/%s' % (i, name) | 297 new_name = '%d/%s' % (i, name) |
299 outzip.writestr(new_name, inzip.read(name)) | 298 outzip.writestr(new_name, inzip.read(name)) |
300 | 299 |
301 | 300 |
302 def main(): | 301 def main(): |
303 args = build_utils.ExpandFileArgs(sys.argv[1:]) | 302 args = build_utils.ExpandFileArgs(sys.argv[1:]) |
304 | 303 |
305 options = ParseArgs(args) | 304 options = ParseArgs(args) |
306 android_jar = os.path.join(options.android_sdk, 'android.jar') | 305 android_jar = os.path.join(options.android_sdk, 'android.jar') |
307 aapt = os.path.join(options.android_sdk_tools, 'aapt') | 306 aapt = options.aapt_path |
308 | 307 |
309 input_files = [] | 308 input_files = [] |
310 | 309 |
311 with build_utils.TempDir() as temp_dir: | 310 with build_utils.TempDir() as temp_dir: |
312 deps_dir = os.path.join(temp_dir, 'deps') | 311 deps_dir = os.path.join(temp_dir, 'deps') |
313 build_utils.MakeDirectory(deps_dir) | 312 build_utils.MakeDirectory(deps_dir) |
314 v14_dir = os.path.join(temp_dir, 'v14') | 313 v14_dir = os.path.join(temp_dir, 'v14') |
315 build_utils.MakeDirectory(v14_dir) | 314 build_utils.MakeDirectory(v14_dir) |
316 | 315 |
317 gen_dir = os.path.join(temp_dir, 'gen') | 316 gen_dir = os.path.join(temp_dir, 'gen') |
318 build_utils.MakeDirectory(gen_dir) | 317 build_utils.MakeDirectory(gen_dir) |
319 | 318 |
320 input_resource_dirs = build_utils.ParseGypList(options.resource_dirs) | 319 input_resource_dirs = build_utils.ParseGypList(options.resource_dirs) |
321 | 320 |
322 for resource_dir in input_resource_dirs: | 321 if not options.v14_skip: |
323 generate_v14_compatible_resources.GenerateV14Resources( | 322 for resource_dir in input_resource_dirs: |
324 resource_dir, | 323 generate_v14_compatible_resources.GenerateV14Resources( |
325 v14_dir, | 324 resource_dir, |
326 options.v14_verify_only) | 325 v14_dir) |
327 | 326 |
328 dep_zips = build_utils.ParseGypList(options.dependencies_res_zips) | 327 dep_zips = build_utils.ParseGypList(options.dependencies_res_zips) |
329 input_files += dep_zips | 328 input_files += dep_zips |
330 dep_subdirs = [] | 329 dep_subdirs = [] |
331 for z in dep_zips: | 330 for z in dep_zips: |
332 subdir = os.path.join(deps_dir, os.path.basename(z)) | 331 subdir = os.path.join(deps_dir, os.path.basename(z)) |
333 if os.path.exists(subdir): | 332 if os.path.exists(subdir): |
334 raise Exception('Resource zip name conflict: ' + os.path.basename(z)) | 333 raise Exception('Resource zip name conflict: ' + os.path.basename(z)) |
335 build_utils.ExtractAll(z, path=subdir) | 334 build_utils.ExtractAll(z, path=subdir) |
336 dep_subdirs.append(subdir) | 335 dep_subdirs.append(subdir) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 if options.depfile: | 411 if options.depfile: |
413 input_files += build_utils.GetPythonDependencies() | 412 input_files += build_utils.GetPythonDependencies() |
414 build_utils.WriteDepfile(options.depfile, input_files) | 413 build_utils.WriteDepfile(options.depfile, input_files) |
415 | 414 |
416 if options.stamp: | 415 if options.stamp: |
417 build_utils.Touch(options.stamp) | 416 build_utils.Touch(options.stamp) |
418 | 417 |
419 | 418 |
420 if __name__ == '__main__': | 419 if __name__ == '__main__': |
421 main() | 420 main() |
OLD | NEW |