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

Side by Side Diff: build/android/gyp/util/build_utils.py

Issue 2400693002: Make apk_merger.py use hermetic timestamps. (Closed)
Patch Set: 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 | « android_webview/tools/apk_merger.py ('k') | 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 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import ast 5 import ast
6 import contextlib 6 import contextlib
7 import fnmatch 7 import fnmatch
8 import json 8 import json
9 import os 9 import os
10 import pipes 10 import pipes
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 321
322 def MatchesGlob(path, filters): 322 def MatchesGlob(path, filters):
323 """Returns whether the given path matches any of the given glob patterns.""" 323 """Returns whether the given path matches any of the given glob patterns."""
324 return filters and any(fnmatch.fnmatch(path, f) for f in filters) 324 return filters and any(fnmatch.fnmatch(path, f) for f in filters)
325 325
326 326
327 def MergeZips(output, inputs, exclude_patterns=None, path_transform=None): 327 def MergeZips(output, inputs, exclude_patterns=None, path_transform=None):
328 path_transform = path_transform or (lambda p, z: p) 328 path_transform = path_transform or (lambda p, z: p)
329 added_names = set() 329 added_names = set()
330 330
331 with zipfile.ZipFile(output, 'w') as out_zip: 331 if isinstance(output, basestring):
332 out_zip = zipfile.ZipFile(output, 'w')
333 else:
334 assert isinstance(output, zipfile.ZipFile)
335 out_zip = output
336
337 try:
332 for in_file in inputs: 338 for in_file in inputs:
333 with zipfile.ZipFile(in_file, 'r') as in_zip: 339 with zipfile.ZipFile(in_file, 'r') as in_zip:
334 in_zip._expected_crc = None 340 in_zip._expected_crc = None
335 for info in in_zip.infolist(): 341 for info in in_zip.infolist():
336 # Ignore directories. 342 # Ignore directories.
337 if info.filename[-1] == '/': 343 if info.filename[-1] == '/':
338 continue 344 continue
339 dst_name = path_transform(info.filename, in_file) 345 dst_name = path_transform(info.filename, in_file)
340 already_added = dst_name in added_names 346 already_added = dst_name in added_names
341 if not already_added and not MatchesGlob(dst_name, exclude_patterns): 347 if not already_added and not MatchesGlob(dst_name, exclude_patterns):
342 AddToZipHermetic(out_zip, dst_name, data=in_zip.read(info)) 348 AddToZipHermetic(out_zip, dst_name, data=in_zip.read(info),
349 compress=info.compress_type != zipfile.ZIP_STORED)
343 added_names.add(dst_name) 350 added_names.add(dst_name)
351 finally:
352 if isinstance(output, basestring):
michaelbai 2016/10/06 18:05:41 nit, use variable instead of checking twice?
agrieve 2016/10/06 18:17:02 Done.
353 out_zip.close()
344 354
345 355
346 def PrintWarning(message): 356 def PrintWarning(message):
347 print 'WARNING: ' + message 357 print 'WARNING: ' + message
348 358
349 359
350 def PrintBigWarning(message): 360 def PrintBigWarning(message):
351 print '***** ' * 8 361 print '***** ' * 8
352 PrintWarning(message) 362 PrintWarning(message)
353 print '***** ' * 8 363 print '***** ' * 8
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 546
537 md5_check.CallAndRecordIfStale( 547 md5_check.CallAndRecordIfStale(
538 on_stale_md5, 548 on_stale_md5,
539 record_path=record_path, 549 record_path=record_path,
540 input_paths=input_paths, 550 input_paths=input_paths,
541 input_strings=input_strings, 551 input_strings=input_strings,
542 output_paths=output_paths, 552 output_paths=output_paths,
543 force=force, 553 force=force,
544 pass_changes=True) 554 pass_changes=True)
545 555
OLDNEW
« no previous file with comments | « android_webview/tools/apk_merger.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698