diff options
Diffstat (limited to 'classes/recipe_sanity.bbclass')
-rw-r--r-- | classes/recipe_sanity.bbclass | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/classes/recipe_sanity.bbclass b/classes/recipe_sanity.bbclass index 4d00ddf1e5..29f4a8fada 100644 --- a/classes/recipe_sanity.bbclass +++ b/classes/recipe_sanity.bbclass @@ -1,3 +1,47 @@ +def __note(msg, d): + import bb + bb.note("%s: recipe_sanity: %s" % (d.getVar("P", 1), msg)) + +__recipe_sanity_badtargetvars = "RDEPENDS RPROVIDES" +def bad_target_vars(cfgdata, d): + import bb.data + if bb.data.inherits_class("native", d) or \ + bb.data.inherits_class("cross", d): + return + + for var in d.getVar("__recipe_sanity_badtargetvars", 1).split(): + val = d.getVar(var, 0) + if val and val != cfgdata.get(var): + __note("%s should not be set, but is set to '%s'" % (var, val), d) + +__recipe_sanity_reqvars = "DESCRIPTION" +__recipe_sanity_reqdiffvars = "LICENSE" +def req_vars(cfgdata, d): + for var in d.getVar("__recipe_sanity_reqvars", 1).split(): + if not d.getVar(var, 0): + __note("%s should be set" % var, d) + + for var in d.getVar("__recipe_sanity_reqdiffvars", 1).split(): + val = d.getVar(var, 0) + cfgval = cfgdata.get(var) + + # Hardcoding is bad, but I'm lazy. We don't care about license being + # unset if the recipe has no sources! + if var == "LICENSE" and d.getVar("SRC_URI", 1) == cfgdata.get("SRC_URI"): + continue + + if not val: + __note("%s should be set" % var, d) + elif val == cfgval: + __note("%s should be defined to something other than default (%s)" % (var, cfgval), d) + +def var_renames_overwrite(cfgdata, d): + renames = d.getVar("__recipe_sanity_renames", 0) + if renames: + for (key, newkey, oldvalue, newvalue) in renames: + if oldvalue != newvalue and oldvalue != cfgdata.get(newkey): + __note("rename of variable '%s' to '%s' overwrote existing value '%s' with '%s'." % (key, newkey, oldvalue, newvalue), d) + def incorrect_nonempty_PACKAGES(cfgdata, d): import bb.data if bb.data.inherits_class("native", d) or \ @@ -19,7 +63,7 @@ def can_use_autotools_base(cfgdata, d): for clsfile in d.getVar("__inherit_cache", 0): (base, _) = os.path.splitext(os.path.basename(clsfile)) if cfg.find("%s_do_configure" % base) != -1: - bb.note("%s: recipe_sanity: autotools_base usage needs verification, spotted %s" % (d.getVar("P", 1), "%s_do_configure" % base)) + __note("autotools_base usage needs verification, spotted %s_do_configure" % base, d) return True @@ -34,7 +78,8 @@ def can_remove_FILESPATH(cfgdata, d): filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)] for fp in filespath: if not fp in expectedpaths: - # bb.note("Path %s in FILESPATH not in the expected paths %s" % (fp, expectedpaths)) + # __note("Path %s in FILESPATH not in the expected paths %s" % + # (fp, expectedpaths), d) return False return expected != unexpanded @@ -74,7 +119,7 @@ def can_remove_others(p, cfgdata, d): if unexpanded != cfgunexpanded and \ cfgexpanded == expanded: - bb.note("%s: recipe_sanity: candidate for removal of %s" % (p, k)) + __note("candidate for removal of %s" % k, d) bb.debug(1, "%s: recipe_sanity: cfg's '%s' and d's '%s' both expand to %s" % (p, cfgunexpanded, unexpanded, expanded)) @@ -92,9 +137,12 @@ python do_recipe_sanity () { for (func, msg) in sanitychecks: if func(cfgdata, d): - bb.note("%s: recipe_sanity: %s" % (p, msg)) + __note(msg, d) can_remove_others(p, cfgdata, d) + var_renames_overwrite(cfgdata, d) + req_vars(cfgdata, d) + bad_target_vars(cfgdata, d) } do_recipe_sanity[nostamp] = "1" #do_recipe_sanity[recrdeptask] = "do_recipe_sanity" @@ -122,5 +170,19 @@ python recipe_sanity_eh () { cfgdata[k] = d.getVar(k, 0) d.setVar("__recipe_sanity_cfgdata", cfgdata) + #d.setVar("__recipe_sanity_cfgdata", d) + + # Sick, very sick.. + from bb.data_smart import DataSmart + old = DataSmart.renameVar + def myrename(self, key, newkey): + oldvalue = self.getVar(newkey, 0) + old(self, key, newkey) + newvalue = self.getVar(newkey, 0) + if oldvalue: + renames = self.getVar("__recipe_sanity_renames", 0) or set() + renames.add((key, newkey, oldvalue, newvalue)) + self.setVar("__recipe_sanity_renames", renames) + DataSmart.renameVar = myrename } addhandler recipe_sanity_eh |