recipe_sanity.bbclass 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. def __note(msg, d):
  2. bb.note("%s: recipe_sanity: %s" % (d.getVar("P"), msg))
  3. __recipe_sanity_badruntimevars = "RDEPENDS RPROVIDES RRECOMMENDS RCONFLICTS"
  4. def bad_runtime_vars(cfgdata, d):
  5. if bb.data.inherits_class("native", d) or \
  6. bb.data.inherits_class("cross", d):
  7. return
  8. for var in d.getVar("__recipe_sanity_badruntimevars").split():
  9. val = d.getVar(var, False)
  10. if val and val != cfgdata.get(var):
  11. __note("%s should be %s_${PN}" % (var, var), d)
  12. __recipe_sanity_reqvars = "DESCRIPTION"
  13. __recipe_sanity_reqdiffvars = ""
  14. def req_vars(cfgdata, d):
  15. for var in d.getVar("__recipe_sanity_reqvars").split():
  16. if not d.getVar(var, False):
  17. __note("%s should be set" % var, d)
  18. for var in d.getVar("__recipe_sanity_reqdiffvars").split():
  19. val = d.getVar(var, False)
  20. cfgval = cfgdata.get(var)
  21. if not val:
  22. __note("%s should be set" % var, d)
  23. elif val == cfgval:
  24. __note("%s should be defined to something other than default (%s)" % (var, cfgval), d)
  25. def var_renames_overwrite(cfgdata, d):
  26. renames = d.getVar("__recipe_sanity_renames", False)
  27. if renames:
  28. for (key, newkey, oldvalue, newvalue) in renames:
  29. if oldvalue != newvalue and oldvalue != cfgdata.get(newkey):
  30. __note("rename of variable '%s' to '%s' overwrote existing value '%s' with '%s'." % (key, newkey, oldvalue, newvalue), d)
  31. def incorrect_nonempty_PACKAGES(cfgdata, d):
  32. if bb.data.inherits_class("native", d) or \
  33. bb.data.inherits_class("cross", d):
  34. if d.getVar("PACKAGES"):
  35. return True
  36. def can_use_autotools_base(cfgdata, d):
  37. cfg = d.getVar("do_configure")
  38. if not bb.data.inherits_class("autotools", d):
  39. return False
  40. for i in ["autoreconf"] + ["%s_do_configure" % cls for cls in ["gnomebase", "gnome", "e", "autotools", "efl", "gpephone", "openmoko", "openmoko2", "xfce", "xlibs"]]:
  41. if cfg.find(i) != -1:
  42. return False
  43. for clsfile in d.getVar("__inherit_cache", False):
  44. (base, _) = os.path.splitext(os.path.basename(clsfile))
  45. if cfg.find("%s_do_configure" % base) != -1:
  46. __note("autotools_base usage needs verification, spotted %s_do_configure" % base, d)
  47. return True
  48. def can_delete_FILESPATH(cfgdata, d):
  49. expected = cfgdata.get("FILESPATH")
  50. expectedpaths = d.expand(expected)
  51. unexpanded = d.getVar("FILESPATH", False)
  52. filespath = d.getVar("FILESPATH").split(":")
  53. filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)]
  54. for fp in filespath:
  55. if not fp in expectedpaths:
  56. # __note("Path %s in FILESPATH not in the expected paths %s" %
  57. # (fp, expectedpaths), d)
  58. return False
  59. return expected != unexpanded
  60. def can_delete_others(p, cfgdata, d):
  61. for k in ["S", "PV", "PN", "DESCRIPTION", "DEPENDS",
  62. "SECTION", "PACKAGES", "EXTRA_OECONF", "EXTRA_OEMAKE"]:
  63. #for k in cfgdata:
  64. unexpanded = d.getVar(k, False)
  65. cfgunexpanded = cfgdata.get(k)
  66. if not cfgunexpanded:
  67. continue
  68. try:
  69. expanded = d.getVar(k)
  70. cfgexpanded = d.expand(cfgunexpanded)
  71. except bb.fetch.ParameterError:
  72. continue
  73. if unexpanded != cfgunexpanded and \
  74. cfgexpanded == expanded:
  75. __note("candidate for removal of %s" % k, d)
  76. bb.debug(1, "%s: recipe_sanity: cfg's '%s' and d's '%s' both expand to %s" %
  77. (p, cfgunexpanded, unexpanded, expanded))
  78. python do_recipe_sanity () {
  79. p = d.getVar("P")
  80. p = "%s %s %s" % (d.getVar("PN"), d.getVar("PV"), d.getVar("PR"))
  81. sanitychecks = [
  82. (can_delete_FILESPATH, "candidate for removal of FILESPATH"),
  83. #(can_use_autotools_base, "candidate for use of autotools_base"),
  84. (incorrect_nonempty_PACKAGES, "native or cross recipe with non-empty PACKAGES"),
  85. ]
  86. cfgdata = d.getVar("__recipe_sanity_cfgdata", False)
  87. for (func, msg) in sanitychecks:
  88. if func(cfgdata, d):
  89. __note(msg, d)
  90. can_delete_others(p, cfgdata, d)
  91. var_renames_overwrite(cfgdata, d)
  92. req_vars(cfgdata, d)
  93. bad_runtime_vars(cfgdata, d)
  94. }
  95. do_recipe_sanity[nostamp] = "1"
  96. addtask recipe_sanity
  97. do_recipe_sanity_all[nostamp] = "1"
  98. do_recipe_sanity_all[recrdeptask] = "do_recipe_sanity_all do_recipe_sanity"
  99. do_recipe_sanity_all () {
  100. :
  101. }
  102. addtask recipe_sanity_all after do_recipe_sanity
  103. python recipe_sanity_eh () {
  104. d = e.data
  105. cfgdata = {}
  106. for k in d.keys():
  107. if not isinstance(d.getVar(k, False), bb.data_smart.DataSmart):
  108. cfgdata[k] = d.getVar(k, False)
  109. d.setVar("__recipe_sanity_cfgdata", cfgdata)
  110. #d.setVar("__recipe_sanity_cfgdata", d)
  111. # Sick, very sick..
  112. from bb.data_smart import DataSmart
  113. old = DataSmart.renameVar
  114. def myrename(self, key, newkey):
  115. oldvalue = self.getVar(newkey, 0)
  116. old(self, key, newkey)
  117. newvalue = self.getVar(newkey, 0)
  118. if oldvalue:
  119. renames = self.getVar("__recipe_sanity_renames", 0) or set()
  120. renames.add((key, newkey, oldvalue, newvalue))
  121. self.setVar("__recipe_sanity_renames", renames)
  122. DataSmart.renameVar = myrename
  123. }
  124. addhandler recipe_sanity_eh
  125. recipe_sanity_eh[eventmask] = "bb.event.ConfigParsed"