| OLD | NEW |
| 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 difflib | 5 import difflib |
| 6 import hashlib | 6 import hashlib |
| 7 import itertools | 7 import itertools |
| 8 import json | 8 import json |
| 9 import os | 9 import os |
| 10 import sys | 10 import sys |
| 11 import zipfile | 11 import zipfile |
| 12 | 12 |
| 13 | 13 |
| 14 # When set and a difference is detected, a diff of what changed is printed. | 14 # When set and a difference is detected, a diff of what changed is printed. |
| 15 _PRINT_MD5_DIFFS = int(os.environ.get('PRINT_MD5_DIFFS', 0)) | 15 PRINT_EXPLANATIONS = int(os.environ.get('PRINT_BUILD_EXPLANATIONS', 0)) |
| 16 | 16 |
| 17 # An escape hatch that causes all targets to be rebuilt. | 17 # An escape hatch that causes all targets to be rebuilt. |
| 18 _FORCE_REBUILD = int(os.environ.get('FORCE_REBUILD', 0)) | 18 _FORCE_REBUILD = int(os.environ.get('FORCE_REBUILD', 0)) |
| 19 | 19 |
| 20 | 20 |
| 21 def CallAndRecordIfStale( | 21 def CallAndRecordIfStale( |
| 22 function, record_path=None, input_paths=None, input_strings=None, | 22 function, record_path=None, input_paths=None, input_strings=None, |
| 23 output_paths=None, force=False, pass_changes=False): | 23 output_paths=None, force=False, pass_changes=False): |
| 24 """Calls function if outputs are stale. | 24 """Calls function if outputs are stale. |
| 25 | 25 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 with open(record_path, 'r') as jsonfile: | 70 with open(record_path, 'r') as jsonfile: |
| 71 try: | 71 try: |
| 72 old_metadata = _Metadata.FromFile(jsonfile) | 72 old_metadata = _Metadata.FromFile(jsonfile) |
| 73 except: # pylint: disable=bare-except | 73 except: # pylint: disable=bare-except |
| 74 pass # Not yet using new file format. | 74 pass # Not yet using new file format. |
| 75 | 75 |
| 76 changes = Changes(old_metadata, new_metadata, force, missing_outputs) | 76 changes = Changes(old_metadata, new_metadata, force, missing_outputs) |
| 77 if not changes.HasChanges(): | 77 if not changes.HasChanges(): |
| 78 return | 78 return |
| 79 | 79 |
| 80 if _PRINT_MD5_DIFFS: | 80 if PRINT_EXPLANATIONS: |
| 81 print '=' * 80 | 81 print '=' * 80 |
| 82 print 'Target is stale: %s' % record_path | 82 print 'Target is stale: %s' % record_path |
| 83 print changes.DescribeDifference() | 83 print changes.DescribeDifference() |
| 84 print '=' * 80 | 84 print '=' * 80 |
| 85 | 85 |
| 86 args = (changes,) if pass_changes else () | 86 args = (changes,) if pass_changes else () |
| 87 function(*args) | 87 function(*args) |
| 88 | 88 |
| 89 with open(record_path, 'w') as f: | 89 with open(record_path, 'w') as f: |
| 90 new_metadata.ToFile(f) | 90 new_metadata.ToFile(f) |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 389 |
| 390 def _ExtractZipEntries(path): | 390 def _ExtractZipEntries(path): |
| 391 """Returns a list of (path, CRC32) of all files within |path|.""" | 391 """Returns a list of (path, CRC32) of all files within |path|.""" |
| 392 entries = [] | 392 entries = [] |
| 393 with zipfile.ZipFile(path) as zip_file: | 393 with zipfile.ZipFile(path) as zip_file: |
| 394 for zip_info in zip_file.infolist(): | 394 for zip_info in zip_file.infolist(): |
| 395 # Skip directories and empty files. | 395 # Skip directories and empty files. |
| 396 if zip_info.CRC: | 396 if zip_info.CRC: |
| 397 entries.append((zip_info.filename, zip_info.CRC)) | 397 entries.append((zip_info.filename, zip_info.CRC)) |
| 398 return entries | 398 return entries |
| OLD | NEW |