build-recipe-list.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) 2017, Intel Corporation.
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms and conditions of the GNU General Public License,
  7. # version 2, as published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. # more details.
  13. #
  14. import os
  15. import shutil
  16. import csv
  17. import sys
  18. import argparse
  19. __version__ = "0.1.0"
  20. # set of BPNs
  21. recipenames = set()
  22. # map of recipe -> data
  23. allrecipes = {}
  24. def make_bpn(recipe):
  25. prefixes = ("nativesdk-",)
  26. suffixes = ("-native", "-cross", "-initial", "-intermediate", "-crosssdk", "-cross-canadian")
  27. for ix in prefixes + suffixes:
  28. if ix in recipe:
  29. recipe = recipe.replace(ix, "")
  30. return recipe
  31. def gather_recipes(rows):
  32. for row in rows:
  33. recipe = row[0]
  34. bpn = make_bpn(recipe)
  35. if bpn not in recipenames:
  36. recipenames.add(bpn)
  37. if recipe not in allrecipes:
  38. allrecipes[recipe] = row
  39. def generate_recipe_list():
  40. # machine list
  41. machine_list = ( "qemuarm64", "qemuarm", "qemumips64", "qemumips", "qemuppc", "qemux86-64", "qemux86" )
  42. # set filename format
  43. fnformat = 'distrodata.%s.csv'
  44. # store all data files in distrodata
  45. datadir = 'distrodata'
  46. # create the directory if it does not exists
  47. if not os.path.exists(datadir):
  48. os.mkdir(datadir)
  49. # doing bitbake distrodata
  50. for machine in machine_list:
  51. os.system('MACHINE='+ machine + ' bitbake -k universe -c distrodata')
  52. shutil.copy('tmp/log/distrodata.csv', 'distrodata/' + fnformat % machine)
  53. for machine in machine_list:
  54. with open('distrodata/' + fnformat % machine) as f:
  55. reader = csv.reader(f)
  56. rows = reader.__iter__()
  57. gather_recipes(rows)
  58. with open('recipe-list.txt', 'w') as f:
  59. for recipe in sorted(recipenames):
  60. f.write("%s\n" % recipe)
  61. print("file : recipe-list.txt is created with %d entries." % len(recipenames))
  62. with open('all-recipe-list.txt', 'w') as f:
  63. for recipe, row in sorted(allrecipes.items()):
  64. f.write("%s\n" % ','.join(row))
  65. def diff_for_new_recipes(recipe1, recipe2):
  66. prev_recipe_path = recipe1 + '/'
  67. curr_recipe_path = recipe2 + '/'
  68. if not os.path.isfile(prev_recipe_path + 'recipe-list.txt') or not os.path.isfile(curr_recipe_path + 'recipe-list.txt'):
  69. print("recipe files do not exists. please verify that the file exists.")
  70. exit(1)
  71. import csv
  72. prev = []
  73. new = []
  74. with open(prev_recipe_path + 'recipe-list.txt') as f:
  75. prev = f.readlines()
  76. with open(curr_recipe_path + 'recipe-list.txt') as f:
  77. new = f.readlines()
  78. updates = []
  79. for pn in new:
  80. if not pn in prev:
  81. updates.append(pn.rstrip())
  82. allrecipe = []
  83. with open(recipe1 + '_' + recipe2 + '_new_recipe_list.txt','w') as dr:
  84. with open(curr_recipe_path + 'all-recipe-list.txt') as f:
  85. reader = csv.reader(f, delimiter=',')
  86. for row in reader:
  87. if row[0] in updates:
  88. dr.write("%s,%s,%s" % (row[0], row[3], row[5]))
  89. if len(row[9:]) > 0:
  90. dr.write(",%s" % ','.join(row[9:]))
  91. dr.write("\n")
  92. def main(argv):
  93. if argv[0] == "generate_recipe_list":
  94. generate_recipe_list()
  95. elif argv[0] == "compare_recipe":
  96. diff_for_new_recipes(argv[1], argv[2])
  97. else:
  98. print("no such option. choose either 'generate_recipe_list' or 'compare_recipe'")
  99. exit(0)
  100. if __name__ == "__main__":
  101. try:
  102. sys.exit(main(sys.argv[1:]))
  103. except Exception as e:
  104. print("Exception :", e)
  105. sys.exit(1)