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> |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 7 | # |
| 8 | # SPDX-License-Identifier: GPL-2.0-only |
| 9 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
| 11 | import sys |
| 12 | import os |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 13 | import argparse |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 14 | from distutils.version import LooseVersion |
| 15 | |
| 16 | # Ensure PythonGit is installed (buildhistory_analysis needs it) |
| 17 | try: |
| 18 | import git |
| 19 | except ImportError: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 20 | 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] | 21 | sys.exit(1) |
| 22 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | def get_args_parser(): |
| 24 | description = "Reports significant differences in the buildhistory repository." |
| 25 | |
| 26 | parser = argparse.ArgumentParser(description=description, |
| 27 | usage=""" |
| 28 | %(prog)s [options] [from-revision [to-revision]] |
| 29 | (if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""") |
| 30 | |
| 31 | parser.add_argument('-p', '--buildhistory-dir', |
| 32 | action='store', |
| 33 | dest='buildhistory_dir', |
| 34 | default='buildhistory/', |
| 35 | help="Specify path to buildhistory directory (defaults to buildhistory/ under cwd)") |
| 36 | parser.add_argument('-v', '--report-version', |
| 37 | action='store_true', |
| 38 | dest='report_ver', |
| 39 | default=False, |
| 40 | help="Report changes in PKGE/PKGV/PKGR even when the values are still the default (PE/PV/PR)") |
| 41 | parser.add_argument('-a', '--report-all', |
| 42 | action='store_true', |
| 43 | dest='report_all', |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 44 | default=False, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 45 | help="Report all changes, not just the default significant ones") |
| 46 | parser.add_argument('-s', '---signatures', |
| 47 | action='store_true', |
| 48 | dest='sigs', |
| 49 | default=False, |
| 50 | help="Report list of signatures differing instead of output") |
| 51 | parser.add_argument('-S', '--signatures-with-diff', |
| 52 | action='store_true', |
| 53 | dest='sigsdiff', |
| 54 | default=False, |
| 55 | 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)") |
| 56 | parser.add_argument('-e', '--exclude-path', |
| 57 | action='append', |
| 58 | help="Exclude path from the output") |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 59 | parser.add_argument('-c', '--colour', |
| 60 | choices=('yes', 'no', 'auto'), |
| 61 | default="auto", |
| 62 | help="Whether to colourise (defaults to auto)") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 63 | parser.add_argument('revisions', |
| 64 | default = ['build-minus-1', 'HEAD'], |
| 65 | nargs='*', |
| 66 | help=argparse.SUPPRESS) |
| 67 | return parser |
| 68 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | def main(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 71 | parser = get_args_parser() |
| 72 | args = parser.parse_args() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 73 | |
| 74 | if LooseVersion(git.__version__) < '0.3.1': |
| 75 | 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") |
| 76 | sys.exit(1) |
| 77 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 78 | if len(args.revisions) > 2: |
| 79 | sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args.revisions[2:])) |
| 80 | parser.print_help() |
| 81 | |
| 82 | sys.exit(1) |
| 83 | if not os.path.exists(args.buildhistory_dir): |
| 84 | if args.buildhistory_dir == 'buildhistory/': |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 85 | cwd = os.getcwd() |
| 86 | if os.path.basename(cwd) == 'buildhistory': |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 87 | args.buildhistory_dir = cwd |
| 88 | |
| 89 | if not os.path.exists(args.buildhistory_dir): |
| 90 | 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] | 91 | parser.print_help() |
| 92 | sys.exit(1) |
| 93 | |
| 94 | scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0]))) |
| 95 | lib_path = scripts_path + '/lib' |
| 96 | sys.path = sys.path + [lib_path] |
| 97 | |
| 98 | import scriptpath |
| 99 | |
| 100 | # Set path to OE lib dir so we can import the buildhistory_analysis module |
| 101 | scriptpath.add_oe_lib_path() |
| 102 | # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils |
| 103 | bitbakepath = scriptpath.add_bitbake_lib_path() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 104 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | if not bitbakepath: |
| 106 | sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n") |
| 107 | sys.exit(1) |
| 108 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 109 | if len(args.revisions) == 1: |
| 110 | if '..' in args.revisions[0]: |
| 111 | fromrev, torev = args.revisions[0].split('..') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 113 | fromrev, torev = args.revisions[0], 'HEAD' |
| 114 | elif len(args.revisions) == 2: |
| 115 | fromrev, torev = args.revisions |
| 116 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 117 | from oe.buildhistory_analysis import init_colours, process_changes |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 118 | import gitdb |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 119 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 120 | init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour]) |
| 121 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | try: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 123 | changes = process_changes(args.buildhistory_dir, fromrev, torev, |
| 124 | args.report_all, args.report_ver, args.sigs, |
| 125 | args.sigsdiff, args.exclude_path) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 126 | except gitdb.exc.BadObject as e: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 127 | if not args.revisions: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n") |
| 129 | parser.print_help() |
| 130 | else: |
| 131 | sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0]) |
| 132 | sys.exit(1) |
| 133 | |
| 134 | for chg in changes: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 135 | out = str(chg) |
| 136 | if out: |
| 137 | print(out) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | |
| 139 | sys.exit(0) |
| 140 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | if __name__ == "__main__": |
| 142 | main() |