vala vala-native: Make use of GNOME_MIRROR in SRC_URI
[vuplus_openembedded] / classes / recipe_sanity.bbclass
1 def __note(msg, d):
2     import bb
3     bb.note("%s: recipe_sanity: %s" % (d.getVar("P", 1), msg))
4
5 __recipe_sanity_badtargetvars = "RDEPENDS RPROVIDES"
6 def bad_target_vars(cfgdata, d):
7     import bb.data
8     if bb.data.inherits_class("native", d) or \
9        bb.data.inherits_class("cross", d):
10         return
11
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)
16
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)
23
24     for var in d.getVar("__recipe_sanity_reqdiffvars", 1).split():
25         val = d.getVar(var, 0)
26         cfgval = cfgdata.get(var)
27
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"):
31             continue
32
33         if not val:
34             __note("%s should be set" % var, d)
35         elif val == cfgval:
36             __note("%s should be defined to something other than default (%s)" % (var, cfgval), d)
37
38 def var_renames_overwrite(cfgdata, d):
39     renames = d.getVar("__recipe_sanity_renames", 0)
40     if renames:
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)
44
45 def incorrect_nonempty_PACKAGES(cfgdata, d):
46     import bb.data
47     if bb.data.inherits_class("native", d) or \
48        bb.data.inherits_class("cross", d):
49         if d.getVar("PACKAGES", 1):
50             return True
51
52 def can_use_autotools_base(cfgdata, d):
53     import bb
54     cfg = d.getVar("do_configure", 1)
55     if not bb.data.inherits_class("autotools", d):
56         return False
57
58     for i in ["autoreconf"] + ["%s_do_configure" % cls for cls in ["gnome", "e", "autotools", "autotools_stage", "efl", "gpephone", "openmoko", "openmoko2", "xfce", "xlibs"]]:
59         if cfg.find(i) != -1:
60             return False
61
62     import os
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)
67
68     return True
69
70 def can_remove_FILESPATH(cfgdata, d):
71     import os
72     import bb
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)]
79     for fp in filespath:
80         if not fp in expectedpaths:
81             # __note("Path %s in FILESPATH not in the expected paths %s" %
82             # (fp, expectedpaths), d)
83             return False
84     return expected != unexpanded
85
86 def can_remove_FILESDIR(cfgdata, d):
87     import os
88     import bb
89     expected = cfgdata.get("FILESDIR")
90     #expected = "${@bb.which(d.getVar('FILESPATH', 1), '.')}"
91     unexpanded = d.getVar("FILESDIR", 0)
92     if unexpanded is None:
93         return False
94
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)]
98
99     return unexpanded != expected and \
100            os.path.exists(expanded) and \
101            (expanded in filespath or
102             expanded == bb.data.expand(expected, d))
103
104 def can_remove_others(p, cfgdata, d):
105     import bb
106     for k in ["S", "PV", "PN", "DESCRIPTION", "LICENSE", "DEPENDS",
107               "SECTION", "PACKAGES", "EXTRA_OECONF", "EXTRA_OEMAKE"]:
108     #for k in cfgdata:
109         unexpanded = d.getVar(k, 0)
110         cfgunexpanded = cfgdata.get(k)
111         if not cfgunexpanded:
112             continue
113
114         try:
115             expanded = d.getVar(k, 1)
116             cfgexpanded = bb.data.expand(cfgunexpanded, d)
117         except bb.fetch.ParameterError:
118             continue
119
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))
125
126 python do_recipe_sanity () {
127     p = d.getVar("P", 1)
128     p = "%s %s %s" % (d.getVar("PN", 1), d.getVar("PV", 1), d.getVar("PR", 1))
129
130     sanitychecks = [
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"),
135     ]
136     cfgdata = d.getVar("__recipe_sanity_cfgdata", 0)
137
138     for (func, msg) in sanitychecks:
139         if func(cfgdata, d):
140             __note(msg, d)
141
142     can_remove_others(p, cfgdata, d)
143     var_renames_overwrite(cfgdata, d)
144     req_vars(cfgdata, d)
145     bad_target_vars(cfgdata, d)
146 }
147 do_recipe_sanity[nostamp] = "1"
148 #do_recipe_sanity[recrdeptask] = "do_recipe_sanity"
149 addtask recipe_sanity
150
151 do_recipe_sanity_all[nostamp] = "1"
152 do_recipe_sanity_all[recrdeptask] = "do_recipe_sanity"
153 do_recipe_sanity_all () {
154     :
155 }
156 addtask recipe_sanity_all after do_recipe_sanity
157
158 python recipe_sanity_eh () {
159     from bb.event import getName
160
161     if getName(e) != "ConfigParsed":
162         return NotHandled
163
164     d = e.data
165
166     cfgdata = {}
167     for k in d.keys():
168     #for k in ["S", "PR", "PV", "PN", "DESCRIPTION", "LICENSE", "DEPENDS",
169     #          "SECTION"]:
170         cfgdata[k] = d.getVar(k, 0)
171
172     d.setVar("__recipe_sanity_cfgdata", cfgdata)
173     #d.setVar("__recipe_sanity_cfgdata", d)
174
175     # Sick, very sick..
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)
182         if oldvalue:
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
187 }
188 addhandler recipe_sanity_eh