Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | # Report significant differences in the buildhistory repository since a specific revision |
| 4 | # |
| 5 | # Copyright (C) 2013 Intel Corporation |
| 6 | # Author: Paul Eggleton <paul.eggleton@linux.intel.com> |
| 7 | |
| 8 | import sys |
| 9 | import os |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | import argparse |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | from distutils.version import LooseVersion |
| 12 | |
| 13 | # Ensure PythonGit is installed (buildhistory_analysis needs it) |
| 14 | try: |
| 15 | import git |
| 16 | except ImportError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 17 | print("Please install GitPython (python3-git) 0.3.4 or later in order to use this script") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | sys.exit(1) |
| 19 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 20 | def get_args_parser(): |
| 21 | description = "Reports significant differences in the buildhistory repository." |
| 22 | |
| 23 | parser = argparse.ArgumentParser(description=description, |
| 24 | usage=""" |
| 25 | %(prog)s [options] [from-revision [to-revision]] |
| 26 | (if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""") |
| 27 | |
| 28 | parser.add_argument('-p', '--buildhistory-dir', |
| 29 | action='store', |
| 30 | dest='buildhistory_dir', |
| 31 | default='buildhistory/', |
| 32 | help="Specify path to buildhistory directory (defaults to buildhistory/ under cwd)") |
| 33 | parser.add_argument('-v', '--report-version', |
| 34 | action='store_true', |
| 35 | dest='report_ver', |
| 36 | default=False, |
| 37 | help="Report changes in PKGE/PKGV/PKGR even when the values are still the default (PE/PV/PR)") |
| 38 | parser.add_argument('-a', '--report-all', |
| 39 | action='store_true', |
| 40 | dest='report_all', |
| 41 | default='False', |
| 42 | help="Report all changes, not just the default significant ones") |
| 43 | parser.add_argument('-s', '---signatures', |
| 44 | action='store_true', |
| 45 | dest='sigs', |
| 46 | default=False, |
| 47 | help="Report list of signatures differing instead of output") |
| 48 | parser.add_argument('-S', '--signatures-with-diff', |
| 49 | action='store_true', |
| 50 | dest='sigsdiff', |
| 51 | default=False, |
| 52 | help="Report on actual signature differences instead of output (requires signature data to have been generated, either by running the actual tasks or using bitbake -S)") |
| 53 | parser.add_argument('-e', '--exclude-path', |
| 54 | action='append', |
| 55 | help="Exclude path from the output") |
| 56 | parser.add_argument('revisions', |
| 57 | default = ['build-minus-1', 'HEAD'], |
| 58 | nargs='*', |
| 59 | help=argparse.SUPPRESS) |
| 60 | return parser |
| 61 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | def main(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | parser = get_args_parser() |
| 65 | args = parser.parse_args() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | |
| 67 | if LooseVersion(git.__version__) < '0.3.1': |
| 68 | sys.stderr.write("Version of GitPython is too old, please install GitPython (python-git) 0.3.1 or later in order to use this script\n") |
| 69 | sys.exit(1) |
| 70 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | if len(args.revisions) > 2: |
| 72 | sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args.revisions[2:])) |
| 73 | parser.print_help() |
| 74 | |
| 75 | sys.exit(1) |
| 76 | if not os.path.exists(args.buildhistory_dir): |
| 77 | if args.buildhistory_dir == 'buildhistory/': |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 78 | cwd = os.getcwd() |
| 79 | if os.path.basename(cwd) == 'buildhistory': |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 80 | args.buildhistory_dir = cwd |
| 81 | |
| 82 | if not os.path.exists(args.buildhistory_dir): |
| 83 | sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % args.buildhistory_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | parser.print_help() |
| 85 | sys.exit(1) |
| 86 | |
| 87 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) |
| 88 | lib_path = scripts_path + '/lib' |
| 89 | sys.path = sys.path + [lib_path] |
| 90 | |
| 91 | import scriptpath |
| 92 | |
| 93 | # Set path to OE lib dir so we can import the buildhistory_analysis module |
| 94 | scriptpath.add_oe_lib_path() |
| 95 | # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils |
| 96 | bitbakepath = scriptpath.add_bitbake_lib_path() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 97 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 | if not bitbakepath: |
| 99 | sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n") |
| 100 | sys.exit(1) |
| 101 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 102 | if len(args.revisions) == 1: |
| 103 | if '..' in args.revisions[0]: |
| 104 | fromrev, torev = args.revisions[0].split('..') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 106 | fromrev, torev = args.revisions[0], 'HEAD' |
| 107 | elif len(args.revisions) == 2: |
| 108 | fromrev, torev = args.revisions |
| 109 | |
| 110 | from oe.buildhistory_analysis import process_changes |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 111 | |
| 112 | import gitdb |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 113 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | try: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 115 | changes = process_changes(args.buildhistory_dir, fromrev, torev, |
| 116 | args.report_all, args.report_ver, args.sigs, |
| 117 | args.sigsdiff, args.exclude_path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 118 | except gitdb.exc.BadObject as e: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 119 | if not args.revisions: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 120 | sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n") |
| 121 | parser.print_help() |
| 122 | else: |
| 123 | sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0]) |
| 124 | sys.exit(1) |
| 125 | |
| 126 | for chg in changes: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 127 | out = str(chg) |
| 128 | if out: |
| 129 | print(out) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | |
| 131 | sys.exit(0) |
| 132 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | if __name__ == "__main__": |
| 134 | main() |