| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 |  | 
|  | 21 | import os | 
|  | 22 | import sys | 
|  | 23 | import warnings | 
|  | 24 | import optparse | 
|  | 25 | import logging | 
| Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 26 | import pickle | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 |  | 
|  | 28 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib')) | 
|  | 29 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 30 | import bb.tinfoil | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | import bb.siggen | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 32 | import bb.msg | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | logger = bb.msg.logger_create('bitbake-dumpsig') | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | def 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 |  | 
|  | 54 | parser = optparse.OptionParser( | 
|  | 55 | description = "Dumps siginfo/sigdata files written out by BitBake", | 
|  | 56 | usage = """ | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 57 | %prog -t recipename taskname | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | %prog sigdatafile""") | 
|  | 59 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | parser.add_option("-D", "--debug", | 
|  | 61 | help = "enable debug", | 
|  | 62 | action = "store_true", dest="debug", default = False) | 
|  | 63 |  | 
|  | 64 | parser.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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | options, args = parser.parse_args(sys.argv) | 
|  | 69 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | if options.debug: | 
|  | 71 | logger.setLevel(logging.DEBUG) | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 |  | 
| Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 73 | if 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) | 
|  | 78 | elif len(args) == 1: | 
|  | 79 | parser.print_help() | 
|  | 80 | sys.exit(0) | 
|  | 81 | else: | 
|  | 82 | file = args[1] | 
|  | 83 |  | 
|  | 84 | try: | 
|  | 85 | output = bb.siggen.dump_sigfile(file) | 
|  | 86 | except IOError as e: | 
|  | 87 | logger.error(str(e)) | 
|  | 88 | sys.exit(1) | 
|  | 89 | except (pickle.UnpicklingError, EOFError): | 
|  | 90 | logger.error('Invalid signature data - ensure you are specifying a sigdata/siginfo file') | 
|  | 91 | sys.exit(1) | 
|  | 92 |  | 
|  | 93 | if output: | 
|  | 94 | print('\n'.join(output)) |