Files
poky/bitbake/bin/bitbake-diffsigs
Paul Eggleton e0eda80371 bitbake: bitbake-diffsigs: change to use argparse
Argparse is a bit easier to deal with than optparse, and since we're
about to add some options, migrate this script over.

(Bitbake rev: 7f130e0b5ce6cfc6b35176465f260092cd3b3d64)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2017-04-10 23:00:32 +01:00

4.7 KiB
Executable File

#!/usr/bin/env python3

bitbake-diffsigs

BitBake task signature data comparison utility

Copyright (C) 2012-2013, 2017 Intel Corporation

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License version 2 as

published by the Free Software Foundation.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License along

with this program; if not, write to the Free Software Foundation, Inc.,

51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os import sys import warnings import fnmatch import argparse import logging import pickle

sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))

import bb.tinfoil import bb.siggen import bb.msg

logger = bb.msg.logger_create('bitbake-diffsigs')

def find_compare_task(bbhandler, pn, taskname): """ Find the most recent signature files for the specified PN/task and compare them """

if not hasattr(bb.siggen, 'find_siginfo'):
    logger.error('Metadata does not support finding signature data files')
    sys.exit(1)

if not taskname.startswith('do_'):
    taskname = 'do_%s' % taskname

filedates = bb.siggen.find_siginfo(pn, taskname, None, bbhandler.config_data)
latestfiles = sorted(filedates.keys(), key=lambda f: filedates[f])[-3:]
if not latestfiles:
    logger.error('No sigdata files found matching %s %s' % (pn, taskname))
    sys.exit(1)
elif len(latestfiles) < 2:
    logger.error('Only one matching sigdata file found for the specified task (%s %s)' % (pn, taskname))
    sys.exit(1)
else:
    # Define recursion callback
    def recursecb(key, hash1, hash2):
        hashes = [hash1, hash2]
        hashfiles = bb.siggen.find_siginfo(key, None, hashes, bbhandler.config_data)

        recout = []
        if len(hashfiles) == 0:
            recout.append("Unable to find matching sigdata for %s with hashes %s or %s" % (key, hash1, hash2))
        elif not hash1 in hashfiles:
            recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash1))
        elif not hash2 in hashfiles:
            recout.append("Unable to find matching sigdata for %s with hash %s" % (key, hash2))
        else:
            out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2], recursecb)
            for change in out2:
                for line in change.splitlines():
                    recout.append('  ' + line)

        return recout

    # Recurse into signature comparison
    logger.debug("Signature file (previous): %s" % latestfiles[-2])
    logger.debug("Signature file (latest): %s" % latestfiles[-1])
    output = bb.siggen.compare_sigfiles(latestfiles[-2], latestfiles[-1], recursecb)
    if output:
        print('\n'.join(output))
sys.exit(0)

parser = argparse.ArgumentParser( description="Compares siginfo/sigdata files written out by BitBake")

parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')

parser.add_argument("-t", "--task", help="find the signature data files for last two runs of the specified task and compare them", action="store", dest="taskargs", nargs=2, metavar=('recipename', 'taskname'))

parser.add_argument("sigdatafile1", help="First signature file to compare (or signature file to dump, if second not specified). Not used when using -t/--task.", action="store", nargs='?')

parser.add_argument("sigdatafile2", help="Second signature file to compare", action="store", nargs='?')

options = parser.parse_args()

if options.debug: logger.setLevel(logging.DEBUG)

if options.taskargs: with bb.tinfoil.Tinfoil() as tinfoil: tinfoil.prepare(config_only=True) find_compare_task(tinfoil, options.taskargs[0], options.taskargs[1]) else: try: if options.sigdatafile1 and options.sigdatafile2: output = bb.siggen.compare_sigfiles(options.sigdatafile1, options.sigdatafile2) elif options.sigdatafile1: output = bb.siggen.dump_sigfile(options.sigdatafile1) except IOError as e: logger.error(str(e)) sys.exit(1) except (pickle.UnpicklingError, EOFError): logger.error('Invalid signature data - ensure you are specifying sigdata/siginfo files') sys.exit(1)

if output:
    print('\n'.join(output))