blob: 70805b0678b4ebb152ddb26cd4d72e5288df7212 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#!/usr/bin/env python3
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
8import sys
9import os
10import argparse
11from distutils.version import LooseVersion
12
13# Ensure PythonGit is installed (buildhistory_analysis needs it)
14try:
15 import git
16except ImportError:
17 print("Please install GitPython (python3-git) 0.3.4 or later in order to use this script")
18 sys.exit(1)
19
20def 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('-c', '--colour',
57 choices=('yes', 'no', 'auto'),
58 default="auto",
59 help="Whether to colourise (defaults to auto)")
60 parser.add_argument('revisions',
61 default = ['build-minus-1', 'HEAD'],
62 nargs='*',
63 help=argparse.SUPPRESS)
64 return parser
65
66def main():
67
68 parser = get_args_parser()
69 args = parser.parse_args()
70
71 if LooseVersion(git.__version__) < '0.3.1':
72 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")
73 sys.exit(1)
74
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)
80 if not os.path.exists(args.buildhistory_dir):
81 if args.buildhistory_dir == 'buildhistory/':
82 cwd = os.getcwd()
83 if os.path.basename(cwd) == 'buildhistory':
84 args.buildhistory_dir = cwd
85
86 if not os.path.exists(args.buildhistory_dir):
87 sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % args.buildhistory_dir)
88 parser.print_help()
89 sys.exit(1)
90
91 scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
92 lib_path = scripts_path + '/lib'
93 sys.path = sys.path + [lib_path]
94
95 import scriptpath
96
97 # Set path to OE lib dir so we can import the buildhistory_analysis module
98 scriptpath.add_oe_lib_path()
99 # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
100 bitbakepath = scriptpath.add_bitbake_lib_path()
101
102 if not bitbakepath:
103 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
104 sys.exit(1)
105
106 if len(args.revisions) == 1:
107 if '..' in args.revisions[0]:
108 fromrev, torev = args.revisions[0].split('..')
109 else:
110 fromrev, torev = args.revisions[0], 'HEAD'
111 elif len(args.revisions) == 2:
112 fromrev, torev = args.revisions
113
114 from oe.buildhistory_analysis import init_colours, process_changes
115 import gitdb
116
117 init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour])
118
119 try:
120 changes = process_changes(args.buildhistory_dir, fromrev, torev,
121 args.report_all, args.report_ver, args.sigs,
122 args.sigsdiff, args.exclude_path)
123 except gitdb.exc.BadObject as e:
124 if not args.revisions:
125 sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
126 parser.print_help()
127 else:
128 sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
129 sys.exit(1)
130
131 for chg in changes:
132 out = str(chg)
133 if out:
134 print(out)
135
136 sys.exit(0)
137
138if __name__ == "__main__":
139 main()