buildhistory-collect-srcrevs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env python
  2. #
  3. # Collects the recorded SRCREV values from buildhistory and reports on them
  4. #
  5. # Copyright 2013 Intel Corporation
  6. # Authored-by: Paul Eggleton <paul.eggleton@intel.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. import os, sys
  21. import optparse
  22. import logging
  23. def logger_create():
  24. logger = logging.getLogger("buildhistory")
  25. loggerhandler = logging.StreamHandler()
  26. loggerhandler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
  27. logger.addHandler(loggerhandler)
  28. logger.setLevel(logging.INFO)
  29. return logger
  30. logger = logger_create()
  31. def main():
  32. parser = optparse.OptionParser(
  33. description = "Collects the recorded SRCREV values from buildhistory and reports on them.",
  34. usage = """
  35. %prog [options]""")
  36. parser.add_option("-a", "--report-all",
  37. help = "Report all SRCREV values, not just ones where AUTOREV has been used",
  38. action="store_true", dest="reportall")
  39. parser.add_option("-f", "--forcevariable",
  40. help = "Use forcevariable override for all output lines",
  41. action="store_true", dest="forcevariable")
  42. parser.add_option("-p", "--buildhistory-dir",
  43. help = "Specify path to buildhistory directory (defaults to buildhistory/ under cwd)",
  44. action="store", dest="buildhistory_dir", default='buildhistory/')
  45. options, args = parser.parse_args(sys.argv)
  46. if len(args) > 1:
  47. sys.stderr.write('Invalid argument(s) specified: %s\n\n' % ' '.join(args[1:]))
  48. parser.print_help()
  49. sys.exit(1)
  50. if not os.path.exists(options.buildhistory_dir):
  51. sys.stderr.write('Buildhistory directory "%s" does not exist\n\n' % options.buildhistory_dir)
  52. parser.print_help()
  53. sys.exit(1)
  54. if options.forcevariable:
  55. forcevariable = '_forcevariable'
  56. else:
  57. forcevariable = ''
  58. lastdir = ''
  59. for root, dirs, files in os.walk(options.buildhistory_dir):
  60. if '.git' in dirs:
  61. dirs.remove('.git')
  62. for fn in files:
  63. if fn == 'latest_srcrev':
  64. curdir = os.path.basename(os.path.dirname(root))
  65. if lastdir != curdir:
  66. print('# %s' % curdir)
  67. lastdir = curdir
  68. fullpath = os.path.join(root, fn)
  69. pn = os.path.basename(root)
  70. srcrev = None
  71. orig_srcrev = None
  72. orig_srcrevs = {}
  73. srcrevs = {}
  74. with open(fullpath) as f:
  75. for line in f:
  76. if '=' in line:
  77. splitval = line.split('=')
  78. value = splitval[1].strip('" \t\n\r')
  79. if line.startswith('# SRCREV = '):
  80. orig_srcrev = value
  81. elif line.startswith('# SRCREV_'):
  82. splitval = line.split('=')
  83. name = splitval[0].split('_')[1].strip()
  84. orig_srcrevs[name] = value
  85. elif line.startswith('SRCREV ='):
  86. srcrev = value
  87. elif line.startswith('SRCREV_'):
  88. name = splitval[0].split('_')[1].strip()
  89. srcrevs[name] = value
  90. if srcrev and (options.reportall or srcrev != orig_srcrev):
  91. print('SRCREV_pn-%s%s = "%s"' % (pn, forcevariable, srcrev))
  92. for name, value in srcrevs.items():
  93. orig = orig_srcrevs.get(name, orig_srcrev)
  94. if options.reportall or value != orig:
  95. print('SRCREV_%s_pn-%s%s = "%s"' % (name, pn, forcevariable, value))
  96. if __name__ == "__main__":
  97. main()