blob: dd9745e80c03b7cb4427abcf6976ca54e252cace [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>
7
8import sys
9import os
10import optparse
11from distutils.version import LooseVersion
12
13# Ensure PythonGit is installed (buildhistory_analysis needs it)
14try:
15 import git
16except ImportError:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060017 print("Please install GitPython (python3-git) 0.3.4 or later in order to use this script")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018 sys.exit(1)
19
20def main():
21 parser = optparse.OptionParser(
22 description = "Reports significant differences in the buildhistory repository.",
23 usage = """
24 %prog [options] [from-revision [to-revision]]
25(if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""")
26
27 parser.add_option("-p", "--buildhistory-dir",
28 help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)",
29 action="store", dest="buildhistory_dir", default='buildhistory/')
30 parser.add_option("-v", "--report-version",
31 help = "Report changes in PKGE/PKGV/PKGR even when the values are still the default (PE/PV/PR)",
32 action="store_true", dest="report_ver", default=False)
33 parser.add_option("-a", "--report-all",
34 help = "Report all changes, not just the default significant ones",
35 action="store_true", dest="report_all", default=False)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036 parser.add_option("-s", "--signatures",
37 help = "Report list of signatures differing instead of output",
38 action="store_true", dest="sigs", default=False)
39 parser.add_option("-S", "--signatures-with-diff",
40 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)",
41 action="store_true", dest="sigsdiff", default=False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
43 options, args = parser.parse_args(sys.argv)
44
45 if len(args) > 3:
46 sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[3:]))
47 parser.print_help()
48 sys.exit(1)
49
50 if LooseVersion(git.__version__) < '0.3.1':
51 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")
52 sys.exit(1)
53
54 if not os.path.exists(options.buildhistory_dir):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055 if options.buildhistory_dir == 'buildhistory/':
56 cwd = os.getcwd()
57 if os.path.basename(cwd) == 'buildhistory':
58 options.buildhistory_dir = cwd
59 if not os.path.exists(options.buildhistory_dir):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
61 parser.print_help()
62 sys.exit(1)
63
64 scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
65 lib_path = scripts_path + '/lib'
66 sys.path = sys.path + [lib_path]
67
68 import scriptpath
69
70 # Set path to OE lib dir so we can import the buildhistory_analysis module
71 scriptpath.add_oe_lib_path()
72 # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
73 bitbakepath = scriptpath.add_bitbake_lib_path()
74 if not bitbakepath:
75 sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
76 sys.exit(1)
77
78 import oe.buildhistory_analysis
79
80 fromrev = 'build-minus-1'
81 torev = 'HEAD'
82 if len(args) > 1:
83 if len(args) == 2 and '..' in args[1]:
84 revs = args[1].split('..')
85 fromrev = revs[0]
86 if revs[1]:
87 torev = revs[1]
88 else:
89 fromrev = args[1]
90 if len(args) > 2:
91 torev = args[2]
92
93 import gitdb
94 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050095 changes = oe.buildhistory_analysis.process_changes(options.buildhistory_dir, fromrev, torev, options.report_all, options.report_ver, options.sigs, options.sigsdiff)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096 except gitdb.exc.BadObject as e:
97 if len(args) == 1:
98 sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
99 parser.print_help()
100 else:
101 sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
102 sys.exit(1)
103
104 for chg in changes:
105 print('%s' % chg)
106
107 sys.exit(0)
108
109
110if __name__ == "__main__":
111 main()