3 bb.note("%s: recipe_sanity: %s" % (d.getVar("P", 1), msg))
5 __recipe_sanity_badtargetvars = "RDEPENDS RPROVIDES"
6 def bad_target_vars(cfgdata, d):
8 if bb.data.inherits_class("native", d) or \
9 bb.data.inherits_class("cross", d):
12 for var in d.getVar("__recipe_sanity_badtargetvars", 1).split():
13 val = d.getVar(var, 0)
14 if val and val != cfgdata.get(var):
15 __note("%s should not be set, but is set to '%s'" % (var, val), d)
17 __recipe_sanity_reqvars = "DESCRIPTION"
18 __recipe_sanity_reqdiffvars = "LICENSE"
19 def req_vars(cfgdata, d):
20 for var in d.getVar("__recipe_sanity_reqvars", 1).split():
21 if not d.getVar(var, 0):
22 __note("%s should be set" % var, d)
24 for var in d.getVar("__recipe_sanity_reqdiffvars", 1).split():
25 val = d.getVar(var, 0)
26 cfgval = cfgdata.get(var)
28 # Hardcoding is bad, but I'm lazy. We don't care about license being
29 # unset if the recipe has no sources!
30 if var == "LICENSE" and d.getVar("SRC_URI", 1) == cfgdata.get("SRC_URI"):
34 __note("%s should be set" % var, d)
36 __note("%s should be defined to something other than default (%s)" % (var, cfgval), d)
38 def var_renames_overwrite(cfgdata, d):
39 renames = d.getVar("__recipe_sanity_renames", 0)
41 for (key, newkey, oldvalue, newvalue) in renames:
42 if oldvalue != newvalue and oldvalue != cfgdata.get(newkey):
43 __note("rename of variable '%s' to '%s' overwrote existing value '%s' with '%s'." % (key, newkey, oldvalue, newvalue), d)
45 def incorrect_nonempty_PACKAGES(cfgdata, d):
47 if bb.data.inherits_class("native", d) or \
48 bb.data.inherits_class("cross", d):
49 if d.getVar("PACKAGES", 1):
52 def can_use_autotools_base(cfgdata, d):
54 cfg = d.getVar("do_configure", 1)
55 if not bb.data.inherits_class("autotools", d):
58 for i in ["autoreconf"] + ["%s_do_configure" % cls for cls in ["gnome", "e", "autotools", "autotools_stage", "efl", "gpephone", "openmoko", "openmoko2", "xfce", "xlibs"]]:
63 for clsfile in d.getVar("__inherit_cache", 0):
64 (base, _) = os.path.splitext(os.path.basename(clsfile))
65 if cfg.find("%s_do_configure" % base) != -1:
66 __note("autotools_base usage needs verification, spotted %s_do_configure" % base, d)
70 def can_remove_FILESPATH(cfgdata, d):
73 expected = cfgdata.get("FILESPATH")
74 #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}"
75 expectedpaths = bb.data.expand(expected, d)
76 unexpanded = d.getVar("FILESPATH", 0)
77 filespath = d.getVar("FILESPATH", 1).split(":")
78 filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)]
80 if not fp in expectedpaths:
81 # __note("Path %s in FILESPATH not in the expected paths %s" %
82 # (fp, expectedpaths), d)
84 return expected != unexpanded
86 def can_remove_FILESDIR(cfgdata, d):
89 expected = cfgdata.get("FILESDIR")
90 #expected = "${@bb.which(d.getVar('FILESPATH', 1), '.')}"
91 unexpanded = d.getVar("FILESDIR", 0)
92 if unexpanded is None:
95 expanded = os.path.normpath(d.getVar("FILESDIR", 1))
96 filespath = d.getVar("FILESPATH", 1).split(":")
97 filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)]
99 return unexpanded != expected and \
100 os.path.exists(expanded) and \
101 (expanded in filespath or
102 expanded == bb.data.expand(expected, d))
104 def can_remove_others(p, cfgdata, d):
106 for k in ["S", "PV", "PN", "DESCRIPTION", "LICENSE", "DEPENDS",
107 "SECTION", "PACKAGES", "EXTRA_OECONF", "EXTRA_OEMAKE"]:
109 unexpanded = d.getVar(k, 0)
110 cfgunexpanded = cfgdata.get(k)
111 if not cfgunexpanded:
115 expanded = d.getVar(k, 1)
116 cfgexpanded = bb.data.expand(cfgunexpanded, d)
117 except bb.fetch.ParameterError:
120 if unexpanded != cfgunexpanded and \
121 cfgexpanded == expanded:
122 __note("candidate for removal of %s" % k, d)
123 bb.debug(1, "%s: recipe_sanity: cfg's '%s' and d's '%s' both expand to %s" %
124 (p, cfgunexpanded, unexpanded, expanded))
126 python do_recipe_sanity () {
128 p = "%s %s %s" % (d.getVar("PN", 1), d.getVar("PV", 1), d.getVar("PR", 1))
131 (can_remove_FILESDIR, "candidate for removal of FILESDIR"),
132 (can_remove_FILESPATH, "candidate for removal of FILESPATH"),
133 #(can_use_autotools_base, "candidate for use of autotools_base"),
134 (incorrect_nonempty_PACKAGES, "native or cross recipe with non-empty PACKAGES"),
136 cfgdata = d.getVar("__recipe_sanity_cfgdata", 0)
138 for (func, msg) in sanitychecks:
142 can_remove_others(p, cfgdata, d)
143 var_renames_overwrite(cfgdata, d)
145 bad_target_vars(cfgdata, d)
147 do_recipe_sanity[nostamp] = "1"
148 #do_recipe_sanity[recrdeptask] = "do_recipe_sanity"
149 addtask recipe_sanity
151 do_recipe_sanity_all[nostamp] = "1"
152 do_recipe_sanity_all[recrdeptask] = "do_recipe_sanity"
153 do_recipe_sanity_all () {
156 addtask recipe_sanity_all after do_recipe_sanity
158 python recipe_sanity_eh () {
159 from bb.event import getName
161 if getName(e) != "ConfigParsed":
168 #for k in ["S", "PR", "PV", "PN", "DESCRIPTION", "LICENSE", "DEPENDS",
170 cfgdata[k] = d.getVar(k, 0)
172 d.setVar("__recipe_sanity_cfgdata", cfgdata)
173 #d.setVar("__recipe_sanity_cfgdata", d)
176 from bb.data_smart import DataSmart
177 old = DataSmart.renameVar
178 def myrename(self, key, newkey):
179 oldvalue = self.getVar(newkey, 0)
180 old(self, key, newkey)
181 newvalue = self.getVar(newkey, 0)
183 renames = self.getVar("__recipe_sanity_renames", 0) or set()
184 renames.add((key, newkey, oldvalue, newvalue))
185 self.setVar("__recipe_sanity_renames", renames)
186 DataSmart.renameVar = myrename
188 addhandler recipe_sanity_eh