Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: build/android/process_resources.py

Issue 12516019: Make process_resources.py more configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/java.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 subprocess 11 import subprocess
12 12
13 13 from pylib import build_utils
14 BUILD_ANDROID_DIR = os.path.dirname(__file__)
15
16 14
17 def ParseArgs(): 15 def ParseArgs():
18 """Parses command line options. 16 """Parses command line options.
19 17
20 Returns: 18 Returns:
21 An options object as from optparse.OptionsParser.parse_args() 19 An options object as from optparse.OptionsParser.parse_args()
22 """ 20 """
23 parser = optparse.OptionParser() 21 parser = optparse.OptionParser()
24 parser.add_option('--android-sdk', help='path to the Android SDK folder') 22 parser.add_option('--android-sdk', help='path to the Android SDK folder')
25 parser.add_option('--android-sdk-tools', 23 parser.add_option('--android-sdk-tools',
26 help='path to the Android SDK platform tools folder') 24 help='path to the Android SDK platform tools folder')
27 parser.add_option('--R-package', help='Java package for generated R.java')
28 parser.add_option('--R-dir', help='directory to hold generated R.java') 25 parser.add_option('--R-dir', help='directory to hold generated R.java')
29 parser.add_option('--res-dir', help='directory containing resources') 26 parser.add_option('--res-dir', help='directory containing resources')
30 parser.add_option('--out-res-dir', 27 parser.add_option('--out-res-dir',
31 help='directory to hold crunched resources') 28 help='directory to hold crunched resources')
29 parser.add_option('--non-constant-id', action='store_true')
30 parser.add_option('--custom-package', help='Java package for R.java')
31 parser.add_option('--android-manifest', help='AndroidManifest.xml path')
32 parser.add_option('--stamp', help='File to touch on success')
33
32 # This is part of a temporary fix for crbug.com/177552. 34 # This is part of a temporary fix for crbug.com/177552.
33 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja. 35 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
34 parser.add_option('--ignore', help='this argument is ignored') 36 parser.add_option('--ignore', help='this argument is ignored')
35 (options, args) = parser.parse_args() 37 (options, args) = parser.parse_args()
36 38
37 if args: 39 if args:
38 parser.error('No positional arguments should be given.') 40 parser.error('No positional arguments should be given.')
39 41
40 # Check that required options have been provided. 42 # Check that required options have been provided.
41 required_options = ('android_sdk', 'android_sdk_tools', 'R_package', 43 required_options = ('android_sdk', 'android_sdk_tools',
42 'R_dir', 'res_dir', 'out_res_dir') 44 'R_dir', 'res_dir', 'out_res_dir')
43 for option_name in required_options: 45 for option_name in required_options:
44 if getattr(options, option_name) is None: 46 if getattr(options, option_name) is None:
45 parser.error('--%s is required' % option_name.replace('_', '-')) 47 parser.error('--%s is required' % option_name.replace('_', '-'))
46 48
47 return options 49 return options
48 50
49 51
50 def main(): 52 def main():
51 options = ParseArgs() 53 options = ParseArgs()
52 android_jar = os.path.join(options.android_sdk, 'android.jar') 54 android_jar = os.path.join(options.android_sdk, 'android.jar')
53 aapt = os.path.join(options.android_sdk_tools, 'aapt') 55 aapt = os.path.join(options.android_sdk_tools, 'aapt')
54 dummy_manifest = os.path.join(BUILD_ANDROID_DIR, 'AndroidManifest.xml') 56
57 build_utils.MakeDirectory(options.R_dir)
55 58
56 # Generate R.java. This R.java contains non-final constants and is used only 59 # Generate R.java. This R.java contains non-final constants and is used only
57 # while compiling the library jar (e.g. chromium_content.jar). When building 60 # while compiling the library jar (e.g. chromium_content.jar). When building
58 # an apk, a new R.java file with the correct resource -> ID mappings will be 61 # an apk, a new R.java file with the correct resource -> ID mappings will be
59 # generated by merging the resources from all libraries and the main apk 62 # generated by merging the resources from all libraries and the main apk
60 # project. 63 # project.
61 package_command = [aapt, 64 package_command = [aapt,
62 'package', 65 'package',
63 '-m', 66 '-m',
64 '--non-constant-id', 67 '-M', options.android_manifest,
65 '--custom-package', options.R_package,
66 '-M', dummy_manifest,
67 '-S', options.res_dir, 68 '-S', options.res_dir,
68 '--auto-add-overlay', 69 '--auto-add-overlay',
69 '-I', android_jar, 70 '-I', android_jar,
70 '--output-text-symbols', options.R_dir, 71 '--output-text-symbols', options.R_dir,
71 '-J', options.R_dir] 72 '-J', options.R_dir]
72 # If strings.xml was generated from a grd file, it will be in out_res_dir. 73 # If strings.xml was generated from a grd file, it will be in out_res_dir.
73 if os.path.isdir(options.out_res_dir): 74 if os.path.isdir(options.out_res_dir):
74 package_command += ['-S', options.out_res_dir] 75 package_command += ['-S', options.out_res_dir]
76 if options.non_constant_id:
77 package_command.append('--non-constant-id')
78 if options.custom_package:
79 package_command += ['--custom-package', options.custom_package]
75 subprocess.check_call(package_command) 80 subprocess.check_call(package_command)
76 81
77 # Crunch image resources. This shrinks png files and is necessary for 9-patch 82 # Crunch image resources. This shrinks png files and is necessary for 9-patch
78 # images to display correctly. 83 # images to display correctly.
79 subprocess.check_call([aapt, 84 subprocess.check_call([aapt,
80 'crunch', 85 'crunch',
81 '-S', options.res_dir, 86 '-S', options.res_dir,
82 '-C', options.out_res_dir]) 87 '-C', options.out_res_dir])
83 88
89 build_utils.Touch(options.stamp)
90
84 91
85 if __name__ == '__main__': 92 if __name__ == '__main__':
86 main() 93 main()
OLDNEW
« no previous file with comments | « no previous file | build/java.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698