OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """Compare the artifacts from two builds.""" | 6 """Compare the artifacts from two builds.""" |
7 | 7 |
8 import ast | 8 import ast |
9 import difflib | 9 import difflib |
10 import json | 10 import json |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 else: | 124 else: |
125 streams = None | 125 streams = None |
126 offset += len(lhs_data) | 126 offset += len(lhs_data) |
127 del lhs_data | 127 del lhs_data |
128 del rhs_data | 128 del rhs_data |
129 if not diffs: | 129 if not diffs: |
130 return None | 130 return None |
131 result = '%d out of %d bytes are different (%.2f%%)' % ( | 131 result = '%d out of %d bytes are different (%.2f%%)' % ( |
132 diffs, file_len, 100.0 * diffs / file_len) | 132 diffs, file_len, 100.0 * diffs / file_len) |
133 if streams: | 133 if streams: |
134 encode = lambda text: ''.join(i if 31 < ord(i) < 128 else '.' for i in text) | 134 encode = lambda text: ''.join(i if 31 < ord(i) < 127 else '.' for i in text) |
135 for offset, lhs_data, rhs_data in streams: | 135 for offset, lhs_data, rhs_data in streams: |
136 lhs_line = '%s \'%s\'' % (lhs_data.encode('hex'), encode(lhs_data)) | 136 lhs_line = '%s \'%s\'' % (lhs_data.encode('hex'), encode(lhs_data)) |
137 rhs_line = '%s \'%s\'' % (rhs_data.encode('hex'), encode(rhs_data)) | 137 rhs_line = '%s \'%s\'' % (rhs_data.encode('hex'), encode(rhs_data)) |
138 diff = list(difflib.Differ().compare([lhs_line], [rhs_line]))[-1][2:-1] | 138 diff = list(difflib.Differ().compare([lhs_line], [rhs_line]))[-1][2:-1] |
139 result += '\n 0x%-8x: %s\n %s\n %s' % ( | 139 result += '\n 0x%-8x: %s\n %s\n %s' % ( |
140 offset, lhs_line, rhs_line, diff) | 140 offset, lhs_line, rhs_line, diff) |
141 return result | 141 return result |
142 | 142 |
143 | 143 |
144 def compare_files(first_filepath, second_filepath): | 144 def compare_files(first_filepath, second_filepath): |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 342 |
343 return compare_build_artifacts(os.path.abspath(options.first_build_dir), | 343 return compare_build_artifacts(os.path.abspath(options.first_build_dir), |
344 os.path.abspath(options.second_build_dir), | 344 os.path.abspath(options.second_build_dir), |
345 options.target_platform, | 345 options.target_platform, |
346 options.json_output, | 346 options.json_output, |
347 options.recursive) | 347 options.recursive) |
348 | 348 |
349 | 349 |
350 if __name__ == '__main__': | 350 if __name__ == '__main__': |
351 sys.exit(main()) | 351 sys.exit(main()) |
OLD | NEW |