summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbitbake/bin/bitbake-diffsigs139
l---------[-rwxr-xr-x]bitbake/bin/bitbake-dumpsig95
2 files changed, 82 insertions, 152 deletions
diff --git a/bitbake/bin/bitbake-diffsigs b/bitbake/bin/bitbake-diffsigs
index 4e6bbddcd8..b0869e1143 100755
--- a/bitbake/bin/bitbake-diffsigs
+++ b/bitbake/bin/bitbake-diffsigs
@@ -1,7 +1,7 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3# bitbake-diffsigs 3# bitbake-diffsigs / bitbake-dumpsig
4# BitBake task signature data comparison utility 4# BitBake task signature data dump and comparison utility
5# 5#
6# Copyright (C) 2012-2013, 2017 Intel Corporation 6# Copyright (C) 2012-2013, 2017 Intel Corporation
7# 7#
@@ -21,7 +21,6 @@
21import os 21import os
22import sys 22import sys
23import warnings 23import warnings
24import fnmatch
25import argparse 24import argparse
26import logging 25import logging
27import pickle 26import pickle
@@ -32,7 +31,10 @@ import bb.tinfoil
32import bb.siggen 31import bb.siggen
33import bb.msg 32import bb.msg
34 33
35logger = bb.msg.logger_create('bitbake-diffsigs') 34myname = os.path.basename(sys.argv[0])
35logger = bb.msg.logger_create(myname)
36
37is_dump = myname == 'bitbake-dumpsig'
36 38
37def find_siginfo(tinfoil, pn, taskname, sigs=None): 39def find_siginfo(tinfoil, pn, taskname, sigs=None):
38 result = None 40 result = None
@@ -59,8 +61,8 @@ def find_siginfo(tinfoil, pn, taskname, sigs=None):
59 sys.exit(2) 61 sys.exit(2)
60 return result 62 return result
61 63
62def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None, color=False): 64def find_siginfo_task(bbhandler, pn, taskname, sig1=None, sig2=None):
63 """ Find the most recent signature files for the specified PN/task and compare them """ 65 """ Find the most recent signature files for the specified PN/task """
64 66
65 if not taskname.startswith('do_'): 67 if not taskname.startswith('do_'):
66 taskname = 'do_%s' % taskname 68 taskname = 'do_%s' % taskname
@@ -79,73 +81,81 @@ def find_compare_task(bbhandler, pn, taskname, sig1=None, sig2=None, color=False
79 latestfiles = [sigfiles[sig1], sigfiles[sig2]] 81 latestfiles = [sigfiles[sig1], sigfiles[sig2]]
80 else: 82 else:
81 filedates = find_siginfo(bbhandler, pn, taskname) 83 filedates = find_siginfo(bbhandler, pn, taskname)
82 latestfiles = sorted(filedates.keys(), key=lambda f: filedates[f])[-3:] 84 latestfiles = sorted(filedates.keys(), key=lambda f: filedates[f])[-2:]
83 if not latestfiles: 85 if not latestfiles:
84 logger.error('No sigdata files found matching %s %s' % (pn, taskname)) 86 logger.error('No sigdata files found matching %s %s' % (pn, taskname))
85 sys.exit(1) 87 sys.exit(1)
86 elif len(latestfiles) < 2:
87 logger.error('Only one matching sigdata file found for the specified task (%s %s)' % (pn, taskname))
88 sys.exit(1)
89 88
90 # Define recursion callback 89 return latestfiles
91 def recursecb(key, hash1, hash2):
92 hashes = [hash1, hash2]
93 hashfiles = find_siginfo(bbhandler, key, None, hashes)
94
95 recout = []
96 if len(hashfiles) == 0:
97 recout.append("Unable to find matching sigdata for %s with hashes %s or %s" % (key, hash1, hash2))
98 elif not hash1 in hashfiles:
99 recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash1))
100 elif not hash2 in hashfiles:
101 recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash2))
102 else:
103 out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb, color=color)
104 for change in out2:
105 for line in change.splitlines():
106 recout.append(' ' + line)
107 90
108 return recout
109 91
110 # Recurse into signature comparison 92# Define recursion callback
111 logger.debug("Signature file (previous): %s" % latestfiles[-2]) 93def recursecb(key, hash1, hash2):
112 logger.debug("Signature file (latest): %s" % latestfiles[-1]) 94 hashes = [hash1, hash2]
113 output = bb.siggen.compare_sigfiles(latestfiles[-2], latestfiles[-1], recursecb, color=color) 95 hashfiles = find_siginfo(tinfoil, key, None, hashes)
114 if output: 96
115 print('\n'.join(output)) 97 recout = []
116 sys.exit(0) 98 if len(hashfiles) == 0:
99 recout.append("Unable to find matching sigdata for %s with hashes %s or %s" % (key, hash1, hash2))
100 elif not hash1 in hashfiles:
101 recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash1))
102 elif not hash2 in hashfiles:
103 recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash2))
104 else:
105 out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb, color=color)
106 for change in out2:
107 for line in change.splitlines():
108 recout.append(' ' + line)
117 109
110 return recout
118 111
119 112
120parser = argparse.ArgumentParser( 113parser = argparse.ArgumentParser(
121 description="Compares siginfo/sigdata files written out by BitBake") 114 description=("Dumps" if is_dump else "Compares") + " siginfo/sigdata files written out by BitBake")
122 115
123parser.add_argument('-d', '--debug', 116parser.add_argument('-D', '--debug',
124 help='Enable debug output', 117 help='Enable debug output',
125 action='store_true') 118 action='store_true')
126 119
127parser.add_argument('--color', 120if is_dump:
128 help='Colorize output (where %(metavar)s is %(choices)s)', 121 parser.add_argument("-t", "--task",
129 choices=['auto', 'always', 'never'], default='auto', metavar='color') 122 help="find the signature data file for the last run of the specified task",
123 action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname'))
130 124
131parser.add_argument("-t", "--task", 125 parser.add_argument("sigdatafile1",
132 help="find the signature data files for last two runs of the specified task and compare them", 126 help="Signature file to dump. Not used when using -t/--task.",
133 action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname')) 127 action="store", nargs='?', metavar="sigdatafile")
128else:
129 parser.add_argument('-c', '--color',
130 help='Colorize the output (where %(metavar)s is %(choices)s)',
131 choices=['auto', 'always', 'never'], default='auto', metavar='color')
132
133 parser.add_argument('-d', '--dump',
134 help='Dump the last signature data instead of comparing (equivalent to using bitbake-dumpsig)',
135 action='store_true')
134 136
135parser.add_argument("-s", "--signature", 137 parser.add_argument("-t", "--task",
136 help="With -t/--task, specify the signatures to look for instead of taking the last two", 138 help="find the signature data files for the last two runs of the specified task and compare them",
137 action="store", dest="sigargs", nargs=2, metavar=('fromsig', 'tosig')) 139 action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname'))
138 140
139parser.add_argument("sigdatafile1", 141 parser.add_argument("-s", "--signature",
140 help="First signature file to compare (or signature file to dump, if second not specified). Not used when using -t/--task.", 142 help="With -t/--task, specify the signatures to look for instead of taking the last two",
141 action="store", nargs='?') 143 action="store", dest="sigargs", nargs=2, metavar=('fromsig', 'tosig'))
142 144
143parser.add_argument("sigdatafile2", 145 parser.add_argument("sigdatafile1",
144 help="Second signature file to compare", 146 help="First signature file to compare (or signature file to dump, if second not specified). Not used when using -t/--task.",
145 action="store", nargs='?') 147 action="store", nargs='?')
146 148
149 parser.add_argument("sigdatafile2",
150 help="Second signature file to compare",
151 action="store", nargs='?')
147 152
148options = parser.parse_args() 153options = parser.parse_args()
154if is_dump:
155 options.color = 'never'
156 options.dump = True
157 options.sigdatafile2 = None
158 options.sigargs = None
149 159
150if options.debug: 160if options.debug:
151 logger.setLevel(logging.DEBUG) 161 logger.setLevel(logging.DEBUG)
@@ -155,16 +165,29 @@ color = (options.color == 'always' or (options.color == 'auto' and sys.stdout.is
155if options.taskargs: 165if options.taskargs:
156 with bb.tinfoil.Tinfoil() as tinfoil: 166 with bb.tinfoil.Tinfoil() as tinfoil:
157 tinfoil.prepare(config_only=True) 167 tinfoil.prepare(config_only=True)
158 if options.sigargs: 168 if not options.dump and options.sigargs:
159 find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], options.sigargs[0], options.sigargs[1], color=color) 169 files = find_siginfo_task(tinfoil, options.taskargs[0], options.taskargs[1], options.sigargs[0], options.sigargs[1])
170 else:
171 files = find_siginfo_task(tinfoil, options.taskargs[0], options.taskargs[1])
172
173 if options.dump:
174 logger.debug("Signature file: %s" % files[-1])
175 output = bb.siggen.dump_sigfile(files[-1])
160 else: 176 else:
161 find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1], color=color) 177 if len(files) < 2:
178 logger.error('Only one matching sigdata file found for the specified task (%s %s)' % (options.taskargs[0], options.taskargs[1]))
179 sys.exit(1)
180
181 # Recurse into signature comparison
182 logger.debug("Signature file (previous): %s" % files[-2])
183 logger.debug("Signature file (latest): %s" % files[-1])
184 output = bb.siggen.compare_sigfiles(files[-2], files[-1], recursecb, color=color)
162else: 185else:
163 if options.sigargs: 186 if options.sigargs:
164 logger.error('-s/--signature can only be used together with -t/--task') 187 logger.error('-s/--signature can only be used together with -t/--task')
165 sys.exit(1) 188 sys.exit(1)
166 try: 189 try:
167 if options.sigdatafile1 and options.sigdatafile2: 190 if not options.dump and options.sigdatafile1 and options.sigdatafile2:
168 output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2, color=color) 191 output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2, color=color)
169 elif options.sigdatafile1: 192 elif options.sigdatafile1:
170 output = bb.siggen.dump_sigfile(options.sigdatafile1) 193 output = bb.siggen.dump_sigfile(options.sigdatafile1)
@@ -179,5 +202,5 @@ else:
179 logger.error('Invalid signature data - ensure you are specifying sigdata/siginfo files') 202 logger.error('Invalid signature data - ensure you are specifying sigdata/siginfo files')
180 sys.exit(1) 203 sys.exit(1)
181 204
182 if output: 205if output:
183 print('\n'.join(output)) 206 print('\n'.join(output))
diff --git a/bitbake/bin/bitbake-dumpsig b/bitbake/bin/bitbake-dumpsig
index 95ebd93546..b1e8489b45 100755..120000
--- a/bitbake/bin/bitbake-dumpsig
+++ b/bitbake/bin/bitbake-dumpsig
@@ -1,94 +1 @@
1#!/usr/bin/env python3 bitbake-diffsigs \ No newline at end of file
2
3# bitbake-dumpsig
4# BitBake task signature dump utility
5#
6# Copyright (C) 2013 Intel Corporation
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
22import sys
23import warnings
24import optparse
25import logging
26import pickle
27
28sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
29
30import bb.tinfoil
31import bb.siggen
32import bb.msg
33
34logger = bb.msg.logger_create('bitbake-dumpsig')
35
36def find_siginfo_task(bbhandler, pn, taskname):
37 """ Find the most recent signature file for the specified PN/task """
38
39 if not hasattr(bb.siggen, 'find_siginfo'):
40 logger.error('Metadata does not support finding signature data files')
41 sys.exit(1)
42
43 if not taskname.startswith('do_'):
44 taskname = 'do_%s' % taskname
45
46 filedates = bb.siggen.find_siginfo(pn, taskname, None, bbhandler.config_data)
47 latestfiles = sorted(filedates.keys(), key=lambda f: filedates[f])[-1:]
48 if not latestfiles:
49 logger.error('No sigdata files found matching %s %s' % (pn, taskname))
50 sys.exit(1)
51
52 return latestfiles[0]
53
54parser = optparse.OptionParser(
55 description = "Dumps siginfo/sigdata files written out by BitBake",
56 usage = """
57 %prog -t recipename taskname
58 %prog sigdatafile""")
59
60parser.add_option("-D", "--debug",
61 help = "enable debug",
62 action = "store_true", dest="debug", default = False)
63
64parser.add_option("-t", "--task",
65 help = "find the signature data file for the specified task",
66 action="store", dest="taskargs", nargs=2, metavar='recipename taskname')
67
68options, args = parser.parse_args(sys.argv)
69
70if options.debug:
71 logger.setLevel(logging.DEBUG)
72
73if options.taskargs:
74 tinfoil = bb.tinfoil.Tinfoil()
75 tinfoil.prepare(config_only = True)
76 file = find_siginfo_task(tinfoil, options.taskargs[0], options.taskargs[1])
77 logger.debug("Signature file: %s" % file)
78elif len(args) == 1:
79 parser.print_help()
80 sys.exit(0)
81else:
82 file = args[1]
83
84try:
85 output = bb.siggen.dump_sigfile(file)
86except IOError as e:
87 logger.error(str(e))
88 sys.exit(1)
89except (pickle.UnpicklingError, EOFError):
90 logger.error('Invalid signature data - ensure you are specifying a sigdata/siginfo file')
91 sys.exit(1)
92
93if output:
94 print('\n'.join(output))