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