buildhistory-diff 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/usr/bin/env python
  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 (python-git) 0.3.1 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. options, args = parser.parse_args(sys.argv)
  32. if len(args) > 3:
  33. sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[3:]))
  34. parser.print_help()
  35. sys.exit(1)
  36. if LooseVersion(git.__version__) < '0.3.1':
  37. 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")
  38. sys.exit(1)
  39. if not os.path.exists(options.buildhistory_dir):
  40. sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
  41. parser.print_help()
  42. sys.exit(1)
  43. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  44. lib_path = scripts_path + '/lib'
  45. sys.path = sys.path + [lib_path]
  46. import scriptpath
  47. # Set path to OE lib dir so we can import the buildhistory_analysis module
  48. scriptpath.add_oe_lib_path()
  49. # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
  50. bitbakepath = scriptpath.add_bitbake_lib_path()
  51. if not bitbakepath:
  52. sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
  53. sys.exit(1)
  54. import oe.buildhistory_analysis
  55. fromrev = 'build-minus-1'
  56. torev = 'HEAD'
  57. if len(args) > 1:
  58. if len(args) == 2 and '..' in args[1]:
  59. revs = args[1].split('..')
  60. fromrev = revs[0]
  61. if revs[1]:
  62. torev = revs[1]
  63. else:
  64. fromrev = args[1]
  65. if len(args) > 2:
  66. torev = args[2]
  67. import gitdb
  68. try:
  69. changes = oe.buildhistory_analysis.process_changes(options.buildhistory_dir, fromrev, torev, options.report_all, options.report_ver)
  70. except gitdb.exc.BadObject as e:
  71. if len(args) == 1:
  72. sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
  73. parser.print_help()
  74. else:
  75. sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
  76. sys.exit(1)
  77. for chg in changes:
  78. print('%s' % chg)
  79. sys.exit(0)
  80. if __name__ == "__main__":
  81. main()