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

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

Issue 2371843002: Reland of Move language pak files to assets. (Closed)
Patch Set: Add locale_pak_assets to android_test_apk Created 4 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 | « build/android/gyp/write_build_config.py ('k') | build/config/android/internal_rules.gni » ('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/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Prints the size of each given file and optionally computes the size of 6 """Prints the size of each given file and optionally computes the size of
7 libchrome.so without the dependencies added for building with android NDK. 7 libchrome.so without the dependencies added for building with android NDK.
8 Also breaks down the contents of the APK to determine the installed size 8 Also breaks down the contents of the APK to determine the installed size
9 and assign size contributions to different classes of file. 9 and assign size contributions to different classes of file.
10 """ 10 """
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 # extracted from the apk at install/runtime. 177 # extracted from the apk at install/runtime.
178 FileGroup = collections.namedtuple('FileGroup', 178 FileGroup = collections.namedtuple('FileGroup',
179 ['name', 'regex', 'extracted']) 179 ['name', 'regex', 'extracted'])
180 180
181 # File groups are checked in sequence, so more specific regexes should be 181 # File groups are checked in sequence, so more specific regexes should be
182 # earlier in the list. 182 # earlier in the list.
183 YES = lambda _: True 183 YES = lambda _: True
184 NO = lambda _: False 184 NO = lambda _: False
185 FILE_GROUPS = ( 185 FILE_GROUPS = (
186 FileGroup('Native code', r'\.so$', lambda f: 'crazy' not in f), 186 FileGroup('Native code', r'\.so$', lambda f: 'crazy' not in f),
187 FileGroup('Java code', r'\.dex$', YES), 187 FileGroup('Java code', r'^classes.*\.dex$', YES),
188 FileGroup('Native resources (no l10n)', r'\.pak$', NO), 188 FileGroup('Native resources (no l10n)',
189 r'^assets/.*(resources|percent)\.pak$', NO),
189 # For locale paks, assume only english paks are extracted. 190 # For locale paks, assume only english paks are extracted.
190 FileGroup('Native resources (l10n)', r'\.lpak$', lambda f: 'en_' in f), 191 FileGroup('Native resources (l10n)',
191 FileGroup('ICU (i18n library) data', r'assets/icudtl\.dat$', NO), 192 r'\.lpak$|^assets/.*(?!resources|percent)\.pak$',
192 FileGroup('V8 Snapshots', r'\.bin$', NO), 193 lambda f: 'en_' in f),
estevenson 2016/09/29 18:02:27 Should this be 'en-' now that we've removed locale
agrieve 2016/09/29 19:09:34 Nice catch! Done.
194 FileGroup('ICU (i18n library) data', r'^assets/icudtl\.dat$', NO),
195 FileGroup('V8 Snapshots', r'^assets/.*\.bin$', NO),
193 FileGroup('PNG drawables', r'\.png$', NO), 196 FileGroup('PNG drawables', r'\.png$', NO),
194 FileGroup('Non-compiled Android resources', r'^res/', NO), 197 FileGroup('Non-compiled Android resources', r'^res/', NO),
195 FileGroup('Compiled Android resources', r'\.arsc$', NO), 198 FileGroup('Compiled Android resources', r'\.arsc$', NO),
196 FileGroup('Package metadata', r'^(META-INF/|AndroidManifest\.xml$)', NO), 199 FileGroup('Package metadata', r'^(META-INF/|AndroidManifest\.xml$)', NO),
197 FileGroup('Unknown files', r'.', NO), 200 FileGroup('Unknown files', r'.', NO),
198 ) 201 )
199 202
200 apk = zipfile.ZipFile(apk_filename, 'r') 203 apk = zipfile.ZipFile(apk_filename, 'r')
201 try: 204 try:
202 apk_contents = apk.infolist() 205 apk_contents = apk.infolist()
(...skipping 11 matching lines...) Expand all
214 for group in FILE_GROUPS: 217 for group in FILE_GROUPS:
215 if re.search(group.regex, member.filename): 218 if re.search(group.regex, member.filename):
216 found_files[group].append(member) 219 found_files[group].append(member)
217 break 220 break
218 else: 221 else:
219 raise KeyError('No group found for file "%s"' % member.filename) 222 raise KeyError('No group found for file "%s"' % member.filename)
220 223
221 total_install_size = total_apk_size 224 total_install_size = total_apk_size
222 225
223 for group in FILE_GROUPS: 226 for group in FILE_GROUPS:
224 uncompressed_size = sum(member.file_size for member in found_files[group]) 227 uncompressed_size = 0
225 packed_size = sum(member.compress_size for member in found_files[group]) 228 packed_size = 0
226 install_size = packed_size 229 extracted_size = 0
227 install_bytes = sum(member.file_size for member in found_files[group] 230 for member in found_files[group]:
228 if group.extracted(member.filename)) 231 uncompressed_size += member.file_size
229 install_size += install_bytes 232 packed_size += member.compress_size
230 total_install_size += install_bytes 233 # Assume that if a file is not compressed, then it is not extracted.
234 is_compressed = member.compress_type != zipfile.ZIP_STORED
235 if is_compressed and group.extracted(member.filename):
236 extracted_size += member.file_size
237 install_size = packed_size + extracted_size
238 total_install_size += extracted_size
231 239
232 ReportPerfResult(chartjson, apk_basename + '_Breakdown', 240 ReportPerfResult(chartjson, apk_basename + '_Breakdown',
233 group.name + ' size', packed_size, 'bytes') 241 group.name + ' size', packed_size, 'bytes')
234 ReportPerfResult(chartjson, apk_basename + '_InstallBreakdown', 242 ReportPerfResult(chartjson, apk_basename + '_InstallBreakdown',
235 group.name + ' size', install_size, 'bytes') 243 group.name + ' size', install_size, 'bytes')
236 ReportPerfResult(chartjson, apk_basename + '_Uncompressed', 244 ReportPerfResult(chartjson, apk_basename + '_Uncompressed',
237 group.name + ' size', uncompressed_size, 'bytes') 245 group.name + ' size', uncompressed_size, 'bytes')
238 246
239 transfer_size = _CalculateCompressedSize(apk_filename) 247 transfer_size = _CalculateCompressedSize(apk_filename)
240 ReportPerfResult(chartjson, apk_basename + '_InstallSize', 248 ReportPerfResult(chartjson, apk_basename + '_InstallSize',
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 508
501 if chartjson: 509 if chartjson:
502 results_path = os.path.join(options.output_dir, 'results-chart.json') 510 results_path = os.path.join(options.output_dir, 'results-chart.json')
503 logging.critical('Dumping json to %s', results_path) 511 logging.critical('Dumping json to %s', results_path)
504 with open(results_path, 'w') as json_file: 512 with open(results_path, 'w') as json_file:
505 json.dump(chartjson, json_file) 513 json.dump(chartjson, json_file)
506 514
507 515
508 if __name__ == '__main__': 516 if __name__ == '__main__':
509 sys.exit(main(sys.argv)) 517 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/android/gyp/write_build_config.py ('k') | build/config/android/internal_rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698