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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 file_len = os.stat(first_file).st_size | 88 file_len = os.stat(first_file).st_size |
89 difference = ('different size' if result == -1 else | 89 difference = '' |
90 '%d out of %d bytes are different (%.2f%%)' % | 90 if files_diffs == -1: |
91 (files_diffs, file_len, 100.0 * files_diffs / file_len)) | 91 difference = 'different size: %d != %d' % (file_len, |
| 92 os.stat(second_file).st_size) |
| 93 else: |
| 94 difference = '%d out of %d bytes are different (%.2f%%)' % ( |
| 95 files_diffs, file_len, 100.0 * files_diffs / file_len) |
92 result = 'DIFFERENT: %s' % difference | 96 result = 'DIFFERENT: %s' % difference |
93 res += 1 | 97 res += 1 |
94 print('%-*s: %s' % (max_filepath_len, f, result)) | 98 print('%-*s: %s' % (max_filepath_len, f, result)) |
95 | 99 |
96 print '%d files are equal, %d are different.' % ( | 100 print '%d files are equal, %d are different.' % ( |
97 len(first_list & second_list) - res, res) | 101 len(first_list & second_list) - res, res) |
98 | 102 |
99 return 0 if res == 0 else 1 | 103 return 0 if res == 0 else 1 |
100 | 104 |
101 | 105 |
102 def main(): | 106 def main(): |
103 parser = optparse.OptionParser(usage='%prog [options]') | 107 parser = optparse.OptionParser(usage='%prog [options]') |
104 parser.add_option('--first-build-dir', help='The first build directory.') | 108 parser.add_option('--first-build-dir', help='The first build directory.') |
105 parser.add_option('--second-build-dir', help='The second build directory.') | 109 parser.add_option('--second-build-dir', help='The second build directory.') |
106 options, _ = parser.parse_args() | 110 options, _ = parser.parse_args() |
107 | 111 |
108 if not options.first_build_dir: | 112 if not options.first_build_dir: |
109 parser.error('--first-build-dir is required') | 113 parser.error('--first-build-dir is required') |
110 if not options.second_build_dir: | 114 if not options.second_build_dir: |
111 parser.error('--second-build-dir is required') | 115 parser.error('--second-build-dir is required') |
112 | 116 |
113 return compare_build_artifacts(options.first_build_dir, | 117 return compare_build_artifacts(options.first_build_dir, |
114 options.second_build_dir) | 118 options.second_build_dir) |
115 | 119 |
116 | 120 |
117 if __name__ == '__main__': | 121 if __name__ == '__main__': |
118 sys.exit(main()) | 122 sys.exit(main()) |
OLD | NEW |