blob: 6d1be3e3721f9fd159a65a464bf1f73306b28f55 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import bb.siggen
2
3def sstate_rundepfilter(siggen, fn, recipename, task, dep, depname, dataCache):
4 # Return True if we should keep the dependency, False to drop it
5 def isNative(x):
6 return x.endswith("-native")
7 def isCross(x):
8 return "-cross-" in x
9 def isNativeSDK(x):
10 return x.startswith("nativesdk-")
11 def isKernel(fn):
12 inherits = " ".join(dataCache.inherits[fn])
13 return inherits.find("/module-base.bbclass") != -1 or inherits.find("/linux-kernel-base.bbclass") != -1
14 def isPackageGroup(fn):
15 inherits = " ".join(dataCache.inherits[fn])
16 return "/packagegroup.bbclass" in inherits
17 def isAllArch(fn):
18 inherits = " ".join(dataCache.inherits[fn])
19 return "/allarch.bbclass" in inherits
20 def isImage(fn):
21 return "/image.bbclass" in " ".join(dataCache.inherits[fn])
22
23 # Always include our own inter-task dependencies
24 if recipename == depname:
25 return True
26
27 # Quilt (patch application) changing isn't likely to affect anything
28 excludelist = ['quilt-native', 'subversion-native', 'git-native']
29 if depname in excludelist and recipename != depname:
30 return False
31
32 # Exclude well defined recipe->dependency
33 if "%s->%s" % (recipename, depname) in siggen.saferecipedeps:
34 return False
35
36 # Don't change native/cross/nativesdk recipe dependencies any further
37 if isNative(recipename) or isCross(recipename) or isNativeSDK(recipename):
38 return True
39
40 # Only target packages beyond here
41
42 # allarch packagegroups are assumed to have well behaved names which don't change between architecures/tunes
43 if isPackageGroup(fn) and isAllArch(fn):
44 return False
45
46 # Exclude well defined machine specific configurations which don't change ABI
47 if depname in siggen.abisaferecipes and not isImage(fn):
48 return False
49
50 # Kernel modules are well namespaced. We don't want to depend on the kernel's checksum
51 # if we're just doing an RRECOMMENDS_xxx = "kernel-module-*", not least because the checksum
52 # is machine specific.
53 # Therefore if we're not a kernel or a module recipe (inheriting the kernel classes)
54 # and we reccomend a kernel-module, we exclude the dependency.
55 depfn = dep.rsplit(".", 1)[0]
56 if dataCache and isKernel(depfn) and not isKernel(fn):
57 for pkg in dataCache.runrecs[fn]:
58 if " ".join(dataCache.runrecs[fn][pkg]).find("kernel-module-") != -1:
59 return False
60
61 # Default to keep dependencies
62 return True
63
64def sstate_lockedsigs(d):
65 sigs = {}
66 types = (d.getVar("SIGGEN_LOCKEDSIGS_TYPES", True) or "").split()
67 for t in types:
68 lockedsigs = (d.getVar("SIGGEN_LOCKEDSIGS_%s" % t, True) or "").split()
69 for ls in lockedsigs:
70 pn, task, h = ls.split(":", 2)
71 if pn not in sigs:
72 sigs[pn] = {}
73 sigs[pn][task] = h
74 return sigs
75
76class SignatureGeneratorOEBasic(bb.siggen.SignatureGeneratorBasic):
77 name = "OEBasic"
78 def init_rundepcheck(self, data):
79 self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE", True) or "").split()
80 self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", True) or "").split()
81 pass
82 def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None):
83 return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache)
84
85class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash):
86 name = "OEBasicHash"
87 def init_rundepcheck(self, data):
88 self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE", True) or "").split()
89 self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", True) or "").split()
90 self.lockedsigs = sstate_lockedsigs(data)
91 self.lockedhashes = {}
92 self.lockedpnmap = {}
93 self.lockedhashfn = {}
94 self.machine = data.getVar("MACHINE", True)
95 self.mismatch_msgs = []
96 pass
Patrick Williamsf1e5d692016-03-30 15:21:19 -050097
98 def tasks_resolved(self, virtmap, virtpnmap, dataCache):
99 # Translate virtual/xxx entries to PN values
100 newabisafe = []
101 for a in self.abisaferecipes:
102 if a in virtpnmap:
103 newabisafe.append(virtpnmap[a])
104 else:
105 newabisafe.append(a)
106 self.abisaferecipes = newabisafe
107 newsafedeps = []
108 for a in self.saferecipedeps:
109 a1, a2 = a.split("->")
110 if a1 in virtpnmap:
111 a1 = virtpnmap[a1]
112 if a2 in virtpnmap:
113 a2 = virtpnmap[a2]
114 newsafedeps.append(a1 + "->" + a2)
115 self.saferecipedeps = newsafedeps
116
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117 def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None):
118 return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache)
119
120 def get_taskdata(self):
121 data = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskdata()
122 return (data, self.lockedpnmap, self.lockedhashfn)
123
124 def set_taskdata(self, data):
125 coredata, self.lockedpnmap, self.lockedhashfn = data
126 super(bb.siggen.SignatureGeneratorBasicHash, self).set_taskdata(coredata)
127
128 def dump_sigs(self, dataCache, options):
129 self.dump_lockedsigs()
130 return super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigs(dataCache, options)
131
132 def get_taskhash(self, fn, task, deps, dataCache):
133 h = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskhash(fn, task, deps, dataCache)
134
135 recipename = dataCache.pkg_fn[fn]
136 self.lockedpnmap[fn] = recipename
137 self.lockedhashfn[fn] = dataCache.hashfn[fn]
138 if recipename in self.lockedsigs:
139 if task in self.lockedsigs[recipename]:
140 k = fn + "." + task
141 h_locked = self.lockedsigs[recipename][task]
142 self.lockedhashes[k] = h_locked
143 self.taskhash[k] = h_locked
144 #bb.warn("Using %s %s %s" % (recipename, task, h))
145
146 if h != h_locked:
147 self.mismatch_msgs.append('The %s:%s sig (%s) changed, use locked sig %s to instead'
148 % (recipename, task, h, h_locked))
149
150 return h_locked
151 #bb.warn("%s %s %s" % (recipename, task, h))
152 return h
153
154 def dump_sigtask(self, fn, task, stampbase, runtime):
155 k = fn + "." + task
156 if k in self.lockedhashes:
157 return
158 super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigtask(fn, task, stampbase, runtime)
159
160 def dump_lockedsigs(self, sigfile=None, taskfilter=None):
161 if not sigfile:
162 sigfile = os.getcwd() + "/locked-sigs.inc"
163
164 bb.plain("Writing locked sigs to %s" % sigfile)
165 types = {}
166 for k in self.runtaskdeps:
167 if taskfilter:
168 if not k in taskfilter:
169 continue
170 fn = k.rsplit(".",1)[0]
171 t = self.lockedhashfn[fn].split(" ")[1].split(":")[5]
172 t = 't-' + t.replace('_', '-')
173 if t not in types:
174 types[t] = []
175 types[t].append(k)
176
177 with open(sigfile, "w") as f:
178 for t in types:
179 f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t)
180 types[t].sort()
181 sortedk = sorted(types[t], key=lambda k: self.lockedpnmap[k.rsplit(".",1)[0]])
182 for k in sortedk:
183 fn = k.rsplit(".",1)[0]
184 task = k.rsplit(".",1)[1]
185 if k not in self.taskhash:
186 continue
187 f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.taskhash[k] + " \\\n")
188 f.write(' "\n')
189 f.write('SIGGEN_LOCKEDSIGS_TYPES_%s = "%s"' % (self.machine, " ".join(types.keys())))
190
191 def checkhashes(self, missed, ret, sq_fn, sq_task, sq_hash, sq_hashfn, d):
192 checklevel = d.getVar("SIGGEN_LOCKEDSIGS_CHECK_LEVEL", True)
193 for task in range(len(sq_fn)):
194 if task not in ret:
195 for pn in self.lockedsigs:
196 if sq_hash[task] in self.lockedsigs[pn].itervalues():
197 self.mismatch_msgs.append("Locked sig is set for %s:%s (%s) yet not in sstate cache?"
198 % (pn, sq_task[task], sq_hash[task]))
199
200 if self.mismatch_msgs and checklevel == 'warn':
201 bb.warn("\n".join(self.mismatch_msgs))
202 elif self.mismatch_msgs and checklevel == 'error':
203 bb.fatal("\n".join(self.mismatch_msgs))
204
205
206# Insert these classes into siggen's namespace so it can see and select them
207bb.siggen.SignatureGeneratorOEBasic = SignatureGeneratorOEBasic
208bb.siggen.SignatureGeneratorOEBasicHash = SignatureGeneratorOEBasicHash
209
210
211def find_siginfo(pn, taskname, taskhashlist, d):
212 """ Find signature data files for comparison purposes """
213
214 import fnmatch
215 import glob
216
217 if taskhashlist:
218 hashfiles = {}
219
220 if not taskname:
221 # We have to derive pn and taskname
222 key = pn
223 splitit = key.split('.bb.')
224 taskname = splitit[1]
225 pn = os.path.basename(splitit[0]).split('_')[0]
226 if key.startswith('virtual:native:'):
227 pn = pn + '-native'
228
229 filedates = {}
230
231 # First search in stamps dir
232 localdata = d.createCopy()
233 localdata.setVar('MULTIMACH_TARGET_SYS', '*')
234 localdata.setVar('PN', pn)
235 localdata.setVar('PV', '*')
236 localdata.setVar('PR', '*')
237 localdata.setVar('EXTENDPE', '')
238 stamp = localdata.getVar('STAMP', True)
239 filespec = '%s.%s.sigdata.*' % (stamp, taskname)
240 foundall = False
241 import glob
242 for fullpath in glob.glob(filespec):
243 match = False
244 if taskhashlist:
245 for taskhash in taskhashlist:
246 if fullpath.endswith('.%s' % taskhash):
247 hashfiles[taskhash] = fullpath
248 if len(hashfiles) == len(taskhashlist):
249 foundall = True
250 break
251 else:
252 try:
253 filedates[fullpath] = os.stat(fullpath).st_mtime
254 except OSError:
255 continue
256
257 if not taskhashlist or (len(filedates) < 2 and not foundall):
258 # That didn't work, look in sstate-cache
259 hashes = taskhashlist or ['*']
260 localdata = bb.data.createCopy(d)
261 for hashval in hashes:
262 localdata.setVar('PACKAGE_ARCH', '*')
263 localdata.setVar('TARGET_VENDOR', '*')
264 localdata.setVar('TARGET_OS', '*')
265 localdata.setVar('PN', pn)
266 localdata.setVar('PV', '*')
267 localdata.setVar('PR', '*')
268 localdata.setVar('BB_TASKHASH', hashval)
269 swspec = localdata.getVar('SSTATE_SWSPEC', True)
270 if taskname in ['do_fetch', 'do_unpack', 'do_patch', 'do_populate_lic', 'do_preconfigure'] and swspec:
271 localdata.setVar('SSTATE_PKGSPEC', '${SSTATE_SWSPEC}')
272 elif pn.endswith('-native') or "-cross-" in pn or "-crosssdk-" in pn:
273 localdata.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/")
274 sstatename = taskname[3:]
275 filespec = '%s_%s.*.siginfo' % (localdata.getVar('SSTATE_PKG', True), sstatename)
276
277 if hashval != '*':
278 sstatedir = "%s/%s" % (d.getVar('SSTATE_DIR', True), hashval[:2])
279 else:
280 sstatedir = d.getVar('SSTATE_DIR', True)
281
282 for root, dirs, files in os.walk(sstatedir):
283 for fn in files:
284 fullpath = os.path.join(root, fn)
285 if fnmatch.fnmatch(fullpath, filespec):
286 if taskhashlist:
287 hashfiles[hashval] = fullpath
288 else:
289 try:
290 filedates[fullpath] = os.stat(fullpath).st_mtime
291 except:
292 continue
293
294 if taskhashlist:
295 return hashfiles
296 else:
297 return filedates
298
299bb.siggen.find_siginfo = find_siginfo
300
301
302def sstate_get_manifest_filename(task, d):
303 """
304 Return the sstate manifest file path for a particular task.
305 Also returns the datastore that can be used to query related variables.
306 """
307 d2 = d.createCopy()
308 extrainf = d.getVarFlag("do_" + task, 'stamp-extra-info', True)
309 if extrainf:
310 d2.setVar("SSTATE_MANMACH", extrainf)
311 return (d2.expand("${SSTATE_MANFILEPREFIX}.%s" % task), d2)