Chromium Code Reviews| 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 filecmp | 7 import filecmp |
| 8 import json | 8 import json |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 blacklist = frozenset(json.load(f)) | 46 blacklist = frozenset(json.load(f)) |
| 47 | 47 |
| 48 res = 0 | 48 res = 0 |
| 49 first_list = get_files_to_compare(first_dir) - blacklist | 49 first_list = get_files_to_compare(first_dir) - blacklist |
| 50 second_list = get_files_to_compare(second_dir) - blacklist | 50 second_list = get_files_to_compare(second_dir) - blacklist |
| 51 | 51 |
| 52 diff = first_list.symmetric_difference(second_list) | 52 diff = first_list.symmetric_difference(second_list) |
| 53 if diff: | 53 if diff: |
| 54 print >> sys.stderr, 'Different list of files in both directories' | 54 print >> sys.stderr, 'Different list of files in both directories' |
| 55 print >> sys.stderr, '\n'.join(' ' + i for i in sorted(diff)) | 55 print >> sys.stderr, '\n'.join(' ' + i for i in sorted(diff)) |
| 56 res = 1 | 56 res += len(diff) |
| 57 | 57 |
| 58 for f in sorted(first_list & second_list): | 58 for f in sorted(first_list & second_list): |
| 59 first_file = os.path.join(first_dir, f) | 59 first_file = os.path.join(first_dir, f) |
| 60 second_file = os.path.join(second_dir, f) | 60 second_file = os.path.join(second_dir, f) |
| 61 if filecmp.cmp(first_file, second_file, shallow=False): | 61 if filecmp.cmp(first_file, second_file, shallow=False): |
| 62 print('%s: equal' % f) | 62 print('%s: equal' % f) |
| 63 else: | 63 else: |
| 64 print('%s: DIFFERENT' % f) | 64 print('%s: DIFFERENT' % f) |
| 65 res = 1 | 65 res += 1 |
| 66 | 66 |
| 67 return res | 67 print '%d files are equal, %d are different.' % ( |
| 68 len(first_list & second_list), res) | |
|
M-A Ruel
2014/10/28 20:31:56
calculation is wrong
Sébastien Marchand
2014/10/28 20:36:57
Oops, forgot to save my changes before uploading..
| |
| 69 | |
| 70 return 0 if res == 0 else 1 | |
| 68 | 71 |
| 69 | 72 |
| 70 def main(): | 73 def main(): |
| 71 parser = optparse.OptionParser(usage='%prog [options]') | 74 parser = optparse.OptionParser(usage='%prog [options]') |
| 72 parser.add_option('--first-build-dir', help='The first build directory.') | 75 parser.add_option('--first-build-dir', help='The first build directory.') |
| 73 parser.add_option('--second-build-dir', help='The second build directory.') | 76 parser.add_option('--second-build-dir', help='The second build directory.') |
| 74 options, _ = parser.parse_args() | 77 options, _ = parser.parse_args() |
| 75 | 78 |
| 76 if not options.first_build_dir: | 79 if not options.first_build_dir: |
| 77 parser.error('--first-build-dir is required') | 80 parser.error('--first-build-dir is required') |
| 78 if not options.second_build_dir: | 81 if not options.second_build_dir: |
| 79 parser.error('--second-build-dir is required') | 82 parser.error('--second-build-dir is required') |
| 80 | 83 |
| 81 return compare_build_artifacts(options.first_build_dir, | 84 return compare_build_artifacts(options.first_build_dir, |
| 82 options.second_build_dir) | 85 options.second_build_dir) |
| 83 | 86 |
| 84 | 87 |
| 85 if __name__ == '__main__': | 88 if __name__ == '__main__': |
| 86 sys.exit(main()) | 89 sys.exit(main()) |
| OLD | NEW |