diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /meta/classes/recipe_sanity.bbclass | |
download | poky-daisy-140929.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/classes/recipe_sanity.bbclass')
-rw-r--r-- | meta/classes/recipe_sanity.bbclass | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/meta/classes/recipe_sanity.bbclass b/meta/classes/recipe_sanity.bbclass new file mode 100644 index 0000000000..5dd4624f40 --- /dev/null +++ b/meta/classes/recipe_sanity.bbclass | |||
@@ -0,0 +1,168 @@ | |||
1 | def __note(msg, d): | ||
2 | bb.note("%s: recipe_sanity: %s" % (d.getVar("P", True), msg)) | ||
3 | |||
4 | __recipe_sanity_badruntimevars = "RDEPENDS RPROVIDES RRECOMMENDS RCONFLICTS" | ||
5 | def 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 = "" | ||
17 | def 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 | |||
31 | def 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 | |||
38 | def 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 | |||
44 | def 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 | |||
60 | def can_delete_FILESPATH(cfgdata, d): | ||
61 | expected = cfgdata.get("FILESPATH") | ||
62 | #expected = "${@':'.join([os.path.normpath(os.path.join(fp, p, o)) for fp in d.getVar('FILESPATHBASE', True).split(':') for p in d.getVar('FILESPATHPKG', True).split(':') for o in (d.getVar('OVERRIDES', True) + ':').split(':') if os.path.exists(os.path.join(fp, p, o))])}:${FILESDIR}" | ||
63 | expectedpaths = d.expand(expected) | ||
64 | unexpanded = d.getVar("FILESPATH", 0) | ||
65 | filespath = d.getVar("FILESPATH", True).split(":") | ||
66 | filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)] | ||
67 | for fp in filespath: | ||
68 | if not fp in expectedpaths: | ||
69 | # __note("Path %s in FILESPATH not in the expected paths %s" % | ||
70 | # (fp, expectedpaths), d) | ||
71 | return False | ||
72 | return expected != unexpanded | ||
73 | |||
74 | def can_delete_FILESDIR(cfgdata, d): | ||
75 | expected = cfgdata.get("FILESDIR") | ||
76 | #expected = "${@bb.utils.which(d.getVar('FILESPATH', True), '.')}" | ||
77 | unexpanded = d.getVar("FILESDIR", 0) | ||
78 | if unexpanded is None: | ||
79 | return False | ||
80 | |||
81 | expanded = os.path.normpath(d.getVar("FILESDIR", True)) | ||
82 | filespath = d.getVar("FILESPATH", True).split(":") | ||
83 | filespath = [os.path.normpath(f) for f in filespath if os.path.exists(f)] | ||
84 | |||
85 | return unexpanded != expected and \ | ||
86 | os.path.exists(expanded) and \ | ||
87 | (expanded in filespath or | ||
88 | expanded == d.expand(expected)) | ||
89 | |||
90 | def can_delete_others(p, cfgdata, d): | ||
91 | for k in ["S", "PV", "PN", "DESCRIPTION", "DEPENDS", | ||
92 | "SECTION", "PACKAGES", "EXTRA_OECONF", "EXTRA_OEMAKE"]: | ||
93 | #for k in cfgdata: | ||
94 | unexpanded = d.getVar(k, 0) | ||
95 | cfgunexpanded = cfgdata.get(k) | ||
96 | if not cfgunexpanded: | ||
97 | continue | ||
98 | |||
99 | try: | ||
100 | expanded = d.getVar(k, True) | ||
101 | cfgexpanded = d.expand(cfgunexpanded) | ||
102 | except bb.fetch.ParameterError: | ||
103 | continue | ||
104 | |||
105 | if unexpanded != cfgunexpanded and \ | ||
106 | cfgexpanded == expanded: | ||
107 | __note("candidate for removal of %s" % k, d) | ||
108 | bb.debug(1, "%s: recipe_sanity: cfg's '%s' and d's '%s' both expand to %s" % | ||
109 | (p, cfgunexpanded, unexpanded, expanded)) | ||
110 | |||
111 | python do_recipe_sanity () { | ||
112 | p = d.getVar("P", True) | ||
113 | p = "%s %s %s" % (d.getVar("PN", True), d.getVar("PV", True), d.getVar("PR", True)) | ||
114 | |||
115 | sanitychecks = [ | ||
116 | (can_delete_FILESDIR, "candidate for removal of FILESDIR"), | ||
117 | (can_delete_FILESPATH, "candidate for removal of FILESPATH"), | ||
118 | #(can_use_autotools_base, "candidate for use of autotools_base"), | ||
119 | (incorrect_nonempty_PACKAGES, "native or cross recipe with non-empty PACKAGES"), | ||
120 | ] | ||
121 | cfgdata = d.getVar("__recipe_sanity_cfgdata", 0) | ||
122 | |||
123 | for (func, msg) in sanitychecks: | ||
124 | if func(cfgdata, d): | ||
125 | __note(msg, d) | ||
126 | |||
127 | can_delete_others(p, cfgdata, d) | ||
128 | var_renames_overwrite(cfgdata, d) | ||
129 | req_vars(cfgdata, d) | ||
130 | bad_runtime_vars(cfgdata, d) | ||
131 | } | ||
132 | do_recipe_sanity[nostamp] = "1" | ||
133 | addtask recipe_sanity | ||
134 | |||
135 | do_recipe_sanity_all[nostamp] = "1" | ||
136 | do_recipe_sanity_all[recrdeptask] = "do_recipe_sanity_all do_recipe_sanity" | ||
137 | do_recipe_sanity_all () { | ||
138 | : | ||
139 | } | ||
140 | addtask recipe_sanity_all after do_recipe_sanity | ||
141 | |||
142 | python recipe_sanity_eh () { | ||
143 | d = e.data | ||
144 | |||
145 | cfgdata = {} | ||
146 | for k in d.keys(): | ||
147 | #for k in ["S", "PR", "PV", "PN", "DESCRIPTION", "LICENSE", "DEPENDS", | ||
148 | # "SECTION"]: | ||
149 | cfgdata[k] = d.getVar(k, 0) | ||
150 | |||
151 | d.setVar("__recipe_sanity_cfgdata", cfgdata) | ||
152 | #d.setVar("__recipe_sanity_cfgdata", d) | ||
153 | |||
154 | # Sick, very sick.. | ||
155 | from bb.data_smart import DataSmart | ||
156 | old = DataSmart.renameVar | ||
157 | def myrename(self, key, newkey): | ||
158 | oldvalue = self.getVar(newkey, 0) | ||
159 | old(self, key, newkey) | ||
160 | newvalue = self.getVar(newkey, 0) | ||
161 | if oldvalue: | ||
162 | renames = self.getVar("__recipe_sanity_renames", 0) or set() | ||
163 | renames.add((key, newkey, oldvalue, newvalue)) | ||
164 | self.setVar("__recipe_sanity_renames", renames) | ||
165 | DataSmart.renameVar = myrename | ||
166 | } | ||
167 | addhandler recipe_sanity_eh | ||
168 | recipe_sanity_eh[eventmask] = "bb.event.ConfigParsed" | ||