buildhistory-diff 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #!/usr/bin/env python3
  2. # Report significant differences in the buildhistory repository since a specific revision
  3. #
  4. # Copyright (C) 2013 Intel Corporation
  5. # Author: Paul Eggleton <paul.eggleton@linux.intel.com>
  6. import sys
  7. import os
  8. import optparse
  9. from distutils.version import LooseVersion
  10. # Ensure PythonGit is installed (buildhistory_analysis needs it)
  11. try:
  12. import git
  13. except ImportError:
  14. print("Please install GitPython (python3-git) 0.3.4 or later in order to use this script")
  15. sys.exit(1)
  16. def main():
  17. parser = optparse.OptionParser(
  18. description = "Reports significant differences in the buildhistory repository.",
  19. usage = """
  20. %prog [options] [from-revision [to-revision]]
  21. (if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""")
  22. parser.add_option("-p", "--buildhistory-dir",
  23. help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)",
  24. action="store", dest="buildhistory_dir", default='buildhistory/')
  25. parser.add_option("-v", "--report-version",
  26. help = "Report changes in PKGE/PKGV/PKGR even when the values are still the default (PE/PV/PR)",
  27. action="store_true", dest="report_ver", default=False)
  28. parser.add_option("-a", "--report-all",
  29. help = "Report all changes, not just the default significant ones",
  30. action="store_true", dest="report_all", default=False)
  31. parser.add_option("-s", "--signatures",
  32. help = "Report list of signatures differing instead of output",
  33. action="store_true", dest="sigs", default=False)
  34. parser.add_option("-S", "--signatures-with-diff",
  35. help = "Report on actual signature differences instead of output (requires signature data to have been generated, either by running the actual tasks or using bitbake -S)",
  36. action="store_true", dest="sigsdiff", default=False)
  37. options, args = parser.parse_args(sys.argv)
  38. if len(args) > 3:
  39. sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[3:]))
  40. parser.print_help()
  41. sys.exit(1)
  42. if LooseVersion(git.__version__) < '0.3.1':
  43. sys.stderr.write("Version of GitPython is too old, please install GitPython (python-git) 0.3.1 or later in order to use this script\n")
  44. sys.exit(1)
  45. if not os.path.exists(options.buildhistory_dir):
  46. if options.buildhistory_dir == 'buildhistory/':
  47. cwd = os.getcwd()
  48. if os.path.basename(cwd) == 'buildhistory':
  49. options.buildhistory_dir = cwd
  50. if not os.path.exists(options.buildhistory_dir):
  51. sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
  52. parser.print_help()
  53. sys.exit(1)
  54. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  55. lib_path = scripts_path + '/lib'
  56. sys.path = sys.path + [lib_path]
  57. import scriptpath
  58. # Set path to OE lib dir so we can import the buildhistory_analysis module
  59. scriptpath.add_oe_lib_path()
  60. # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
  61. bitbakepath = scriptpath.add_bitbake_lib_path()
  62. if not bitbakepath:
  63. sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
  64. sys.exit(1)
  65. import oe.buildhistory_analysis
  66. fromrev = 'build-minus-1'
  67. torev = 'HEAD'
  68. if len(args) > 1:
  69. if len(args) == 2 and '..' in args[1]:
  70. revs = args[1].split('..')
  71. fromrev = revs[0]
  72. if revs[1]:
  73. torev = revs[1]
  74. else:
  75. fromrev = args[1]
  76. if len(args) > 2:
  77. torev = args[2]
  78. import gitdb
  79. try:
  80. changes = oe.buildhistory_analysis.process_changes(options.buildhistory_dir, fromrev, torev, options.report_all, options.report_ver, options.sigs, options.sigsdiff)
  81. except gitdb.exc.BadObject as e:
  82. if len(args) == 1:
  83. sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
  84. parser.print_help()
  85. else:
  86. sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
  87. sys.exit(1)
  88. for chg in changes:
  89. print('%s' % chg)
  90. sys.exit(0)
  91. if __name__ == "__main__":
  92. main()