blob: c4d203ff4d950eff187a95c045e56b41591c03bf [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002#
3# Collects the recorded SRCREV values from buildhistory and reports on them
4#
5# Copyright 2013 Intel Corporation
6# Authored-by: Paul Eggleton <paul.eggleton@intel.com>
7#
Brad Bishopc342db32019-05-15 21:57:59 -04008# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009#
Patrick Williamsc124f4f2015-09-15 14:41:29 -050010
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050011import collections
12import os
13import sys
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014import optparse
15import logging
16
17def logger_create():
18 logger = logging.getLogger("buildhistory")
19 loggerhandler = logging.StreamHandler()
20 loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
21 logger.addHandler(loggerhandler)
22 logger.setLevel(logging.INFO)
23 return logger
24
25logger = logger_create()
26
27def main():
28 parser = optparse.OptionParser(
29 description = "Collects the recorded SRCREV values from buildhistory and reports on them.",
30 usage = """
31 %prog [options]""")
32
33 parser.add_option("-a", "--report-all",
34 help = "Report all SRCREV values, not just ones where AUTOREV has been used",
35 action="store_true", dest="reportall")
36 parser.add_option("-f", "--forcevariable",
37 help = "Use forcevariable override for all output lines",
38 action="store_true", dest="forcevariable")
39 parser.add_option("-p", "--buildhistory-dir",
40 help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)",
41 action="store", dest="buildhistory_dir", default='buildhistory/')
42
43 options, args = parser.parse_args(sys.argv)
44
45 if len(args) > 1:
46 sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[1:]))
47 parser.print_help()
48 sys.exit(1)
49
50 if not os.path.exists(options.buildhistory_dir):
51 sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
52 parser.print_help()
53 sys.exit(1)
54
55 if options.forcevariable:
56 forcevariable = '_forcevariable'
57 else:
58 forcevariable = ''
59
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050060 all_srcrevs = collections.defaultdict(list)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061 for root, dirs, files in os.walk(options.buildhistory_dir):
62 if '.git' in dirs:
63 dirs.remove('.git')
64 for fn in files:
65 if fn == 'latest_srcrev':
66 curdir = os.path.basename(os.path.dirname(root))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067 fullpath = os.path.join(root, fn)
68 pn = os.path.basename(root)
69 srcrev = None
70 orig_srcrev = None
71 orig_srcrevs = {}
72 srcrevs = {}
73 with open(fullpath) as f:
74 for line in f:
75 if '=' in line:
76 splitval = line.split('=')
77 value = splitval[1].strip('" \t\n\r')
78 if line.startswith('# SRCREV = '):
79 orig_srcrev = value
80 elif line.startswith('# SRCREV_'):
81 splitval = line.split('=')
82 name = splitval[0].split('_')[1].strip()
83 orig_srcrevs[name] = value
84 elif line.startswith('SRCREV ='):
85 srcrev = value
86 elif line.startswith('SRCREV_'):
87 name = splitval[0].split('_')[1].strip()
88 srcrevs[name] = value
89 if srcrev and (options.reportall or srcrev != orig_srcrev):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050090 all_srcrevs[curdir].append((pn, None, srcrev))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 for name, value in srcrevs.items():
92 orig = orig_srcrevs.get(name, orig_srcrev)
93 if options.reportall or value != orig:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 all_srcrevs[curdir].append((pn, name, value))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050095
Patrick Williamsc0f7c042017-02-23 20:41:17 -060096 for curdir, srcrevs in sorted(all_srcrevs.items()):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050097 if srcrevs:
98 print('# %s' % curdir)
99 for pn, name, srcrev in srcrevs:
100 if name:
101 print('SRCREV_%s_pn-%s%s = "%s"' % (name, pn, forcevariable, srcrev))
102 else:
103 print('SRCREV_pn-%s%s = "%s"' % (pn, forcevariable, srcrev))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104
105
106if __name__ == "__main__":
107 main()