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. #
  7. # SPDX-License-Identifier: GPL-2.0-only
  8. #
  9. import sys
  10. import os
  11. import argparse
  12. # Ensure PythonGit is installed (buildhistory_analysis needs it)
  13. try:
  14. import git
  15. except ImportError:
  16. print("Please install GitPython (python3-git) 0.3.4 or later in order to use this script")
  17. sys.exit(1)
  18. def get_args_parser():
  19. description = "Reports significant differences in the buildhistory repository."
  20. parser = argparse.ArgumentParser(description=description,
  21. usage="""
  22. %(prog)s [options] [from-revision [to-revision]]
  23. (if not specified, from-revision defaults to build-minus-1, and to-revision defaults to HEAD)""")
  24. default_dir = os.path.join(os.environ.get('BUILDDIR', '.'), 'buildhistory')
  25. parser.add_argument('-p', '--buildhistory-dir',
  26. action='store',
  27. dest='buildhistory_dir',
  28. default=default_dir,
  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 len(args.revisions) > 2:
  66. sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args.revisions[2:]))
  67. parser.print_help()
  68. sys.exit(1)
  69. if not os.path.exists(args.buildhistory_dir):
  70. sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % args.buildhistory_dir)
  71. parser.print_help()
  72. sys.exit(1)
  73. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  74. lib_path = scripts_path + '/lib'
  75. sys.path = sys.path + [lib_path]
  76. import scriptpath
  77. # Set path to OE lib dir so we can import the buildhistory_analysis module
  78. scriptpath.add_oe_lib_path()
  79. # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
  80. bitbakepath = scriptpath.add_bitbake_lib_path()
  81. if not bitbakepath:
  82. sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
  83. sys.exit(1)
  84. if len(args.revisions) == 1:
  85. if '..' in args.revisions[0]:
  86. fromrev, torev = args.revisions[0].split('..')
  87. else:
  88. fromrev, torev = args.revisions[0], 'HEAD'
  89. elif len(args.revisions) == 2:
  90. fromrev, torev = args.revisions
  91. from oe.buildhistory_analysis import init_colours, process_changes
  92. import gitdb
  93. init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour])
  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()