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 """Compare the artifacts from two builds.""" | 5 """Compare the artifacts from two builds.""" |
6 | 6 |
7 import json | 7 import json |
8 import optparse | 8 import optparse |
9 import os | 9 import os |
10 import sys | 10 import sys |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 res += len(diff) | 78 res += len(diff) |
79 | 79 |
80 max_filepath_len = max(len(n) for n in first_list & second_list) | 80 max_filepath_len = max(len(n) for n in first_list & second_list) |
81 for f in sorted(first_list & second_list): | 81 for f in sorted(first_list & second_list): |
82 first_file = os.path.join(first_dir, f) | 82 first_file = os.path.join(first_dir, f) |
83 second_file = os.path.join(second_dir, f) | 83 second_file = os.path.join(second_dir, f) |
84 files_diffs = compare_files(first_file, second_file) | 84 files_diffs = compare_files(first_file, second_file) |
85 if not files_diffs: | 85 if not files_diffs: |
86 result = 'equal' | 86 result = 'equal' |
87 else: | 87 else: |
88 result = 'DIFFERENT: %s' % ('different size' if result == -1 else | 88 file_len = os.stat(first_file).st_size |
89 '%d different bytes' % files_diffs) | 89 difference = ('different size' if result == -1 else |
| 90 '%d out of %d bytes are different (%.2f%%)' % |
| 91 (files_diffs, file_len, 100.0 * files_diffs / file_len)) |
| 92 result = 'DIFFERENT: %s' % difference |
90 res += 1 | 93 res += 1 |
91 print('%-*s: %s' % (max_filepath_len, f, result)) | 94 print('%-*s: %s' % (max_filepath_len, f, result)) |
92 | 95 |
93 print '%d files are equal, %d are different.' % ( | 96 print '%d files are equal, %d are different.' % ( |
94 len(first_list & second_list) - res, res) | 97 len(first_list & second_list) - res, res) |
95 | 98 |
96 return 0 if res == 0 else 1 | 99 return 0 if res == 0 else 1 |
97 | 100 |
98 | 101 |
99 def main(): | 102 def main(): |
100 parser = optparse.OptionParser(usage='%prog [options]') | 103 parser = optparse.OptionParser(usage='%prog [options]') |
101 parser.add_option('--first-build-dir', help='The first build directory.') | 104 parser.add_option('--first-build-dir', help='The first build directory.') |
102 parser.add_option('--second-build-dir', help='The second build directory.') | 105 parser.add_option('--second-build-dir', help='The second build directory.') |
103 options, _ = parser.parse_args() | 106 options, _ = parser.parse_args() |
104 | 107 |
105 if not options.first_build_dir: | 108 if not options.first_build_dir: |
106 parser.error('--first-build-dir is required') | 109 parser.error('--first-build-dir is required') |
107 if not options.second_build_dir: | 110 if not options.second_build_dir: |
108 parser.error('--second-build-dir is required') | 111 parser.error('--second-build-dir is required') |
109 | 112 |
110 return compare_build_artifacts(options.first_build_dir, | 113 return compare_build_artifacts(options.first_build_dir, |
111 options.second_build_dir) | 114 options.second_build_dir) |
112 | 115 |
113 | 116 |
114 if __name__ == '__main__': | 117 if __name__ == '__main__': |
115 sys.exit(main()) | 118 sys.exit(main()) |
OLD | NEW |