blob: 833f7c33a5b7aa16db938056b4b2e065c3216348 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
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 Bishopc342db32019-05-15 21:57:59 -04007#
8# SPDX-License-Identifier: GPL-2.0-only
9#
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010
11import sys
12import os
Brad Bishopd7bf8c12018-02-25 22:55:05 -050013import argparse
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014from distutils.version import LooseVersion
15
16# Ensure PythonGit is installed (buildhistory_analysis needs it)
17try:
18 import git
19except ImportError:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060020 print("Please install GitPython (python3-git) 0.3.4 or later in order to use this script")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021 sys.exit(1)
22
Brad Bishopd7bf8c12018-02-25 22:55:05 -050023def 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 Bishop316dfdd2018-06-25 12:45:53 -040044 default=False,
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 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 Bishop316dfdd2018-06-25 12:45:53 -040059 parser.add_argument('-c', '--colour',
60 choices=('yes', 'no', 'auto'),
61 default="auto",
62 help="Whether to colourise (defaults to auto)")
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063 parser.add_argument('revisions',
64 default = ['build-minus-1', 'HEAD'],
65 nargs='*',
66 help=argparse.SUPPRESS)
67 return parser
68
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069def main():
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
Brad Bishopd7bf8c12018-02-25 22:55:05 -050071 parser = get_args_parser()
72 args = parser.parse_args()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
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 Bishopd7bf8c12018-02-25 22:55:05 -050078 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 Bishop6e60e8b2018-02-01 10:27:11 -050085 cwd = os.getcwd()
86 if os.path.basename(cwd) == 'buildhistory':
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087 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 Williamsc124f4f2015-09-15 14:41:29 -050091 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 Bishopd7bf8c12018-02-25 22:55:05 -0500104
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 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 Bishopd7bf8c12018-02-25 22:55:05 -0500109 if len(args.revisions) == 1:
110 if '..' in args.revisions[0]:
111 fromrev, torev = args.revisions[0].split('..')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 else:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500113 fromrev, torev = args.revisions[0], 'HEAD'
114 elif len(args.revisions) == 2:
115 fromrev, torev = args.revisions
116
Brad Bishop316dfdd2018-06-25 12:45:53 -0400117 from oe.buildhistory_analysis import init_colours, process_changes
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500118 import gitdb
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500119
Brad Bishop316dfdd2018-06-25 12:45:53 -0400120 init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour])
121
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 try:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500123 changes = process_changes(args.buildhistory_dir, fromrev, torev,
124 args.report_all, args.report_ver, args.sigs,
125 args.sigsdiff, args.exclude_path)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 except gitdb.exc.BadObject as e:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500127 if not args.revisions:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 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 Bishopd7bf8c12018-02-25 22:55:05 -0500135 out = str(chg)
136 if out:
137 print(out)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138
139 sys.exit(0)
140
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141if __name__ == "__main__":
142 main()