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

Unified Diff: tools/determinism/compare_build_artifacts.py

Issue 2303063003: Skip COFF timestamp difference. (Closed)
Patch Set: skip COFF header in binary_diff. Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/determinism/compare_build_artifacts.py
diff --git a/tools/determinism/compare_build_artifacts.py b/tools/determinism/compare_build_artifacts.py
index d486cb99db63af1ac1eaa66dcce8164b7e3b6d87..ccd3ddf154447f7976a2f404e0edd12b32e6b7f0 100755
--- a/tools/determinism/compare_build_artifacts.py
+++ b/tools/determinism/compare_build_artifacts.py
@@ -436,6 +436,22 @@ def diff_dict(a, b):
return out.rstrip()
+def may_skip_coff_header(lhs_header, rhs_header):
+ """Returns True if we can skip checking COFF headers."""
+ # COFF header:
+ # 0 - 1: magic.
+ # 2 - 3: # sections.
+ # 4 - 8: timestamp.
+ # ...
+ if len(lhs_header) < 8:
+ return False
+ lhs_data = [l for l in lhs_header]
M-A Ruel 2016/09/06 15:35:54 Replace the lines 448-452 with: return lhs_data[4:
Yoshisato Yanagisawa 2016/09/07 01:50:28 I would basically change the code like so but let
+ rhs_data = [r for r in rhs_header]
+ for x in xrange(4):
+ lhs_data[4 + x] = rhs_data[4 + x] = chr(0)
+ return rhs_data == lhs_data
+
+
def diff_binary(first_filepath, second_filepath, file_len):
"""Returns a compact binary diff if the diff is small enough."""
CHUNK_SIZE = 32
@@ -445,6 +461,17 @@ def diff_binary(first_filepath, second_filepath, file_len):
offset = 0
with open(first_filepath, 'rb') as lhs:
with open(second_filepath, 'rb') as rhs:
+ # Skip COFF header on Win32 object file if only timestamps are different.
+ if sys.platform == 'win32' and first_filepath.endswith('.obj'):
+ COFF_HEADER_SIZE = 22
+ lhs_data = lhs.read(COFF_HEADER_SIZE)
+ rhs_data = rhs.read(COFF_HEADER_SIZE)
+ if may_skip_coff_header(lhs_data, rhs_data):
+ offset += COFF_HEADER_SIZE
+ else:
+ lhs.seek(0)
+ rhs.seek(0)
+
while True:
lhs_data = lhs.read(CHUNK_SIZE)
rhs_data = rhs.read(CHUNK_SIZE)
@@ -559,7 +586,7 @@ def compare_deps(first_dir, second_dir, targets):
second_file = os.path.join(second_dir, d)
result = compare_files(first_file, second_file)
if result:
- print('%-*s: %s' % (max_filepath_len, d, result))
+ print(' %-*s: %s' % (max_filepath_len, d, result))
def compare_build_artifacts(first_dir, second_dir, target_platform,
« 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