buildhistory-diff 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. parser.add_option("-e", "--exclude-path", action="append",
  38. help = "exclude path from the output")
  39. options, args = parser.parse_args(sys.argv)
  40. if len(args) > 3:
  41. sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[3:]))
  42. parser.print_help()
  43. sys.exit(1)
  44. if LooseVersion(git.__version__) < '0.3.1':
  45. 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")
  46. sys.exit(1)
  47. if not os.path.exists(options.buildhistory_dir):
  48. if options.buildhistory_dir == 'buildhistory/':
  49. cwd = os.getcwd()
  50. if os.path.basename(cwd) == 'buildhistory':
  51. options.buildhistory_dir = cwd
  52. if not os.path.exists(options.buildhistory_dir):
  53. sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
  54. parser.print_help()
  55. sys.exit(1)
  56. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  57. lib_path = scripts_path + '/lib'
  58. sys.path = sys.path + [lib_path]
  59. import scriptpath
  60. # Set path to OE lib dir so we can import the buildhistory_analysis module
  61. scriptpath.add_oe_lib_path()
  62. # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
  63. bitbakepath = scriptpath.add_bitbake_lib_path()
  64. if not bitbakepath:
  65. sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
  66. sys.exit(1)
  67. from oe.buildhistory_analysis import process_changes
  68. fromrev = 'build-minus-1'
  69. torev = 'HEAD'
  70. if len(args) > 1:
  71. if len(args) == 2 and '..' in args[1]:
  72. revs = args[1].split('..')
  73. fromrev = revs[0]
  74. if revs[1]:
  75. torev = revs[1]
  76. else:
  77. fromrev = args[1]
  78. if len(args) > 2:
  79. torev = args[2]
  80. import gitdb
  81. try:
  82. changes = process_changes(options.buildhistory_dir, fromrev, torev,
  83. options.report_all, options.report_ver, options.sigs,
  84. options.sigsdiff, options.exclude_path)
  85. except gitdb.exc.BadObject as e:
  86. if len(args) == 1:
  87. sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
  88. parser.print_help()
  89. else:
  90. sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
  91. sys.exit(1)
  92. for chg in changes:
  93. out = str(chg)
  94. if out:
  95. print(out)
  96. sys.exit(0)
  97. if __name__ == "__main__":
  98. main()