buildhistory-diff 5.3 KB

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