summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Larson <clarson@mvista.com>2009-06-10 08:36:57 -0700
committerChris Larson <clarson@mvista.com>2009-06-10 08:36:59 -0700
commit8604f603321ce63ea5dc94334153af0841145fc6 (patch)
tree6301c6e7a23cd11f53feb40a596d68442ed0778f
parentd302cb3796aea6f77e3a32ae2e5d6c807ddbbcd0 (diff)
recipe_sanity.bbclass: add initial recipe sanity checker.
Currently just checks for variables which the recipe can avoid defining, as the values end up the same as the defaults. Formerly known as kergoth_sanity, but we all know such a thing is mythical ;) Signed-off-by: Chris Larson <clarson@mvista.com>
-rw-r--r--classes/recipe_sanity.bbclass111
1 files changed, 111 insertions, 0 deletions
diff --git a/classes/recipe_sanity.bbclass b/classes/recipe_sanity.bbclass
new file mode 100644
index 0000000000..a10755cf47
--- /dev/null
+++ b/classes/recipe_sanity.bbclass
@@ -0,0 +1,111 @@
+def can_use_autotools_base(cfgdata, d):
+ import bb
+ cfg = d.getVar("do_configure", 1)
+ if not bb.data.inherits_class("autotools", d):
+ return False
+
+ for i in ["autoreconf"] + ["%s_do_configure" % cls for cls in ["gnome", "e", "autotools", "autotools_stage", "efl", "gpephone", "openmoko", "openmoko2", "xfce", "xlibs"]]:
+ if cfg.find(i) != -1:
+ return False
+
+ import os
+ 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))
+
+ return True
+
+def can_remove_FILESPATH(cfgdata, d):
+ import os
+ import bb
+ expected = cfgdata.get("FILESPATH")
+ #expected = "${@':'.join([os.path.normpath(os.path.join(fp, p, o)) for fp in d.getVar('FILESPATHBASE', 1).split(':') for p in d.getVar('FILESPATHPKG', 1).split(':') for o in (d.getVar('OVERRIDES', 1) + ':').split(':') if os.path.exists(os.path.join(fp, p, o))])}:${FILESDIR}"
+ expectedpaths = bb.data.expand(expected, d)
+ unexpanded = d.getVar("FILESPATH", 0)
+ filespath = d.getVar("FILESPATH", 1).split(":")
+ 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))
+ return False
+ return expected != unexpanded
+
+def can_remove_FILESDIR(cfgdata, d):
+ import os
+ import bb
+ expected = cfgdata.get("FILESDIR")
+ #expected = "${@bb.which(d.getVar('FILESPATH', 1), '.')}"
+ unexpanded = d.getVar("FILESDIR", 0)
+ if unexpanded is None:
+ return False
+
+ expanded = os.path.normpath(d.getVar("FILESDIR", 1))
+ filespath = d.getVar("FILESPATH", 1).split(":")
+ filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)]
+
+ return unexpanded != expected and \
+ os.path.exists(expanded) and \
+ (expanded in filespath or
+ expanded == bb.data.expand(expected, d))
+
+def can_remove_others(p, cfgdata, d):
+ import bb
+ for k in ["S", "PV", "PN", "DESCRIPTION", "LICENSE", "DEPENDS",
+ "SECTION", "PACKAGES", "EXTRA_OECONF", "EXTRA_OEMAKE"]:
+ #for k in cfgdata:
+ unexpanded = d.getVar(k, 0)
+ cfgunexpanded = cfgdata.get(k)
+ if not cfgunexpanded:
+ continue
+
+ try:
+ expanded = d.getVar(k, 1)
+ cfgexpanded = bb.data.expand(cfgunexpanded, d)
+ except bb.fetch.ParameterError:
+ continue
+
+ if unexpanded != cfgunexpanded and \
+ cfgexpanded == expanded:
+ bb.note("%s: recipe_sanity: candidate for removal of %s" % (p, k))
+ 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 () {
+ p = d.getVar("P", 1)
+ p = "%s %s %s" % (d.getVar("PN", 1), d.getVar("PV", 1), d.getVar("PR", 1))
+
+ sanitychecks = [
+ (can_remove_FILESDIR, "removal of FILESDIR"),
+ (can_remove_FILESPATH, "removal of FILESPATH"),
+ #(can_use_autotools_base, "use of autotools_base"),
+ ]
+ cfgdata = d.getVar("__recipe_sanity_cfgdata", 0)
+
+ for (func, msg) in sanitychecks:
+ if func(cfgdata, d):
+ bb.note("%s: recipe_sanity: candidate for %s" % (p, msg))
+
+ can_remove_others(p, cfgdata, d)
+}
+do_recipe_sanity[nostamp] = "1"
+do_recipe_sanity[recrdeptask] = "do_recipe_sanity"
+addtask recipe_sanity
+
+python recipe_sanity_eh () {
+ from bb.event import getName
+
+ if getName(e) != "ConfigParsed":
+ return NotHandled
+
+ d = e.data
+
+ cfgdata = {}
+ for k in d.keys():
+ #for k in ["S", "PR", "PV", "PN", "DESCRIPTION", "LICENSE", "DEPENDS",
+ # "SECTION"]:
+ cfgdata[k] = d.getVar(k, 0)
+
+ d.setVar("__recipe_sanity_cfgdata", cfgdata)
+}
+addhandler recipe_sanity_eh