Index: tools/determinism/compare_build_artifacts.py |
diff --git a/tools/determinism/compare_build_artifacts.py b/tools/determinism/compare_build_artifacts.py |
index 57bb236e8541f0335cd3c06733820837e0998e78..87e55731906ff6f910d5c32e3dfbdc06243b6731 100755 |
--- a/tools/determinism/compare_build_artifacts.py |
+++ b/tools/determinism/compare_build_artifacts.py |
@@ -9,6 +9,8 @@ import difflib |
import json |
import optparse |
import os |
+import re |
+import subprocess |
import struct |
import sys |
import time |
@@ -495,6 +497,46 @@ def compare_files(first_filepath, second_filepath): |
return diff_binary(first_filepath, second_filepath, file_len) |
+def get_deps(build_dir, target): |
+ """Returns list of object files needed to build target.""" |
+ NODE_PATTERN = re.compile(r'label="([a-zA-Z0-9_\\/.-]+)"') |
+ CHECK_EXTS = ('.o', '.obj') |
+ try: |
+ out = subprocess.check_output(['ninja', '-C', build_dir, |
M-A Ruel
2016/08/24 18:47:27
There's a problem as the directory was renamed, so
Yoshisato Yanagisawa
2016/08/25 08:47:29
I have never seen absolute object file path names
M-A Ruel
2016/08/25 15:46:26
zforman@ worked on making this work on linux but t
Yoshisato Yanagisawa
2016/08/29 05:44:49
I checked the code seems to work on Win.
|
+ '-t', 'graph', target]) |
+ except subprocess.CalledProcessError as e: |
+ print >> sys.stderr, 'error to get graph for %s: %s' % (target, e) |
+ return [] |
+ files = [] |
+ for line in out.splitlines(): |
+ matched = NODE_PATTERN.search(line) |
+ if matched: |
+ path = matched.group(1) |
+ if not os.path.splitext(path)[1] in CHECK_EXTS: |
+ continue |
+ files.append(path) |
+ return files |
+ |
+ |
+def compare_deps(first_dir, second_dir, targets): |
+ """Print difference of dependent files.""" |
+ for target in targets: |
+ print 'Checking %s difference:' % target |
+ first_deps = get_deps(first_dir, target) |
+ second_deps = get_deps(second_dir, target) |
+ deps = set(first_deps).union(set(second_deps)) |
M-A Ruel
2016/08/24 18:47:27
the difference should be empty ?
Yoshisato Yanagisawa
2016/08/25 08:47:29
I am not confident. However, I will simplify the
M-A Ruel
2016/08/25 15:46:26
I guess my question was more to print out the diff
Yoshisato Yanagisawa
2016/08/29 05:44:49
I think current code still help us to find this ki
|
+ for d in deps: |
+ first_file = os.path.join(first_dir, d) |
+ second_file = os.path.join(second_dir, d) |
+ if not os.path.exists(first_file): |
+ print '%s: not found' % first_file |
+ continue |
+ if not os.path.exists(second_file): |
+ print '%s: not found' % second_file |
+ continue |
+ compare_files(first_file, second_file) |
+ |
+ |
def compare_build_artifacts(first_dir, second_dir, target_platform, |
recursive=False): |
"""Compares the artifacts from two distinct builds.""" |
@@ -561,6 +603,11 @@ def compare_build_artifacts(first_dir, second_dir, target_platform, |
for u in unexpected_equals: |
print(' %s' % u) |
+ if unexpected_diffs: |
+ diffs_to_investigate = set(unexpected_diffs).difference( |
+ set(missing_files)) |
+ compare_deps(first_dir, second_dir, diffs_to_investigate) |
+ |
return int(bool(unexpected_diffs)) |
@@ -575,7 +622,7 @@ def main(): |
target = { |
'darwin': 'mac', 'linux2': 'linux', 'win32': 'win' |
}.get(sys.platform, sys.platform) |
- parser.add_option('-t', '--target-platform', help='The target platform.' |
+ parser.add_option('-t', '--target-platform', help='The target platform.', |
default=target, choices=('android', 'mac', 'linux', 'win')) |
options, _ = parser.parse_args() |