blob: 58a270803254d98a132852d148017e175b9cd6fd [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#!/usr/bin/env python
2#
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#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21import os, sys
22import optparse
23import logging
24
25def logger_create():
26 logger = logging.getLogger("buildhistory")
27 loggerhandler = logging.StreamHandler()
28 loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
29 logger.addHandler(loggerhandler)
30 logger.setLevel(logging.INFO)
31 return logger
32
33logger = logger_create()
34
35def main():
36 parser = optparse.OptionParser(
37 description = "Collects the recorded SRCREV values from buildhistory and reports on them.",
38 usage = """
39 %prog [options]""")
40
41 parser.add_option("-a", "--report-all",
42 help = "Report all SRCREV values, not just ones where AUTOREV has been used",
43 action="store_true", dest="reportall")
44 parser.add_option("-f", "--forcevariable",
45 help = "Use forcevariable override for all output lines",
46 action="store_true", dest="forcevariable")
47 parser.add_option("-p", "--buildhistory-dir",
48 help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)",
49 action="store", dest="buildhistory_dir", default='buildhistory/')
50
51 options, args = parser.parse_args(sys.argv)
52
53 if len(args) > 1:
54 sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[1:]))
55 parser.print_help()
56 sys.exit(1)
57
58 if not os.path.exists(options.buildhistory_dir):
59 sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
60 parser.print_help()
61 sys.exit(1)
62
63 if options.forcevariable:
64 forcevariable = '_forcevariable'
65 else:
66 forcevariable = ''
67
68 lastdir = ''
69 for root, dirs, files in os.walk(options.buildhistory_dir):
70 if '.git' in dirs:
71 dirs.remove('.git')
72 for fn in files:
73 if fn == 'latest_srcrev':
74 curdir = os.path.basename(os.path.dirname(root))
75 if lastdir != curdir:
76 print('# %s' % curdir)
77 lastdir = curdir
78 fullpath = os.path.join(root, fn)
79 pn = os.path.basename(root)
80 srcrev = None
81 orig_srcrev = None
82 orig_srcrevs = {}
83 srcrevs = {}
84 with open(fullpath) as f:
85 for line in f:
86 if '=' in line:
87 splitval = line.split('=')
88 value = splitval[1].strip('" \t\n\r')
89 if line.startswith('# SRCREV = '):
90 orig_srcrev = value
91 elif line.startswith('# SRCREV_'):
92 splitval = line.split('=')
93 name = splitval[0].split('_')[1].strip()
94 orig_srcrevs[name] = value
95 elif line.startswith('SRCREV ='):
96 srcrev = value
97 elif line.startswith('SRCREV_'):
98 name = splitval[0].split('_')[1].strip()
99 srcrevs[name] = value
100 if srcrev and (options.reportall or srcrev != orig_srcrev):
101 print('SRCREV_pn-%s%s = "%s"' % (pn, forcevariable, srcrev))
102 for name, value in srcrevs.items():
103 orig = orig_srcrevs.get(name, orig_srcrev)
104 if options.reportall or value != orig:
105 print('SRCREV_%s_pn-%s%s = "%s"' % (name, pn, forcevariable, value))
106
107
108if __name__ == "__main__":
109 main()