blob: 18c5a353a2a81d26811dea4dc16fd532776ec252 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import bb.siggen
Brad Bishop316dfdd2018-06-25 12:45:53 -04002import oe
Patrick Williamsc124f4f2015-09-15 14:41:29 -05003
4def sstate_rundepfilter(siggen, fn, recipename, task, dep, depname, dataCache):
5 # Return True if we should keep the dependency, False to drop it
6 def isNative(x):
7 return x.endswith("-native")
8 def isCross(x):
9 return "-cross-" in x
10 def isNativeSDK(x):
11 return x.startswith("nativesdk-")
12 def isKernel(fn):
13 inherits = " ".join(dataCache.inherits[fn])
14 return inherits.find("/module-base.bbclass") != -1 or inherits.find("/linux-kernel-base.bbclass") != -1
15 def isPackageGroup(fn):
16 inherits = " ".join(dataCache.inherits[fn])
17 return "/packagegroup.bbclass" in inherits
18 def isAllArch(fn):
19 inherits = " ".join(dataCache.inherits[fn])
20 return "/allarch.bbclass" in inherits
21 def isImage(fn):
22 return "/image.bbclass" in " ".join(dataCache.inherits[fn])
23
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024 # (Almost) always include our own inter-task dependencies.
25 # The exception is the special do_kernel_configme->do_unpack_and_patch
26 # dependency from archiver.bbclass.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027 if recipename == depname:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 if task == "do_kernel_configme" and dep.endswith(".do_unpack_and_patch"):
29 return False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030 return True
31
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032 # Exclude well defined recipe->dependency
33 if "%s->%s" % (recipename, depname) in siggen.saferecipedeps:
34 return False
35
Brad Bishop316dfdd2018-06-25 12:45:53 -040036 # Check for special wildcard
37 if "*->%s" % depname in siggen.saferecipedeps and recipename != depname:
38 return False
39
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 # Don't change native/cross/nativesdk recipe dependencies any further
41 if isNative(recipename) or isCross(recipename) or isNativeSDK(recipename):
42 return True
43
44 # Only target packages beyond here
45
46 # allarch packagegroups are assumed to have well behaved names which don't change between architecures/tunes
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050047 if isPackageGroup(fn) and isAllArch(fn) and not isNative(depname):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080048 return False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049
50 # Exclude well defined machine specific configurations which don't change ABI
51 if depname in siggen.abisaferecipes and not isImage(fn):
52 return False
53
54 # Kernel modules are well namespaced. We don't want to depend on the kernel's checksum
55 # if we're just doing an RRECOMMENDS_xxx = "kernel-module-*", not least because the checksum
56 # is machine specific.
57 # Therefore if we're not a kernel or a module recipe (inheriting the kernel classes)
58 # and we reccomend a kernel-module, we exclude the dependency.
59 depfn = dep.rsplit(".", 1)[0]
60 if dataCache and isKernel(depfn) and not isKernel(fn):
61 for pkg in dataCache.runrecs[fn]:
62 if " ".join(dataCache.runrecs[fn][pkg]).find("kernel-module-") != -1:
63 return False
64
65 # Default to keep dependencies
66 return True
67
68def sstate_lockedsigs(d):
69 sigs = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050070 types = (d.getVar("SIGGEN_LOCKEDSIGS_TYPES") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071 for t in types:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050072 siggen_lockedsigs_var = "SIGGEN_LOCKEDSIGS_%s" % t
Brad Bishop6e60e8b2018-02-01 10:27:11 -050073 lockedsigs = (d.getVar(siggen_lockedsigs_var) or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074 for ls in lockedsigs:
75 pn, task, h = ls.split(":", 2)
76 if pn not in sigs:
77 sigs[pn] = {}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050078 sigs[pn][task] = [h, siggen_lockedsigs_var]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079 return sigs
80
81class SignatureGeneratorOEBasic(bb.siggen.SignatureGeneratorBasic):
82 name = "OEBasic"
83 def init_rundepcheck(self, data):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050084 self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split()
85 self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086 pass
87 def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None):
88 return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache)
89
90class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash):
91 name = "OEBasicHash"
92 def init_rundepcheck(self, data):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split()
94 self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 self.lockedsigs = sstate_lockedsigs(data)
96 self.lockedhashes = {}
97 self.lockedpnmap = {}
98 self.lockedhashfn = {}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050099 self.machine = data.getVar("MACHINE")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 self.mismatch_msgs = []
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500101 self.unlockedrecipes = (data.getVar("SIGGEN_UNLOCKED_RECIPES") or
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500102 "").split()
103 self.unlockedrecipes = { k: "" for k in self.unlockedrecipes }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104 pass
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500105
106 def tasks_resolved(self, virtmap, virtpnmap, dataCache):
107 # Translate virtual/xxx entries to PN values
108 newabisafe = []
109 for a in self.abisaferecipes:
110 if a in virtpnmap:
111 newabisafe.append(virtpnmap[a])
112 else:
113 newabisafe.append(a)
114 self.abisaferecipes = newabisafe
115 newsafedeps = []
116 for a in self.saferecipedeps:
117 a1, a2 = a.split("->")
118 if a1 in virtpnmap:
119 a1 = virtpnmap[a1]
120 if a2 in virtpnmap:
121 a2 = virtpnmap[a2]
122 newsafedeps.append(a1 + "->" + a2)
123 self.saferecipedeps = newsafedeps
124
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None):
126 return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache)
127
128 def get_taskdata(self):
129 data = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskdata()
130 return (data, self.lockedpnmap, self.lockedhashfn)
131
132 def set_taskdata(self, data):
133 coredata, self.lockedpnmap, self.lockedhashfn = data
134 super(bb.siggen.SignatureGeneratorBasicHash, self).set_taskdata(coredata)
135
136 def dump_sigs(self, dataCache, options):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137 sigfile = os.getcwd() + "/locked-sigs.inc"
138 bb.plain("Writing locked sigs to %s" % sigfile)
139 self.dump_lockedsigs(sigfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140 return super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigs(dataCache, options)
141
142 def get_taskhash(self, fn, task, deps, dataCache):
143 h = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskhash(fn, task, deps, dataCache)
144
145 recipename = dataCache.pkg_fn[fn]
146 self.lockedpnmap[fn] = recipename
147 self.lockedhashfn[fn] = dataCache.hashfn[fn]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500148
149 unlocked = False
150 if recipename in self.unlockedrecipes:
151 unlocked = True
152 else:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800153 def get_mc(tid):
154 tid = tid.rsplit('.', 1)[0]
155 if tid.startswith('multiconfig:'):
156 elems = tid.split(':')
157 return elems[1]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500158 def recipename_from_dep(dep):
159 # The dep entry will look something like
160 # /path/path/recipename.bb.task, virtual:native:/p/foo.bb.task,
161 # ...
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800162
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500163 fn = dep.rsplit('.', 1)[0]
164 return dataCache.pkg_fn[fn]
165
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800166 mc = get_mc(fn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500167 # If any unlocked recipe is in the direct dependencies then the
168 # current recipe should be unlocked as well.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800169 depnames = [ recipename_from_dep(x) for x in deps if mc == get_mc(x)]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500170 if any(x in y for y in depnames for x in self.unlockedrecipes):
171 self.unlockedrecipes[recipename] = ''
172 unlocked = True
173
174 if not unlocked and recipename in self.lockedsigs:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175 if task in self.lockedsigs[recipename]:
176 k = fn + "." + task
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500177 h_locked = self.lockedsigs[recipename][task][0]
178 var = self.lockedsigs[recipename][task][1]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179 self.lockedhashes[k] = h_locked
180 self.taskhash[k] = h_locked
181 #bb.warn("Using %s %s %s" % (recipename, task, h))
182
183 if h != h_locked:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500184 self.mismatch_msgs.append('The %s:%s sig is computed to be %s, but the sig is locked to %s in %s'
185 % (recipename, task, h, h_locked, var))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
187 return h_locked
188 #bb.warn("%s %s %s" % (recipename, task, h))
189 return h
190
191 def dump_sigtask(self, fn, task, stampbase, runtime):
192 k = fn + "." + task
193 if k in self.lockedhashes:
194 return
195 super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigtask(fn, task, stampbase, runtime)
196
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600197 def dump_lockedsigs(self, sigfile, taskfilter=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 types = {}
199 for k in self.runtaskdeps:
200 if taskfilter:
201 if not k in taskfilter:
202 continue
203 fn = k.rsplit(".",1)[0]
204 t = self.lockedhashfn[fn].split(" ")[1].split(":")[5]
205 t = 't-' + t.replace('_', '-')
206 if t not in types:
207 types[t] = []
208 types[t].append(k)
209
210 with open(sigfile, "w") as f:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500211 l = sorted(types)
212 for t in l:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500213 f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t)
214 types[t].sort()
215 sortedk = sorted(types[t], key=lambda k: self.lockedpnmap[k.rsplit(".",1)[0]])
216 for k in sortedk:
217 fn = k.rsplit(".",1)[0]
218 task = k.rsplit(".",1)[1]
219 if k not in self.taskhash:
220 continue
221 f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.taskhash[k] + " \\\n")
222 f.write(' "\n')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500223 f.write('SIGGEN_LOCKEDSIGS_TYPES_%s = "%s"' % (self.machine, " ".join(l)))
224
225 def dump_siglist(self, sigfile):
226 with open(sigfile, "w") as f:
227 tasks = []
228 for taskitem in self.taskhash:
229 (fn, task) = taskitem.rsplit(".", 1)
230 pn = self.lockedpnmap[fn]
231 tasks.append((pn, task, fn, self.taskhash[taskitem]))
232 for (pn, task, fn, taskhash) in sorted(tasks):
233 f.write('%s.%s %s %s\n' % (pn, task, fn, taskhash))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234
235 def checkhashes(self, missed, ret, sq_fn, sq_task, sq_hash, sq_hashfn, d):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500236 warn_msgs = []
237 error_msgs = []
238 sstate_missing_msgs = []
239
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240 for task in range(len(sq_fn)):
241 if task not in ret:
242 for pn in self.lockedsigs:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600243 if sq_hash[task] in iter(self.lockedsigs[pn].values()):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500244 if sq_task[task] == 'do_shared_workdir':
245 continue
246 sstate_missing_msgs.append("Locked sig is set for %s:%s (%s) yet not in sstate cache?"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 % (pn, sq_task[task], sq_hash[task]))
248
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500249 checklevel = d.getVar("SIGGEN_LOCKEDSIGS_TASKSIG_CHECK")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500250 if checklevel == 'warn':
251 warn_msgs += self.mismatch_msgs
252 elif checklevel == 'error':
253 error_msgs += self.mismatch_msgs
254
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500255 checklevel = d.getVar("SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500256 if checklevel == 'warn':
257 warn_msgs += sstate_missing_msgs
258 elif checklevel == 'error':
259 error_msgs += sstate_missing_msgs
260
261 if warn_msgs:
262 bb.warn("\n".join(warn_msgs))
263 if error_msgs:
264 bb.fatal("\n".join(error_msgs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265
266
267# Insert these classes into siggen's namespace so it can see and select them
268bb.siggen.SignatureGeneratorOEBasic = SignatureGeneratorOEBasic
269bb.siggen.SignatureGeneratorOEBasicHash = SignatureGeneratorOEBasicHash
270
271
272def find_siginfo(pn, taskname, taskhashlist, d):
273 """ Find signature data files for comparison purposes """
274
275 import fnmatch
276 import glob
277
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 if not taskname:
279 # We have to derive pn and taskname
280 key = pn
281 splitit = key.split('.bb.')
282 taskname = splitit[1]
283 pn = os.path.basename(splitit[0]).split('_')[0]
284 if key.startswith('virtual:native:'):
285 pn = pn + '-native'
286
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500287 hashfiles = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288 filedates = {}
289
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500290 def get_hashval(siginfo):
291 if siginfo.endswith('.siginfo'):
292 return siginfo.rpartition(':')[2].partition('_')[0]
293 else:
294 return siginfo.rpartition('.')[2]
295
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500296 # First search in stamps dir
297 localdata = d.createCopy()
298 localdata.setVar('MULTIMACH_TARGET_SYS', '*')
299 localdata.setVar('PN', pn)
300 localdata.setVar('PV', '*')
301 localdata.setVar('PR', '*')
302 localdata.setVar('EXTENDPE', '')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 stamp = localdata.getVar('STAMP')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500304 if pn.startswith("gcc-source"):
305 # gcc-source shared workdir is a special case :(
306 stamp = localdata.expand("${STAMPS_DIR}/work-shared/gcc-${PV}-${PR}")
307
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308 filespec = '%s.%s.sigdata.*' % (stamp, taskname)
309 foundall = False
310 import glob
311 for fullpath in glob.glob(filespec):
312 match = False
313 if taskhashlist:
314 for taskhash in taskhashlist:
315 if fullpath.endswith('.%s' % taskhash):
316 hashfiles[taskhash] = fullpath
317 if len(hashfiles) == len(taskhashlist):
318 foundall = True
319 break
320 else:
321 try:
322 filedates[fullpath] = os.stat(fullpath).st_mtime
323 except OSError:
324 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500325 hashval = get_hashval(fullpath)
326 hashfiles[hashval] = fullpath
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500327
328 if not taskhashlist or (len(filedates) < 2 and not foundall):
329 # That didn't work, look in sstate-cache
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500330 hashes = taskhashlist or ['?' * 32]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331 localdata = bb.data.createCopy(d)
332 for hashval in hashes:
333 localdata.setVar('PACKAGE_ARCH', '*')
334 localdata.setVar('TARGET_VENDOR', '*')
335 localdata.setVar('TARGET_OS', '*')
336 localdata.setVar('PN', pn)
337 localdata.setVar('PV', '*')
338 localdata.setVar('PR', '*')
339 localdata.setVar('BB_TASKHASH', hashval)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500340 swspec = localdata.getVar('SSTATE_SWSPEC')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500341 if taskname in ['do_fetch', 'do_unpack', 'do_patch', 'do_populate_lic', 'do_preconfigure'] and swspec:
342 localdata.setVar('SSTATE_PKGSPEC', '${SSTATE_SWSPEC}')
343 elif pn.endswith('-native') or "-cross-" in pn or "-crosssdk-" in pn:
344 localdata.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/")
345 sstatename = taskname[3:]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500346 filespec = '%s_%s.*.siginfo' % (localdata.getVar('SSTATE_PKG'), sstatename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500348 matchedfiles = glob.glob(filespec)
349 for fullpath in matchedfiles:
350 actual_hashval = get_hashval(fullpath)
351 if actual_hashval in hashfiles:
352 continue
353 hashfiles[hashval] = fullpath
354 if not taskhashlist:
355 try:
356 filedates[fullpath] = os.stat(fullpath).st_mtime
357 except:
358 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500359
360 if taskhashlist:
361 return hashfiles
362 else:
363 return filedates
364
365bb.siggen.find_siginfo = find_siginfo
366
367
368def sstate_get_manifest_filename(task, d):
369 """
370 Return the sstate manifest file path for a particular task.
371 Also returns the datastore that can be used to query related variables.
372 """
373 d2 = d.createCopy()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500374 extrainf = d.getVarFlag("do_" + task, 'stamp-extra-info')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500375 if extrainf:
376 d2.setVar("SSTATE_MANMACH", extrainf)
377 return (d2.expand("${SSTATE_MANFILEPREFIX}.%s" % task), d2)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400378
379def find_sstate_manifest(taskdata, taskdata2, taskname, d, multilibcache):
380 d2 = d
381 variant = ''
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800382 curr_variant = ''
383 if d.getVar("BBEXTENDCURR") == "multilib":
384 curr_variant = d.getVar("BBEXTENDVARIANT")
385 if "virtclass-multilib" not in d.getVar("OVERRIDES"):
386 curr_variant = "invalid"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400387 if taskdata2.startswith("virtual:multilib"):
388 variant = taskdata2.split(":")[2]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800389 if curr_variant != variant:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400390 if variant not in multilibcache:
391 multilibcache[variant] = oe.utils.get_multilib_datastore(variant, d)
392 d2 = multilibcache[variant]
393
394 if taskdata.endswith("-native"):
395 pkgarchs = ["${BUILD_ARCH}"]
396 elif taskdata.startswith("nativesdk-"):
397 pkgarchs = ["${SDK_ARCH}_${SDK_OS}", "allarch"]
398 elif "-cross-canadian" in taskdata:
399 pkgarchs = ["${SDK_ARCH}_${SDK_ARCH}-${SDKPKGSUFFIX}"]
400 elif "-cross-" in taskdata:
401 pkgarchs = ["${BUILD_ARCH}_${TARGET_ARCH}"]
402 elif "-crosssdk" in taskdata:
403 pkgarchs = ["${BUILD_ARCH}_${SDK_ARCH}_${SDK_OS}"]
404 else:
405 pkgarchs = ['${MACHINE_ARCH}']
406 pkgarchs = pkgarchs + list(reversed(d2.getVar("PACKAGE_EXTRA_ARCHS").split()))
407 pkgarchs.append('allarch')
408 pkgarchs.append('${SDK_ARCH}_${SDK_ARCH}-${SDKPKGSUFFIX}')
409
410 for pkgarch in pkgarchs:
411 manifest = d2.expand("${SSTATE_MANIFESTS}/manifest-%s-%s.%s" % (pkgarch, taskdata, taskname))
412 if os.path.exists(manifest):
413 return manifest, d2
414 bb.warn("Manifest %s not found in %s (variant '%s')?" % (manifest, d2.expand(" ".join(pkgarchs)), variant))
415 return None, d2
416
417