blob: b8dd4c869eda3ff7d8e8828232463d411f558e76 [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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 # (Almost) always include our own inter-task dependencies.
24 # The exception is the special do_kernel_configme->do_unpack_and_patch
25 # dependency from archiver.bbclass.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026 if recipename == depname:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027 if task == "do_kernel_configme" and dep.endswith(".do_unpack_and_patch"):
28 return False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 return True
30
31 # Quilt (patch application) changing isn't likely to affect anything
32 excludelist = ['quilt-native', 'subversion-native', 'git-native']
33 if depname in excludelist and recipename != depname:
34 return False
35
36 # Exclude well defined recipe->dependency
37 if "%s->%s" % (recipename, depname) in siggen.saferecipedeps:
38 return False
39
40 # 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):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048 return False
49
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:
153 def recipename_from_dep(dep):
154 # The dep entry will look something like
155 # /path/path/recipename.bb.task, virtual:native:/p/foo.bb.task,
156 # ...
157 fn = dep.rsplit('.', 1)[0]
158 return dataCache.pkg_fn[fn]
159
160 # If any unlocked recipe is in the direct dependencies then the
161 # current recipe should be unlocked as well.
162 depnames = [ recipename_from_dep(x) for x in deps ]
163 if any(x in y for y in depnames for x in self.unlockedrecipes):
164 self.unlockedrecipes[recipename] = ''
165 unlocked = True
166
167 if not unlocked and recipename in self.lockedsigs:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168 if task in self.lockedsigs[recipename]:
169 k = fn + "." + task
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500170 h_locked = self.lockedsigs[recipename][task][0]
171 var = self.lockedsigs[recipename][task][1]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500172 self.lockedhashes[k] = h_locked
173 self.taskhash[k] = h_locked
174 #bb.warn("Using %s %s %s" % (recipename, task, h))
175
176 if h != h_locked:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500177 self.mismatch_msgs.append('The %s:%s sig is computed to be %s, but the sig is locked to %s in %s'
178 % (recipename, task, h, h_locked, var))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179
180 return h_locked
181 #bb.warn("%s %s %s" % (recipename, task, h))
182 return h
183
184 def dump_sigtask(self, fn, task, stampbase, runtime):
185 k = fn + "." + task
186 if k in self.lockedhashes:
187 return
188 super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigtask(fn, task, stampbase, runtime)
189
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600190 def dump_lockedsigs(self, sigfile, taskfilter=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191 types = {}
192 for k in self.runtaskdeps:
193 if taskfilter:
194 if not k in taskfilter:
195 continue
196 fn = k.rsplit(".",1)[0]
197 t = self.lockedhashfn[fn].split(" ")[1].split(":")[5]
198 t = 't-' + t.replace('_', '-')
199 if t not in types:
200 types[t] = []
201 types[t].append(k)
202
203 with open(sigfile, "w") as f:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500204 l = sorted(types)
205 for t in l:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t)
207 types[t].sort()
208 sortedk = sorted(types[t], key=lambda k: self.lockedpnmap[k.rsplit(".",1)[0]])
209 for k in sortedk:
210 fn = k.rsplit(".",1)[0]
211 task = k.rsplit(".",1)[1]
212 if k not in self.taskhash:
213 continue
214 f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.taskhash[k] + " \\\n")
215 f.write(' "\n')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 f.write('SIGGEN_LOCKEDSIGS_TYPES_%s = "%s"' % (self.machine, " ".join(l)))
217
218 def dump_siglist(self, sigfile):
219 with open(sigfile, "w") as f:
220 tasks = []
221 for taskitem in self.taskhash:
222 (fn, task) = taskitem.rsplit(".", 1)
223 pn = self.lockedpnmap[fn]
224 tasks.append((pn, task, fn, self.taskhash[taskitem]))
225 for (pn, task, fn, taskhash) in sorted(tasks):
226 f.write('%s.%s %s %s\n' % (pn, task, fn, taskhash))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227
228 def checkhashes(self, missed, ret, sq_fn, sq_task, sq_hash, sq_hashfn, d):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500229 warn_msgs = []
230 error_msgs = []
231 sstate_missing_msgs = []
232
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500233 for task in range(len(sq_fn)):
234 if task not in ret:
235 for pn in self.lockedsigs:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600236 if sq_hash[task] in iter(self.lockedsigs[pn].values()):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500237 if sq_task[task] == 'do_shared_workdir':
238 continue
239 sstate_missing_msgs.append("Locked sig is set for %s:%s (%s) yet not in sstate cache?"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240 % (pn, sq_task[task], sq_hash[task]))
241
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500242 checklevel = d.getVar("SIGGEN_LOCKEDSIGS_TASKSIG_CHECK")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500243 if checklevel == 'warn':
244 warn_msgs += self.mismatch_msgs
245 elif checklevel == 'error':
246 error_msgs += self.mismatch_msgs
247
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500248 checklevel = d.getVar("SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500249 if checklevel == 'warn':
250 warn_msgs += sstate_missing_msgs
251 elif checklevel == 'error':
252 error_msgs += sstate_missing_msgs
253
254 if warn_msgs:
255 bb.warn("\n".join(warn_msgs))
256 if error_msgs:
257 bb.fatal("\n".join(error_msgs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258
259
260# Insert these classes into siggen's namespace so it can see and select them
261bb.siggen.SignatureGeneratorOEBasic = SignatureGeneratorOEBasic
262bb.siggen.SignatureGeneratorOEBasicHash = SignatureGeneratorOEBasicHash
263
264
265def find_siginfo(pn, taskname, taskhashlist, d):
266 """ Find signature data files for comparison purposes """
267
268 import fnmatch
269 import glob
270
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500271 if not taskname:
272 # We have to derive pn and taskname
273 key = pn
274 splitit = key.split('.bb.')
275 taskname = splitit[1]
276 pn = os.path.basename(splitit[0]).split('_')[0]
277 if key.startswith('virtual:native:'):
278 pn = pn + '-native'
279
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 hashfiles = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281 filedates = {}
282
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500283 def get_hashval(siginfo):
284 if siginfo.endswith('.siginfo'):
285 return siginfo.rpartition(':')[2].partition('_')[0]
286 else:
287 return siginfo.rpartition('.')[2]
288
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289 # First search in stamps dir
290 localdata = d.createCopy()
291 localdata.setVar('MULTIMACH_TARGET_SYS', '*')
292 localdata.setVar('PN', pn)
293 localdata.setVar('PV', '*')
294 localdata.setVar('PR', '*')
295 localdata.setVar('EXTENDPE', '')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500296 stamp = localdata.getVar('STAMP')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500297 if pn.startswith("gcc-source"):
298 # gcc-source shared workdir is a special case :(
299 stamp = localdata.expand("${STAMPS_DIR}/work-shared/gcc-${PV}-${PR}")
300
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500301 filespec = '%s.%s.sigdata.*' % (stamp, taskname)
302 foundall = False
303 import glob
304 for fullpath in glob.glob(filespec):
305 match = False
306 if taskhashlist:
307 for taskhash in taskhashlist:
308 if fullpath.endswith('.%s' % taskhash):
309 hashfiles[taskhash] = fullpath
310 if len(hashfiles) == len(taskhashlist):
311 foundall = True
312 break
313 else:
314 try:
315 filedates[fullpath] = os.stat(fullpath).st_mtime
316 except OSError:
317 continue
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500318 hashval = get_hashval(fullpath)
319 hashfiles[hashval] = fullpath
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320
321 if not taskhashlist or (len(filedates) < 2 and not foundall):
322 # That didn't work, look in sstate-cache
323 hashes = taskhashlist or ['*']
324 localdata = bb.data.createCopy(d)
325 for hashval in hashes:
326 localdata.setVar('PACKAGE_ARCH', '*')
327 localdata.setVar('TARGET_VENDOR', '*')
328 localdata.setVar('TARGET_OS', '*')
329 localdata.setVar('PN', pn)
330 localdata.setVar('PV', '*')
331 localdata.setVar('PR', '*')
332 localdata.setVar('BB_TASKHASH', hashval)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500333 swspec = localdata.getVar('SSTATE_SWSPEC')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500334 if taskname in ['do_fetch', 'do_unpack', 'do_patch', 'do_populate_lic', 'do_preconfigure'] and swspec:
335 localdata.setVar('SSTATE_PKGSPEC', '${SSTATE_SWSPEC}')
336 elif pn.endswith('-native') or "-cross-" in pn or "-crosssdk-" in pn:
337 localdata.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/")
338 sstatename = taskname[3:]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500339 filespec = '%s_%s.*.siginfo' % (localdata.getVar('SSTATE_PKG'), sstatename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500341 matchedfiles = glob.glob(filespec)
342 for fullpath in matchedfiles:
343 actual_hashval = get_hashval(fullpath)
344 if actual_hashval in hashfiles:
345 continue
346 hashfiles[hashval] = fullpath
347 if not taskhashlist:
348 try:
349 filedates[fullpath] = os.stat(fullpath).st_mtime
350 except:
351 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352
353 if taskhashlist:
354 return hashfiles
355 else:
356 return filedates
357
358bb.siggen.find_siginfo = find_siginfo
359
360
361def sstate_get_manifest_filename(task, d):
362 """
363 Return the sstate manifest file path for a particular task.
364 Also returns the datastore that can be used to query related variables.
365 """
366 d2 = d.createCopy()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500367 extrainf = d.getVarFlag("do_" + task, 'stamp-extra-info')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500368 if extrainf:
369 d2.setVar("SSTATE_MANMACH", extrainf)
370 return (d2.expand("${SSTATE_MANFILEPREFIX}.%s" % task), d2)