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

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

Issue 619793002: Ignore "libpng: unknown profile" warnings when running aapt crunch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wrapped long line Created 6 years, 2 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 | no next file » | 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 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 build_utils.MakeDirectory(package_r_java_dir) 113 build_utils.MakeDirectory(package_r_java_dir)
114 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')
115 open(package_r_java_path, 'w').write( 115 open(package_r_java_path, 'w').write(
116 re.sub(r'package [.\w]*;', 'package %s;' % package, r_java_contents)) 116 re.sub(r'package [.\w]*;', 'package %s;' % package, r_java_contents))
117 # TODO(cjhopman): These extra package's R.java files should be filtered to 117 # TODO(cjhopman): These extra package's R.java files should be filtered to
118 # only contain the resources listed in their R.txt files. At this point, we 118 # only contain the resources listed in their R.txt files. At this point, we
119 # have already compiled those other libraries, so doing this would only 119 # have already compiled those other libraries, so doing this would only
120 # affect how the code in this .apk target could refer to the resources. 120 # affect how the code in this .apk target could refer to the resources.
121 121
122 122
123 def FilterCrunchStderr(stderr):
124 """Filters out lines from aapt crunch's stderr that can safely be ignored."""
125 filtered_lines = []
126 for line in stderr.splitlines(True):
127 # Ignore this libpng warning, which is a known non-error condition.
128 # http://crbug.com/364355
129 if ('libpng warning: iCCP: Not recognizing known sRGB profile that has '
130 + 'been edited' in line):
131 continue
132 filtered_lines.append(line)
133 return ''.join(filtered_lines)
134
135
123 def DidCrunchFail(returncode, stderr): 136 def DidCrunchFail(returncode, stderr):
124 """Determines whether aapt crunch failed from its return code and output. 137 """Determines whether aapt crunch failed from its return code and output.
125 138
126 Because aapt's return code cannot be trusted, any output to stderr is 139 Because aapt's return code cannot be trusted, any output to stderr is
127 an indication that aapt has failed (http://crbug.com/314885), except 140 an indication that aapt has failed (http://crbug.com/314885).
128 lines that contain "libpng warning", which is a known non-error condition
129 (http://crbug.com/364355).
130 """ 141 """
131 if returncode != 0: 142 return returncode != 0 or stderr
132 return True
133 for line in stderr.splitlines():
134 if line and not 'libpng warning' in line:
135 return True
136 return False
137 143
138 144
139 def ZipResources(resource_dirs, zip_path): 145 def ZipResources(resource_dirs, zip_path):
140 # Python zipfile does not provide a way to replace a file (it just writes 146 # Python zipfile does not provide a way to replace a file (it just writes
141 # another file with the same name). So, first collect all the files to put 147 # another file with the same name). So, first collect all the files to put
142 # in the zip (with proper overriding), and then zip them. 148 # in the zip (with proper overriding), and then zip them.
143 files_to_zip = dict() 149 files_to_zip = dict()
144 for d in resource_dirs: 150 for d in resource_dirs:
145 for root, _, files in os.walk(d): 151 for root, _, files in os.walk(d):
146 for f in files: 152 for f in files:
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 # 9-patch images to display correctly. 'aapt crunch' accepts only a single 252 # 9-patch images to display correctly. 'aapt crunch' accepts only a single
247 # directory at a time and deletes everything in the output directory. 253 # directory at a time and deletes everything in the output directory.
248 for idx, d in enumerate(input_resource_dirs): 254 for idx, d in enumerate(input_resource_dirs):
249 crunch_dir = os.path.join(base_crunch_dir, str(idx)) 255 crunch_dir = os.path.join(base_crunch_dir, str(idx))
250 build_utils.MakeDirectory(crunch_dir) 256 build_utils.MakeDirectory(crunch_dir)
251 zip_resource_dirs.append(crunch_dir) 257 zip_resource_dirs.append(crunch_dir)
252 aapt_cmd = [aapt, 258 aapt_cmd = [aapt,
253 'crunch', 259 'crunch',
254 '-C', crunch_dir, 260 '-C', crunch_dir,
255 '-S', d] 261 '-S', d]
256 build_utils.CheckOutput(aapt_cmd, fail_func=DidCrunchFail) 262 build_utils.CheckOutput(aapt_cmd, stderr_filter=FilterCrunchStderr,
263 fail_func=DidCrunchFail)
257 264
258 ZipResources(zip_resource_dirs, options.resource_zip_out) 265 ZipResources(zip_resource_dirs, options.resource_zip_out)
259 266
260 if options.all_resources_zip_out: 267 if options.all_resources_zip_out:
261 CombineZips([options.resource_zip_out] + dep_zips, 268 CombineZips([options.resource_zip_out] + dep_zips,
262 options.all_resources_zip_out) 269 options.all_resources_zip_out)
263 270
264 if options.R_dir: 271 if options.R_dir:
265 build_utils.DeleteDirectory(options.R_dir) 272 build_utils.DeleteDirectory(options.R_dir)
266 shutil.copytree(gen_dir, options.R_dir) 273 shutil.copytree(gen_dir, options.R_dir)
267 else: 274 else:
268 build_utils.ZipDir(options.srcjar_out, gen_dir) 275 build_utils.ZipDir(options.srcjar_out, gen_dir)
269 276
270 if options.depfile: 277 if options.depfile:
271 input_files += build_utils.GetPythonDependencies() 278 input_files += build_utils.GetPythonDependencies()
272 build_utils.WriteDepfile(options.depfile, input_files) 279 build_utils.WriteDepfile(options.depfile, input_files)
273 280
274 if options.stamp: 281 if options.stamp:
275 build_utils.Touch(options.stamp) 282 build_utils.Touch(options.stamp)
276 283
277 284
278 if __name__ == '__main__': 285 if __name__ == '__main__':
279 main() 286 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698