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

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

Issue 570033002: Fix handling of resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-openmax-dl
Patch Set: Created 6 years, 3 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
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 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 parser.add_option( 57 parser.add_option(
58 '--v14-verify-only', 58 '--v14-verify-only',
59 action='store_true', 59 action='store_true',
60 help='Do not generate v14 resources. Instead, just verify that the ' 60 help='Do not generate v14 resources. Instead, just verify that the '
61 'resources are already compatible with v14, i.e. they don\'t use ' 61 'resources are already compatible with v14, i.e. they don\'t use '
62 'attributes that cause crashes on certain devices.') 62 'attributes that cause crashes on certain devices.')
63 63
64 parser.add_option( 64 parser.add_option(
65 '--extra-res-packages', 65 '--extra-res-packages',
66 help='Additional package names to generate R.java files for') 66 help='Additional package names to generate R.java files for')
67 # TODO(cjhopman): Actually use --extra-r-text-files. We currently include all
68 # the resources in all R.java files for a particular apk.
67 parser.add_option( 69 parser.add_option(
68 '--extra-r-text-files', 70 '--extra-r-text-files',
69 help='For each additional package, the R.txt file should contain a ' 71 help='For each additional package, the R.txt file should contain a '
70 'list of resources to be included in the R.java file in the format ' 72 'list of resources to be included in the R.java file in the format '
71 'generated by aapt') 73 'generated by aapt')
72 74
73 parser.add_option( 75 parser.add_option(
74 '--all-resources-zip-out', 76 '--all-resources-zip-out',
75 help='Path for output of all resources. This includes resources in ' 77 help='Path for output of all resources. This includes resources in '
76 'dependencies.') 78 'dependencies.')
(...skipping 15 matching lines...) Expand all
92 'resource_zip_out', 94 'resource_zip_out',
93 ) 95 )
94 build_utils.CheckOptions(options, parser, required=required_options) 96 build_utils.CheckOptions(options, parser, required=required_options)
95 97
96 if (options.R_dir is None) == (options.srcjar_out is None): 98 if (options.R_dir is None) == (options.srcjar_out is None):
97 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.') 99 raise Exception('Exactly one of --R-dir or --srcjar-out must be specified.')
98 100
99 return options 101 return options
100 102
101 103
102 def CreateExtraRJavaFiles( 104 def CreateExtraRJavaFiles(r_dir, extra_packages):
103 r_dir, extra_packages, extra_r_text_files):
104 if len(extra_packages) != len(extra_r_text_files):
105 raise Exception('--extra-res-packages and --extra-r-text-files'
106 'should have the same length')
107
108 java_files = build_utils.FindInDirectory(r_dir, "R.java") 105 java_files = build_utils.FindInDirectory(r_dir, "R.java")
109 if len(java_files) != 1: 106 if len(java_files) != 1:
110 return 107 return
111 r_java_file = java_files[0] 108 r_java_file = java_files[0]
112 r_java_contents = open(r_java_file).read() 109 r_java_contents = open(r_java_file).read()
113 110
114 for package in extra_packages: 111 for package in extra_packages:
115 package_r_java_dir = os.path.join(r_dir, *package.split('.')) 112 package_r_java_dir = os.path.join(r_dir, *package.split('.'))
116 build_utils.MakeDirectory(package_r_java_dir) 113 build_utils.MakeDirectory(package_r_java_dir)
117 package_r_java_path = os.path.join(package_r_java_dir, 'R.java') 114 package_r_java_path = os.path.join(package_r_java_dir, 'R.java')
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 package_command.append('--non-constant-id') 226 package_command.append('--non-constant-id')
230 if options.custom_package: 227 if options.custom_package:
231 package_command += ['--custom-package', options.custom_package] 228 package_command += ['--custom-package', options.custom_package]
232 if options.proguard_file: 229 if options.proguard_file:
233 package_command += ['-G', options.proguard_file] 230 package_command += ['-G', options.proguard_file]
234 build_utils.CheckOutput(package_command, print_stderr=False) 231 build_utils.CheckOutput(package_command, print_stderr=False)
235 232
236 if options.extra_res_packages: 233 if options.extra_res_packages:
237 CreateExtraRJavaFiles( 234 CreateExtraRJavaFiles(
238 gen_dir, 235 gen_dir,
239 build_utils.ParseGypList(options.extra_res_packages), 236 build_utils.ParseGypList(options.extra_res_packages))
240 build_utils.ParseGypList(options.extra_r_text_files))
241 237
242 # This is the list of directories with resources to put in the final .zip 238 # This is the list of directories with resources to put in the final .zip
243 # file. The order of these is important so that crunched/v14 resources 239 # file. The order of these is important so that crunched/v14 resources
244 # override the normal ones. 240 # override the normal ones.
245 zip_resource_dirs = input_resource_dirs + [v14_dir] 241 zip_resource_dirs = input_resource_dirs + [v14_dir]
246 242
247 base_crunch_dir = os.path.join(temp_dir, 'crunch') 243 base_crunch_dir = os.path.join(temp_dir, 'crunch')
248 244
249 # Crunch image resources. This shrinks png files and is necessary for 245 # Crunch image resources. This shrinks png files and is necessary for
250 # 9-patch images to display correctly. 'aapt crunch' accepts only a single 246 # 9-patch images to display correctly. 'aapt crunch' accepts only a single
(...skipping 23 matching lines...) Expand all
274 if options.depfile: 270 if options.depfile:
275 input_files += build_utils.GetPythonDependencies() 271 input_files += build_utils.GetPythonDependencies()
276 build_utils.WriteDepfile(options.depfile, input_files) 272 build_utils.WriteDepfile(options.depfile, input_files)
277 273
278 if options.stamp: 274 if options.stamp:
279 build_utils.Touch(options.stamp) 275 build_utils.Touch(options.stamp)
280 276
281 277
282 if __name__ == '__main__': 278 if __name__ == '__main__':
283 main() 279 main()
OLDNEW
« no previous file with comments | « no previous file | build/android/gyp/write_build_config.py » ('j') | build/android/gyp/write_build_config.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698