blob: 95ebd9354624ad80ecb44d8de443e57c90f09f67 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
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
Patrick Williamsc0f7c042017-02-23 20:41:17 -060026import pickle
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027
28sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
29
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030import bb.tinfoil
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031import bb.siggen
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032import bb.msg
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034logger = bb.msg.logger_create('bitbake-dumpsig')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036def 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]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
54parser = optparse.OptionParser(
55 description = "Dumps siginfo/sigdata files written out by BitBake",
56 usage = """
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 %prog -t recipename taskname
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 %prog sigdatafile""")
59
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060parser.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
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068options, args = parser.parse_args(sys.argv)
69
Brad Bishop6e60e8b2018-02-01 10:27:11 -050070if options.debug:
71 logger.setLevel(logging.DEBUG)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072
Brad Bishop6e60e8b2018-02-01 10:27:11 -050073if 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))