buildhistory-diff 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 argparse
  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 get_args_parser():
  17. description = "Reports significant differences in the buildhistory repository."
  18. parser = argparse.ArgumentParser(description=description,
  19. usage="""
  20. %(prog)s [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_argument('-p', '--buildhistory-dir',
  23. action='store',
  24. dest='buildhistory_dir',
  25. default='buildhistory/',
  26. help="Specify path to buildhistory directory (defaults to buildhistory/ under cwd)")
  27. parser.add_argument('-v', '--report-version',
  28. action='store_true',
  29. dest='report_ver',
  30. default=False,
  31. help="Report changes in PKGE/PKGV/PKGR even when the values are still the default (PE/PV/PR)")
  32. parser.add_argument('-a', '--report-all',
  33. action='store_true',
  34. dest='report_all',
  35. default='False',
  36. help="Report all changes, not just the default significant ones")
  37. parser.add_argument('-s', '---signatures',
  38. action='store_true',
  39. dest='sigs',
  40. default=False,
  41. help="Report list of signatures differing instead of output")
  42. parser.add_argument('-S', '--signatures-with-diff',
  43. action='store_true',
  44. dest='sigsdiff',
  45. default=False,
  46. 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)")
  47. parser.add_argument('-e', '--exclude-path',
  48. action='append',
  49. help="Exclude path from the output")
  50. parser.add_argument('revisions',
  51. default = ['build-minus-1', 'HEAD'],
  52. nargs='*',
  53. help=argparse.SUPPRESS)
  54. return parser
  55. def main():
  56. parser = get_args_parser()
  57. args = parser.parse_args()
  58. if LooseVersion(git.__version__) < '0.3.1':
  59. 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")
  60. sys.exit(1)
  61. if len(args.revisions) > 2:
  62. sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args.revisions[2:]))
  63. parser.print_help()
  64. sys.exit(1)
  65. if not os.path.exists(args.buildhistory_dir):
  66. if args.buildhistory_dir == 'buildhistory/':
  67. cwd = os.getcwd()
  68. if os.path.basename(cwd) == 'buildhistory':
  69. args.buildhistory_dir = cwd
  70. if not os.path.exists(args.buildhistory_dir):
  71. sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % args.buildhistory_dir)
  72. parser.print_help()
  73. sys.exit(1)
  74. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  75. lib_path = scripts_path + '/lib'
  76. sys.path = sys.path + [lib_path]
  77. import scriptpath
  78. # Set path to OE lib dir so we can import the buildhistory_analysis module
  79. scriptpath.add_oe_lib_path()
  80. # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
  81. bitbakepath = scriptpath.add_bitbake_lib_path()
  82. if not bitbakepath:
  83. sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
  84. sys.exit(1)
  85. if len(args.revisions) == 1:
  86. if '..' in args.revisions[0]:
  87. fromrev, torev = args.revisions[0].split('..')
  88. else:
  89. fromrev, torev = args.revisions[0], 'HEAD'
  90. elif len(args.revisions) == 2:
  91. fromrev, torev = args.revisions
  92. from oe.buildhistory_analysis import process_changes
  93. import gitdb
  94. try:
  95. changes = process_changes(args.buildhistory_dir, fromrev, torev,
  96. args.report_all, args.report_ver, args.sigs,
  97. args.sigsdiff, args.exclude_path)
  98. except gitdb.exc.BadObject as e:
  99. if not args.revisions:
  100. sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
  101. parser.print_help()
  102. else:
  103. sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
  104. sys.exit(1)
  105. for chg in changes:
  106. out = str(chg)
  107. if out:
  108. print(out)
  109. sys.exit(0)
  110. if __name__ == "__main__":
  111. main()