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