diff options
Diffstat (limited to 'bitbake/bin/bitbake-diffsigs')
| -rwxr-xr-x | bitbake/bin/bitbake-diffsigs | 208 |
1 files changed, 0 insertions, 208 deletions
diff --git a/bitbake/bin/bitbake-diffsigs b/bitbake/bin/bitbake-diffsigs deleted file mode 100755 index 9d6cb8c944..0000000000 --- a/bitbake/bin/bitbake-diffsigs +++ /dev/null | |||
| @@ -1,208 +0,0 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | |||
| 3 | # bitbake-diffsigs / bitbake-dumpsig | ||
| 4 | # BitBake task signature data dump and comparison utility | ||
| 5 | # | ||
| 6 | # Copyright (C) 2012-2013, 2017 Intel Corporation | ||
| 7 | # | ||
| 8 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 9 | # | ||
| 10 | |||
| 11 | import os | ||
| 12 | import sys | ||
| 13 | import warnings | ||
| 14 | |||
| 15 | warnings.simplefilter("default") | ||
| 16 | import argparse | ||
| 17 | import logging | ||
| 18 | import pickle | ||
| 19 | |||
| 20 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib')) | ||
| 21 | |||
| 22 | import bb.tinfoil | ||
| 23 | import bb.siggen | ||
| 24 | import bb.msg | ||
| 25 | |||
| 26 | myname = os.path.basename(sys.argv[0]) | ||
| 27 | logger = bb.msg.logger_create(myname) | ||
| 28 | |||
| 29 | is_dump = myname == 'bitbake-dumpsig' | ||
| 30 | |||
| 31 | |||
| 32 | def find_siginfo(tinfoil, pn, taskname, sigs=None): | ||
| 33 | result = None | ||
| 34 | tinfoil.set_event_mask(['bb.event.FindSigInfoResult', | ||
| 35 | 'logging.LogRecord', | ||
| 36 | 'bb.command.CommandCompleted', | ||
| 37 | 'bb.command.CommandFailed']) | ||
| 38 | ret = tinfoil.run_command('findSigInfo', pn, taskname, sigs) | ||
| 39 | if ret: | ||
| 40 | while True: | ||
| 41 | event = tinfoil.wait_event(1) | ||
| 42 | if event: | ||
| 43 | if isinstance(event, bb.command.CommandCompleted): | ||
| 44 | break | ||
| 45 | elif isinstance(event, bb.command.CommandFailed): | ||
| 46 | logger.error(str(event)) | ||
| 47 | sys.exit(2) | ||
| 48 | elif isinstance(event, bb.event.FindSigInfoResult): | ||
| 49 | result = event.result | ||
| 50 | elif isinstance(event, logging.LogRecord): | ||
| 51 | logger.handle(event) | ||
| 52 | else: | ||
| 53 | logger.error('No result returned from findSigInfo command') | ||
| 54 | sys.exit(2) | ||
| 55 | return result | ||
| 56 | |||
| 57 | |||
| 58 | def find_siginfo_task(bbhandler, pn, taskname, sig1=None, sig2=None): | ||
| 59 | """ Find the most recent signature files for the specified PN/task """ | ||
| 60 | |||
| 61 | if not taskname.startswith('do_'): | ||
| 62 | taskname = 'do_%s' % taskname | ||
| 63 | |||
| 64 | if sig1 and sig2: | ||
| 65 | sigfiles = find_siginfo(bbhandler, pn, taskname, [sig1, sig2]) | ||
| 66 | if not sigfiles: | ||
| 67 | logger.error('No sigdata files found matching %s %s matching either %s or %s' % (pn, taskname, sig1, sig2)) | ||
| 68 | sys.exit(1) | ||
| 69 | elif sig1 not in sigfiles: | ||
| 70 | logger.error('No sigdata files found matching %s %s with signature %s' % (pn, taskname, sig1)) | ||
| 71 | sys.exit(1) | ||
| 72 | elif sig2 not in sigfiles: | ||
| 73 | logger.error('No sigdata files found matching %s %s with signature %s' % (pn, taskname, sig2)) | ||
| 74 | sys.exit(1) | ||
| 75 | |||
| 76 | latestfiles = [sigfiles[sig1]['path'], sigfiles[sig2]['path']] | ||
| 77 | else: | ||
| 78 | sigfiles = find_siginfo(bbhandler, pn, taskname) | ||
| 79 | latestsigs = sorted(sigfiles.keys(), key=lambda h: sigfiles[h]['time'])[-2:] | ||
| 80 | if not latestsigs: | ||
| 81 | logger.error('No sigdata files found matching %s %s' % (pn, taskname)) | ||
| 82 | sys.exit(1) | ||
| 83 | latestfiles = [sigfiles[latestsigs[0]]['path']] | ||
| 84 | if len(latestsigs) > 1: | ||
| 85 | latestfiles.append(sigfiles[latestsigs[1]]['path']) | ||
| 86 | |||
| 87 | return latestfiles | ||
| 88 | |||
| 89 | |||
| 90 | # Define recursion callback | ||
| 91 | def recursecb(key, hash1, hash2): | ||
| 92 | hashes = [hash1, hash2] | ||
| 93 | hashfiles = find_siginfo(tinfoil, key, None, hashes) | ||
| 94 | |||
| 95 | recout = [] | ||
| 96 | if not hashfiles: | ||
| 97 | recout.append("Unable to find matching sigdata for %s with hashes %s or %s" % (key, hash1, hash2)) | ||
| 98 | elif hash1 not in hashfiles: | ||
| 99 | recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash1)) | ||
| 100 | elif hash2 not 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]['path'], hashfiles[hash2]['path'], recursecb, color=color) | ||
| 104 | for change in out2: | ||
| 105 | for line in change.splitlines(): | ||
| 106 | recout.append(' ' + line) | ||
| 107 | |||
| 108 | return recout | ||
| 109 | |||
| 110 | |||
| 111 | parser = argparse.ArgumentParser( | ||
| 112 | description=("Dumps" if is_dump else "Compares") + " siginfo/sigdata files written out by BitBake") | ||
| 113 | |||
| 114 | parser.add_argument('-D', '--debug', | ||
| 115 | help='Enable debug output', | ||
| 116 | action='store_true') | ||
| 117 | |||
| 118 | if is_dump: | ||
| 119 | parser.add_argument("-t", "--task", | ||
| 120 | help="find the signature data file for the last run of the specified task", | ||
| 121 | action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname')) | ||
| 122 | |||
| 123 | parser.add_argument("sigdatafile1", | ||
| 124 | help="Signature file to dump. Not used when using -t/--task.", | ||
| 125 | action="store", nargs='?', metavar="sigdatafile") | ||
| 126 | else: | ||
| 127 | parser.add_argument('-c', '--color', | ||
| 128 | help='Colorize the output (where %(metavar)s is %(choices)s)', | ||
| 129 | choices=['auto', 'always', 'never'], default='auto', metavar='color') | ||
| 130 | |||
| 131 | parser.add_argument('-d', '--dump', | ||
| 132 | help='Dump the last signature data instead of comparing (equivalent to using bitbake-dumpsig)', | ||
| 133 | action='store_true') | ||
| 134 | |||
| 135 | parser.add_argument("-t", "--task", | ||
| 136 | help="find the signature data files for the last two runs of the specified task and compare them", | ||
| 137 | action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname')) | ||
| 138 | |||
| 139 | parser.add_argument("-s", "--signature", | ||
| 140 | help="With -t/--task, specify the signatures to look for instead of taking the last two", | ||
| 141 | action="store", dest="sigargs", nargs=2, metavar=('fromsig', 'tosig')) | ||
| 142 | |||
| 143 | parser.add_argument("sigdatafile1", | ||
| 144 | 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='?') | ||
| 146 | |||
| 147 | parser.add_argument("sigdatafile2", | ||
| 148 | help="Second signature file to compare", | ||
| 149 | action="store", nargs='?') | ||
| 150 | |||
| 151 | options = parser.parse_args() | ||
| 152 | if is_dump: | ||
| 153 | options.color = 'never' | ||
| 154 | options.dump = True | ||
| 155 | options.sigdatafile2 = None | ||
| 156 | options.sigargs = None | ||
| 157 | |||
| 158 | if options.debug: | ||
| 159 | logger.setLevel(logging.DEBUG) | ||
| 160 | |||
| 161 | color = (options.color == 'always' or (options.color == 'auto' and sys.stdout.isatty())) | ||
| 162 | |||
| 163 | if options.taskargs: | ||
| 164 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
| 165 | tinfoil.prepare(config_only=True) | ||
| 166 | if not options.dump and options.sigargs: | ||
| 167 | files = find_siginfo_task(tinfoil, options.taskargs[0], options.taskargs[1], options.sigargs[0], | ||
| 168 | options.sigargs[1]) | ||
| 169 | else: | ||
| 170 | files = find_siginfo_task(tinfoil, options.taskargs[0], options.taskargs[1]) | ||
| 171 | |||
| 172 | if options.dump: | ||
| 173 | logger.debug("Signature file: %s" % files[-1]) | ||
| 174 | output = bb.siggen.dump_sigfile(files[-1]) | ||
| 175 | else: | ||
| 176 | if len(files) < 2: | ||
| 177 | logger.error('Only one matching sigdata file found for the specified task (%s %s)' % ( | ||
| 178 | 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) | ||
| 185 | else: | ||
| 186 | if options.sigargs: | ||
| 187 | logger.error('-s/--signature can only be used together with -t/--task') | ||
| 188 | sys.exit(1) | ||
| 189 | try: | ||
| 190 | if not options.dump and options.sigdatafile1 and options.sigdatafile2: | ||
| 191 | with bb.tinfoil.Tinfoil() as tinfoil: | ||
| 192 | tinfoil.prepare(config_only=True) | ||
| 193 | output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2, recursecb, color=color) | ||
| 194 | elif options.sigdatafile1: | ||
| 195 | output = bb.siggen.dump_sigfile(options.sigdatafile1) | ||
| 196 | else: | ||
| 197 | logger.error('Must specify signature file(s) or -t/--task') | ||
| 198 | parser.print_help() | ||
| 199 | sys.exit(1) | ||
| 200 | except IOError as e: | ||
| 201 | logger.error(str(e)) | ||
| 202 | sys.exit(1) | ||
| 203 | except (pickle.UnpicklingError, EOFError): | ||
| 204 | logger.error('Invalid signature data - ensure you are specifying sigdata/siginfo files') | ||
| 205 | sys.exit(1) | ||
| 206 | |||
| 207 | if output: | ||
| 208 | print('\n'.join(output)) | ||
