buildhistory-diff 5.5 KB

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