bitbake-dumpsig 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python3
  2. # bitbake-dumpsig
  3. # BitBake task signature dump utility
  4. #
  5. # Copyright (C) 2013 Intel Corporation
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License version 2 as
  9. # published by the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License along
  17. # with this program; if not, write to the Free Software Foundation, Inc.,
  18. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. import os
  20. import sys
  21. import warnings
  22. import optparse
  23. import logging
  24. import pickle
  25. sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
  26. import bb.tinfoil
  27. import bb.siggen
  28. import bb.msg
  29. logger = bb.msg.logger_create('bitbake-dumpsig')
  30. def find_siginfo_task(bbhandler, pn, taskname):
  31. """ Find the most recent signature file for the specified PN/task """
  32. if not hasattr(bb.siggen, 'find_siginfo'):
  33. logger.error('Metadata does not support finding signature data files')
  34. sys.exit(1)
  35. if not taskname.startswith('do_'):
  36. taskname = 'do_%s' % taskname
  37. filedates = bb.siggen.find_siginfo(pn, taskname, None, bbhandler.config_data)
  38. latestfiles = sorted(filedates.keys(), key=lambda f: filedates[f])[-1:]
  39. if not latestfiles:
  40. logger.error('No sigdata files found matching %s %s' % (pn, taskname))
  41. sys.exit(1)
  42. return latestfiles[0]
  43. parser = optparse.OptionParser(
  44. description = "Dumps siginfo/sigdata files written out by BitBake",
  45. usage = """
  46. %prog -t recipename taskname
  47. %prog sigdatafile""")
  48. parser.add_option("-D", "--debug",
  49. help = "enable debug",
  50. action = "store_true", dest="debug", default = False)
  51. parser.add_option("-t", "--task",
  52. help = "find the signature data file for the specified task",
  53. action="store", dest="taskargs", nargs=2, metavar='recipename taskname')
  54. options, args = parser.parse_args(sys.argv)
  55. if options.debug:
  56. logger.setLevel(logging.DEBUG)
  57. if options.taskargs:
  58. tinfoil = bb.tinfoil.Tinfoil()
  59. tinfoil.prepare(config_only = True)
  60. file = find_siginfo_task(tinfoil, options.taskargs[0], options.taskargs[1])
  61. logger.debug("Signature file: %s" % file)
  62. elif len(args) == 1:
  63. parser.print_help()
  64. sys.exit(0)
  65. else:
  66. file = args[1]
  67. try:
  68. output = bb.siggen.dump_sigfile(file)
  69. except IOError as e:
  70. logger.error(str(e))
  71. sys.exit(1)
  72. except (pickle.UnpicklingError, EOFError):
  73. logger.error('Invalid signature data - ensure you are specifying a sigdata/siginfo file')
  74. sys.exit(1)
  75. if output:
  76. print('\n'.join(output))