blob: 833f7c33a5b7aa16db938056b4b2e065c3216348 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/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#
8# SPDX-License-Identifier: GPL-2.0-only
9#
10
11import sys
12import os
13import argparse
14from distutils.version import LooseVersion
15
16# Ensure PythonGit is installed (buildhistory_analysis needs it)
17try:
18 import git
19except ImportError:
20 print("Please install GitPython (python3-git) 0.3.4 or later in order to use this script")
21 sys.exit(1)
22
23def 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',
44 default=False,
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")
59 parser.add_argument('-c', '--colour',
60 choices=('yes', 'no', 'auto'),
61 default="auto",
62 help="Whether to colourise (defaults to auto)")
63 parser.add_argument('revisions',
64 default = ['build-minus-1', 'HEAD'],
65 nargs='*',
66 help=argparse.SUPPRESS)
67 return parser
68
69def main():
70
71 parser = get_args_parser()
72 args = parser.parse_args()
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
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/':
85 cwd = os.getcwd()
86 if os.path.basename(cwd) == 'buildhistory':
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)
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()
104
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
109 if len(args.revisions) == 1:
110 if '..' in args.revisions[0]:
111 fromrev, torev = args.revisions[0].split('..')
112 else:
113 fromrev, torev = args.revisions[0], 'HEAD'
114 elif len(args.revisions) == 2:
115 fromrev, torev = args.revisions
116
117 from oe.buildhistory_analysis import init_colours, process_changes
118 import gitdb
119
120 init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour])
121
122 try:
123 changes = process_changes(args.buildhistory_dir, fromrev, torev,
124 args.report_all, args.report_ver, args.sigs,
125 args.sigsdiff, args.exclude_path)
126 except gitdb.exc.BadObject as e:
127 if not args.revisions:
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:
135 out = str(chg)
136 if out:
137 print(out)
138
139 sys.exit(0)
140
141if __name__ == "__main__":
142 main()