2011-06-10 14:28:02 +00:00
def __note(msg, d):
2016-12-14 21:13:04 +00:00
bb.note("%s: recipe_sanity: %s" % (d.getVar("P"), msg))
2011-06-10 14:28:02 +00:00
__recipe_sanity_badruntimevars = "RDEPENDS RPROVIDES RRECOMMENDS RCONFLICTS"
def bad_runtime_vars(cfgdata, d):
if bb.data.inherits_class("native", d) or \
2012-08-20 16:52:21 +00:00
bb.data.inherits_class("cross", d):
2011-06-10 14:28:02 +00:00
return
2016-12-14 21:13:04 +00:00
for var in d.getVar("__recipe_sanity_badruntimevars").split():
2016-09-12 08:32:08 +00:00
val = d.getVar(var, False)
2011-06-10 14:28:02 +00:00
if val and val != cfgdata.get(var):
__note("%s should be %s_${PN}" % (var, var), d)
__recipe_sanity_reqvars = "DESCRIPTION"
2012-10-01 16:03:04 +00:00
__recipe_sanity_reqdiffvars = ""
2011-06-10 14:28:02 +00:00
def req_vars(cfgdata, d):
2016-12-14 21:13:04 +00:00
for var in d.getVar("__recipe_sanity_reqvars").split():
2016-09-12 08:32:08 +00:00
if not d.getVar(var, False):
2011-06-10 14:28:02 +00:00
__note("%s should be set" % var, d)
2016-12-14 21:13:04 +00:00
for var in d.getVar("__recipe_sanity_reqdiffvars").split():
2016-09-12 08:32:08 +00:00
val = d.getVar(var, False)
2011-06-10 14:28:02 +00:00
cfgval = cfgdata.get(var)
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):
2016-09-12 08:32:08 +00:00
renames = d.getVar("__recipe_sanity_renames", False)
2011-06-10 14:28:02 +00:00
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):
if bb.data.inherits_class("native", d) or \
2012-08-20 16:52:21 +00:00
bb.data.inherits_class("cross", d):
2016-12-14 21:13:04 +00:00
if d.getVar("PACKAGES"):
2011-06-10 14:28:02 +00:00
return True
def can_use_autotools_base(cfgdata, d):
2016-12-14 21:13:04 +00:00
cfg = d.getVar("do_configure")
2011-06-10 14:28:02 +00:00
if not bb.data.inherits_class("autotools", d):
return False
for i in ["autoreconf"] + ["%s_do_configure" % cls for cls in ["gnomebase", "gnome", "e", "autotools", "efl", "gpephone", "openmoko", "openmoko2", "xfce", "xlibs"]]:
if cfg.find(i) != -1:
return False
2016-09-12 08:32:08 +00:00
for clsfile in d.getVar("__inherit_cache", False):
2011-06-10 14:28:02 +00:00
(base, _) = os.path.splitext(os.path.basename(clsfile))
if cfg.find("%s_do_configure" % base) != -1:
__note("autotools_base usage needs verification, spotted %s_do_configure" % base, d)
return True
2013-08-24 16:01:20 +00:00
def can_delete_FILESPATH(cfgdata, d):
2011-06-10 14:28:02 +00:00
expected = cfgdata.get("FILESPATH")
2012-03-03 11:21:22 +00:00
expectedpaths = d.expand(expected)
2016-09-12 08:32:08 +00:00
unexpanded = d.getVar("FILESPATH", False)
2016-12-14 21:13:04 +00:00
filespath = d.getVar("FILESPATH").split(":")
2011-06-10 14:28:02 +00:00
filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)]
for fp in filespath:
if not fp in expectedpaths:
# __note("Path %s in FILESPATH not in the expected paths %s" %
# (fp, expectedpaths), d)
return False
return expected != unexpanded
2013-08-24 16:01:20 +00:00
def can_delete_others(p, cfgdata, d):
2012-10-01 16:03:04 +00:00
for k in ["S", "PV", "PN", "DESCRIPTION", "DEPENDS",
2011-06-10 14:28:02 +00:00
"SECTION", "PACKAGES", "EXTRA_OECONF", "EXTRA_OEMAKE"]:
#for k in cfgdata:
2016-09-12 08:32:08 +00:00
unexpanded = d.getVar(k, False)
2011-06-10 14:28:02 +00:00
cfgunexpanded = cfgdata.get(k)
if not cfgunexpanded:
continue
try:
2016-12-14 21:13:04 +00:00
expanded = d.getVar(k)
2012-03-03 11:21:22 +00:00
cfgexpanded = d.expand(cfgunexpanded)
2011-06-10 14:28:02 +00:00
except bb.fetch.ParameterError:
continue
if unexpanded != cfgunexpanded and \
cfgexpanded == expanded:
__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))
python do_recipe_sanity () {
2016-12-14 21:13:04 +00:00
p = d.getVar("P")
p = "%s %s %s" % (d.getVar("PN"), d.getVar("PV"), d.getVar("PR"))
2011-06-10 14:28:02 +00:00
sanitychecks = [
2013-08-24 16:01:20 +00:00
(can_delete_FILESPATH, "candidate for removal of FILESPATH"),
2011-06-10 14:28:02 +00:00
#(can_use_autotools_base, "candidate for use of autotools_base"),
(incorrect_nonempty_PACKAGES, "native or cross recipe with non-empty PACKAGES"),
]
2016-09-12 08:32:08 +00:00
cfgdata = d.getVar("__recipe_sanity_cfgdata", False)
2011-06-10 14:28:02 +00:00
for (func, msg) in sanitychecks:
if func(cfgdata, d):
__note(msg, d)
2013-08-24 16:01:20 +00:00
can_delete_others(p, cfgdata, d)
2011-06-10 14:28:02 +00:00
var_renames_overwrite(cfgdata, d)
req_vars(cfgdata, d)
bad_runtime_vars(cfgdata, d)
}
do_recipe_sanity[nostamp] = "1"
addtask recipe_sanity
do_recipe_sanity_all[nostamp] = "1"
2012-07-02 12:27:46 +00:00
do_recipe_sanity_all[recrdeptask] = "do_recipe_sanity_all do_recipe_sanity"
2011-06-10 14:28:02 +00:00
do_recipe_sanity_all () {
:
}
addtask recipe_sanity_all after do_recipe_sanity
python recipe_sanity_eh () {
d = e.data
cfgdata = {}
for k in d.keys():
2016-09-12 08:32:08 +00:00
if not isinstance(d.getVar(k, False), bb.data_smart.DataSmart):
cfgdata[k] = d.getVar(k, False)
2011-06-10 14:28:02 +00:00
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
2013-06-12 16:31:57 +00:00
recipe_sanity_eh[eventmask] = "bb.event.ConfigParsed"