buildhistory-diff 5.4 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. 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('-c', '--colour',
  51. choices=('yes', 'no', 'auto'),
  52. default="auto",
  53. help="Whether to colourise (defaults to auto)")
  54. parser.add_argument('revisions',
  55. default = ['build-minus-1', 'HEAD'],
  56. nargs='*',
  57. help=argparse.SUPPRESS)
  58. return parser
  59. def main():
  60. parser = get_args_parser()
  61. args = parser.parse_args()
  62. if LooseVersion(git.__version__) < '0.3.1':
  63. 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")
  64. sys.exit(1)
  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. if args.buildhistory_dir == 'buildhistory/':
  71. cwd = os.getcwd()
  72. if os.path.basename(cwd) == 'buildhistory':
  73. args.buildhistory_dir = cwd
  74. if not os.path.exists(args.buildhistory_dir):
  75. sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % args.buildhistory_dir)
  76. parser.print_help()
  77. sys.exit(1)
  78. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  79. lib_path = scripts_path + '/lib'
  80. sys.path = sys.path + [lib_path]
  81. import scriptpath
  82. # Set path to OE lib dir so we can import the buildhistory_analysis module
  83. scriptpath.add_oe_lib_path()
  84. # Set path to bitbake lib dir so the buildhistory_analysis module can load bb.utils
  85. bitbakepath = scriptpath.add_bitbake_lib_path()
  86. if not bitbakepath:
  87. sys.stderr.write("Unable to find bitbake by searching parent directory of this script or PATH\n")
  88. sys.exit(1)
  89. if len(args.revisions) == 1:
  90. if '..' in args.revisions[0]:
  91. fromrev, torev = args.revisions[0].split('..')
  92. else:
  93. fromrev, torev = args.revisions[0], 'HEAD'
  94. elif len(args.revisions) == 2:
  95. fromrev, torev = args.revisions
  96. from oe.buildhistory_analysis import init_colours, process_changes
  97. import gitdb
  98. init_colours({"yes": True, "no": False, "auto": sys.stdout.isatty()}[args.colour])
  99. try:
  100. changes = process_changes(args.buildhistory_dir, fromrev, torev,
  101. args.report_all, args.report_ver, args.sigs,
  102. args.sigsdiff, args.exclude_path)
  103. except gitdb.exc.BadObject as e:
  104. if not args.revisions:
  105. sys.stderr.write("Unable to find previous build revision in buildhistory repository\n\n")
  106. parser.print_help()
  107. else:
  108. sys.stderr.write('Specified git revision "%s" is not valid\n' % e.args[0])
  109. sys.exit(1)
  110. for chg in changes:
  111. out = str(chg)
  112. if out:
  113. print(out)
  114. sys.exit(0)
  115. if __name__ == "__main__":
  116. main()