buildhistory-collect-srcrevs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. usage = """
  34. %prog [options] <buildhistory-dir>""")
  35. parser.add_option("-a", "--report-all",
  36. help = "Report all SRCREV values, not just ones where AUTOREV has been used",
  37. action="store_true", dest="reportall")
  38. parser.add_option("-f", "--forcevariable",
  39. help = "Use forcevariable override for all output lines",
  40. action="store_true", dest="forcevariable")
  41. options, args = parser.parse_args(sys.argv)
  42. if len(args) != 2:
  43. parser.print_help()
  44. sys.exit(1)
  45. buildhistory_dir = args[1]
  46. if not os.path.exists(buildhistory_dir):
  47. logger.error('specified buildhistory path %s could not be found' % buildhistory_dir)
  48. sys.exit(1)
  49. if options.forcevariable:
  50. forcevariable = '_forcevariable'
  51. else:
  52. forcevariable = ''
  53. lastdir = ''
  54. for root, dirs, files in os.walk(buildhistory_dir):
  55. if '.git' in dirs:
  56. dirs.remove('.git')
  57. for fn in files:
  58. if fn == 'latest_srcrev':
  59. curdir = os.path.basename(os.path.dirname(root))
  60. if lastdir != curdir:
  61. print('# %s' % curdir)
  62. lastdir = curdir
  63. fullpath = os.path.join(root, fn)
  64. pn = os.path.basename(root)
  65. srcrev = None
  66. orig_srcrev = None
  67. orig_srcrevs = {}
  68. srcrevs = {}
  69. with open(fullpath) as f:
  70. for line in f:
  71. if '=' in line:
  72. splitval = line.split('=')
  73. value = splitval[1].strip('" \t\n\r')
  74. if line.startswith('# SRCREV = '):
  75. orig_srcrev = value
  76. elif line.startswith('# SRCREV_'):
  77. splitval = line.split('=')
  78. name = splitval[0].split('_')[1].strip()
  79. orig_srcrevs[name] = value
  80. elif line.startswith('SRCREV ='):
  81. srcrev = value
  82. elif line.startswith('SRCREV_'):
  83. name = splitval[0].split('_')[1].strip()
  84. srcrevs[name] = value
  85. if srcrev and (options.reportall or srcrev != orig_srcrev):
  86. print('SRCREV_pn-%s%s = "%s"' % (pn, forcevariable, srcrev))
  87. for name, value in srcrevs.items():
  88. orig = orig_srcrevs.get(name, orig_srcrev)
  89. if options.reportall or value != orig:
  90. print('SRCREV_%s_pn-%s%s = "%s"' % (name, pn, forcevariable, value))
  91. if __name__ == "__main__":
  92. main()