summaryrefslogtreecommitdiffstats
path: root/bitbake/bin/bitbake-diffsigs
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/bin/bitbake-diffsigs')
-rwxr-xr-xbitbake/bin/bitbake-diffsigs122
1 files changed, 122 insertions, 0 deletions
diff --git a/bitbake/bin/bitbake-diffsigs b/bitbake/bin/bitbake-diffsigs
new file mode 100755
index 0000000000..08ae00db0f
--- /dev/null
+++ b/bitbake/bin/bitbake-diffsigs
@@ -0,0 +1,122 @@
1#!/usr/bin/env python
2
3# bitbake-diffsigs
4# BitBake task signature data comparison utility
5#
6# Copyright (C) 2012-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 fnmatch
25import optparse
26import logging
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
32
33def logger_create(name, output=sys.stderr):
34 logger = logging.getLogger(name)
35 console = logging.StreamHandler(output)
36 format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
37 if output.isatty():
38 format.enable_color()
39 console.setFormatter(format)
40 logger.addHandler(console)
41 logger.setLevel(logging.INFO)
42 return logger
43
44logger = logger_create('bitbake-diffsigs')
45
46def find_compare_task(bbhandler, pn, taskname):
47 """ Find the most recent signature files for the specified PN/task and compare them """
48
49 if not hasattr(bb.siggen, 'find_siginfo'):
50 logger.error('Metadata does not support finding signature data files')
51 sys.exit(1)
52
53 if not taskname.startswith('do_'):
54 taskname = 'do_%s' % taskname
55
56 filedates = bb.siggen.find_siginfo(pn, taskname, None, bbhandler.config_data)
57 latestfiles = sorted(filedates.keys(), key=lambda f: filedates[f])[-2:]
58 if not latestfiles:
59 logger.error('No sigdata files found matching %s %s' % (pn, taskname))
60 sys.exit(1)
61 elif len(latestfiles) < 2:
62 logger.error('Only one matching sigdata file found for the specified task (%s %s)' % (pn, taskname))
63 sys.exit(1)
64 else:
65 # Define recursion callback
66 def recursecb(key, hash1, hash2):
67 hashes = [hash1, hash2]
68 hashfiles = bb.siggen.find_siginfo(key, None, hashes, bbhandler.config_data)
69
70 recout = []
71 if len(hashfiles) == 2:
72 out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb)
73 recout.extend(list(' ' + l for l in out2))
74 else:
75 recout.append("Unable to find matching sigdata for %s with hashes %s or %s" % (key, hash1, hash2))
76
77 return recout
78
79 # Recurse into signature comparison
80 output = bb.siggen.compare_sigfiles(latestfiles[0], latestfiles[1], recursecb)
81 if output:
82 print '\n'.join(output)
83 sys.exit(0)
84
85
86
87parser = optparse.OptionParser(
88 description = "Compares siginfo/sigdata files written out by BitBake",
89 usage = """
90 %prog -t recipename taskname
91 %prog sigdatafile1 sigdatafile2
92 %prog sigdatafile1""")
93
94parser.add_option("-t", "--task",
95 help = "find the signature data files for last two runs of the specified task and compare them",
96 action="store", dest="taskargs", nargs=2, metavar='recipename taskname')
97
98options, args = parser.parse_args(sys.argv)
99
100if options.taskargs:
101 tinfoil = bb.tinfoil.Tinfoil()
102 tinfoil.prepare(config_only = True)
103 find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1])
104else:
105 if len(args) == 1:
106 parser.print_help()
107 else:
108 import cPickle
109 try:
110 if len(args) == 2:
111 output = bb.siggen.dump_sigfile(sys.argv[1])
112 else:
113 output = bb.siggen.compare_sigfiles(sys.argv[1], sys.argv[2])
114 except IOError as e:
115 logger.error(str(e))
116 sys.exit(1)
117 except cPickle.UnpicklingError, EOFError:
118 logger.error('Invalid signature data - ensure you are specifying sigdata/siginfo files')
119 sys.exit(1)
120
121 if output:
122 print '\n'.join(output)