| 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 difflib | 8 import difflib |
| 9 import json | 9 import json |
| 10 import optparse | 10 import optparse |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 max_filepath_len = max(len(n) for n in first_deps) | 586 max_filepath_len = max(len(n) for n in first_deps) |
| 587 for d in first_deps: | 587 for d in first_deps: |
| 588 first_file = os.path.join(first_dir, d) | 588 first_file = os.path.join(first_dir, d) |
| 589 second_file = os.path.join(second_dir, d) | 589 second_file = os.path.join(second_dir, d) |
| 590 result = compare_files(first_file, second_file) | 590 result = compare_files(first_file, second_file) |
| 591 if result: | 591 if result: |
| 592 print(' %-*s: %s' % (max_filepath_len, d, result)) | 592 print(' %-*s: %s' % (max_filepath_len, d, result)) |
| 593 | 593 |
| 594 | 594 |
| 595 def compare_build_artifacts(first_dir, second_dir, target_platform, | 595 def compare_build_artifacts(first_dir, second_dir, target_platform, |
| 596 recursive=False): | 596 json_output, recursive=False): |
| 597 """Compares the artifacts from two distinct builds.""" | 597 """Compares the artifacts from two distinct builds.""" |
| 598 if not os.path.isdir(first_dir): | 598 if not os.path.isdir(first_dir): |
| 599 print >> sys.stderr, '%s isn\'t a valid directory.' % first_dir | 599 print >> sys.stderr, '%s isn\'t a valid directory.' % first_dir |
| 600 return 1 | 600 return 1 |
| 601 if not os.path.isdir(second_dir): | 601 if not os.path.isdir(second_dir): |
| 602 print >> sys.stderr, '%s isn\'t a valid directory.' % second_dir | 602 print >> sys.stderr, '%s isn\'t a valid directory.' % second_dir |
| 603 return 1 | 603 return 1 |
| 604 | 604 |
| 605 epoch_hex = struct.pack('<I', int(time.time())).encode('hex') | 605 epoch_hex = struct.pack('<I', int(time.time())).encode('hex') |
| 606 print('Epoch: %s' % | 606 print('Epoch: %s' % |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 print(' %s' % u) | 655 print(' %s' % u) |
| 656 if unexpected_equals: | 656 if unexpected_equals: |
| 657 print('Unexpected files with no diffs:\n') | 657 print('Unexpected files with no diffs:\n') |
| 658 for u in unexpected_equals: | 658 for u in unexpected_equals: |
| 659 print(' %s' % u) | 659 print(' %s' % u) |
| 660 | 660 |
| 661 all_diffs = expected_diffs + unexpected_diffs | 661 all_diffs = expected_diffs + unexpected_diffs |
| 662 diffs_to_investigate = sorted(set(all_diffs).difference(missing_files)) | 662 diffs_to_investigate = sorted(set(all_diffs).difference(missing_files)) |
| 663 compare_deps(first_dir, second_dir, diffs_to_investigate) | 663 compare_deps(first_dir, second_dir, diffs_to_investigate) |
| 664 | 664 |
| 665 if json_output: |
| 666 try: |
| 667 out = { |
| 668 'expected_diffs': expected_diffs, |
| 669 'unexpected_diffs': unexpected_diffs, |
| 670 } |
| 671 with open(json_output) as f: |
| 672 json.dump(out, f) |
| 673 except Exception as e: |
| 674 print('failed to write json output: %s' % e) |
| 675 |
| 665 return int(bool(unexpected_diffs)) | 676 return int(bool(unexpected_diffs)) |
| 666 | 677 |
| 667 | 678 |
| 668 def main(): | 679 def main(): |
| 669 parser = optparse.OptionParser(usage='%prog [options]') | 680 parser = optparse.OptionParser(usage='%prog [options]') |
| 670 parser.add_option( | 681 parser.add_option( |
| 671 '-f', '--first-build-dir', help='The first build directory.') | 682 '-f', '--first-build-dir', help='The first build directory.') |
| 672 parser.add_option( | 683 parser.add_option( |
| 673 '-s', '--second-build-dir', help='The second build directory.') | 684 '-s', '--second-build-dir', help='The second build directory.') |
| 674 parser.add_option('-r', '--recursive', action='store_true', default=False, | 685 parser.add_option('-r', '--recursive', action='store_true', default=False, |
| 675 help='Indicates if the comparison should be recursive.') | 686 help='Indicates if the comparison should be recursive.') |
| 687 parser.add_option('--json-output', help='JSON file to output differences') |
| 676 target = { | 688 target = { |
| 677 'darwin': 'mac', 'linux2': 'linux', 'win32': 'win' | 689 'darwin': 'mac', 'linux2': 'linux', 'win32': 'win' |
| 678 }.get(sys.platform, sys.platform) | 690 }.get(sys.platform, sys.platform) |
| 679 parser.add_option('-t', '--target-platform', help='The target platform.', | 691 parser.add_option('-t', '--target-platform', help='The target platform.', |
| 680 default=target, choices=('android', 'mac', 'linux', 'win')) | 692 default=target, choices=('android', 'mac', 'linux', 'win')) |
| 681 options, _ = parser.parse_args() | 693 options, _ = parser.parse_args() |
| 682 | 694 |
| 683 if not options.first_build_dir: | 695 if not options.first_build_dir: |
| 684 parser.error('--first-build-dir is required') | 696 parser.error('--first-build-dir is required') |
| 685 if not options.second_build_dir: | 697 if not options.second_build_dir: |
| 686 parser.error('--second-build-dir is required') | 698 parser.error('--second-build-dir is required') |
| 687 if not options.target_platform: | 699 if not options.target_platform: |
| 688 parser.error('--target-platform is required') | 700 parser.error('--target-platform is required') |
| 689 | 701 |
| 690 return compare_build_artifacts(os.path.abspath(options.first_build_dir), | 702 return compare_build_artifacts(os.path.abspath(options.first_build_dir), |
| 691 os.path.abspath(options.second_build_dir), | 703 os.path.abspath(options.second_build_dir), |
| 692 options.target_platform, | 704 options.target_platform, |
| 705 options.json_output, |
| 693 options.recursive) | 706 options.recursive) |
| 694 | 707 |
| 695 | 708 |
| 696 if __name__ == '__main__': | 709 if __name__ == '__main__': |
| 697 sys.exit(main()) | 710 sys.exit(main()) |
| OLD | NEW |