blob: 01dce660cf40f2a9f1ad13da549d4936042f0bb5 [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
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043 if isPackageGroup(fn) and isAllArch(fn) and not isNative(depname):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050044 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:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050068 siggen_lockedsigs_var = "SIGGEN_LOCKEDSIGS_%s" % t
69 lockedsigs = (d.getVar(siggen_lockedsigs_var, True) or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070 for ls in lockedsigs:
71 pn, task, h = ls.split(":", 2)
72 if pn not in sigs:
73 sigs[pn] = {}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050074 sigs[pn][task] = [h, siggen_lockedsigs_var]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 return sigs
76
77class SignatureGeneratorOEBasic(bb.siggen.SignatureGeneratorBasic):
78 name = "OEBasic"
79 def init_rundepcheck(self, data):
80 self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE", True) or "").split()
81 self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", True) or "").split()
82 pass
83 def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None):
84 return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache)
85
86class SignatureGeneratorOEBasicHash(bb.siggen.SignatureGeneratorBasicHash):
87 name = "OEBasicHash"
88 def init_rundepcheck(self, data):
89 self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE", True) or "").split()
90 self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS", True) or "").split()
91 self.lockedsigs = sstate_lockedsigs(data)
92 self.lockedhashes = {}
93 self.lockedpnmap = {}
94 self.lockedhashfn = {}
95 self.machine = data.getVar("MACHINE", True)
96 self.mismatch_msgs = []
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050097 self.unlockedrecipes = (data.getVar("SIGGEN_UNLOCKED_RECIPES", True) or
98 "").split()
99 self.unlockedrecipes = { k: "" for k in self.unlockedrecipes }
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100 pass
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500101
102 def tasks_resolved(self, virtmap, virtpnmap, dataCache):
103 # Translate virtual/xxx entries to PN values
104 newabisafe = []
105 for a in self.abisaferecipes:
106 if a in virtpnmap:
107 newabisafe.append(virtpnmap[a])
108 else:
109 newabisafe.append(a)
110 self.abisaferecipes = newabisafe
111 newsafedeps = []
112 for a in self.saferecipedeps:
113 a1, a2 = a.split("->")
114 if a1 in virtpnmap:
115 a1 = virtpnmap[a1]
116 if a2 in virtpnmap:
117 a2 = virtpnmap[a2]
118 newsafedeps.append(a1 + "->" + a2)
119 self.saferecipedeps = newsafedeps
120
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500121 def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None):
122 return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache)
123
124 def get_taskdata(self):
125 data = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskdata()
126 return (data, self.lockedpnmap, self.lockedhashfn)
127
128 def set_taskdata(self, data):
129 coredata, self.lockedpnmap, self.lockedhashfn = data
130 super(bb.siggen.SignatureGeneratorBasicHash, self).set_taskdata(coredata)
131
132 def dump_sigs(self, dataCache, options):
133 self.dump_lockedsigs()
134 return super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigs(dataCache, options)
135
136 def get_taskhash(self, fn, task, deps, dataCache):
137 h = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskhash(fn, task, deps, dataCache)
138
139 recipename = dataCache.pkg_fn[fn]
140 self.lockedpnmap[fn] = recipename
141 self.lockedhashfn[fn] = dataCache.hashfn[fn]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500142
143 unlocked = False
144 if recipename in self.unlockedrecipes:
145 unlocked = True
146 else:
147 def recipename_from_dep(dep):
148 # The dep entry will look something like
149 # /path/path/recipename.bb.task, virtual:native:/p/foo.bb.task,
150 # ...
151 fn = dep.rsplit('.', 1)[0]
152 return dataCache.pkg_fn[fn]
153
154 # If any unlocked recipe is in the direct dependencies then the
155 # current recipe should be unlocked as well.
156 depnames = [ recipename_from_dep(x) for x in deps ]
157 if any(x in y for y in depnames for x in self.unlockedrecipes):
158 self.unlockedrecipes[recipename] = ''
159 unlocked = True
160
161 if not unlocked and recipename in self.lockedsigs:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162 if task in self.lockedsigs[recipename]:
163 k = fn + "." + task
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500164 h_locked = self.lockedsigs[recipename][task][0]
165 var = self.lockedsigs[recipename][task][1]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166 self.lockedhashes[k] = h_locked
167 self.taskhash[k] = h_locked
168 #bb.warn("Using %s %s %s" % (recipename, task, h))
169
170 if h != h_locked:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500171 self.mismatch_msgs.append('The %s:%s sig is computed to be %s, but the sig is locked to %s in %s'
172 % (recipename, task, h, h_locked, var))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173
174 return h_locked
175 #bb.warn("%s %s %s" % (recipename, task, h))
176 return h
177
178 def dump_sigtask(self, fn, task, stampbase, runtime):
179 k = fn + "." + task
180 if k in self.lockedhashes:
181 return
182 super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigtask(fn, task, stampbase, runtime)
183
184 def dump_lockedsigs(self, sigfile=None, taskfilter=None):
185 if not sigfile:
186 sigfile = os.getcwd() + "/locked-sigs.inc"
187
188 bb.plain("Writing locked sigs to %s" % sigfile)
189 types = {}
190 for k in self.runtaskdeps:
191 if taskfilter:
192 if not k in taskfilter:
193 continue
194 fn = k.rsplit(".",1)[0]
195 t = self.lockedhashfn[fn].split(" ")[1].split(":")[5]
196 t = 't-' + t.replace('_', '-')
197 if t not in types:
198 types[t] = []
199 types[t].append(k)
200
201 with open(sigfile, "w") as f:
202 for t in types:
203 f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t)
204 types[t].sort()
205 sortedk = sorted(types[t], key=lambda k: self.lockedpnmap[k.rsplit(".",1)[0]])
206 for k in sortedk:
207 fn = k.rsplit(".",1)[0]
208 task = k.rsplit(".",1)[1]
209 if k not in self.taskhash:
210 continue
211 f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.taskhash[k] + " \\\n")
212 f.write(' "\n')
213 f.write('SIGGEN_LOCKEDSIGS_TYPES_%s = "%s"' % (self.machine, " ".join(types.keys())))
214
215 def checkhashes(self, missed, ret, sq_fn, sq_task, sq_hash, sq_hashfn, d):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500216 warn_msgs = []
217 error_msgs = []
218 sstate_missing_msgs = []
219
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220 for task in range(len(sq_fn)):
221 if task not in ret:
222 for pn in self.lockedsigs:
223 if sq_hash[task] in self.lockedsigs[pn].itervalues():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500224 if sq_task[task] == 'do_shared_workdir':
225 continue
226 sstate_missing_msgs.append("Locked sig is set for %s:%s (%s) yet not in sstate cache?"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227 % (pn, sq_task[task], sq_hash[task]))
228
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500229 checklevel = d.getVar("SIGGEN_LOCKEDSIGS_TASKSIG_CHECK", True)
230 if checklevel == 'warn':
231 warn_msgs += self.mismatch_msgs
232 elif checklevel == 'error':
233 error_msgs += self.mismatch_msgs
234
235 checklevel = d.getVar("SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK", True)
236 if checklevel == 'warn':
237 warn_msgs += sstate_missing_msgs
238 elif checklevel == 'error':
239 error_msgs += sstate_missing_msgs
240
241 if warn_msgs:
242 bb.warn("\n".join(warn_msgs))
243 if error_msgs:
244 bb.fatal("\n".join(error_msgs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500245
246
247# Insert these classes into siggen's namespace so it can see and select them
248bb.siggen.SignatureGeneratorOEBasic = SignatureGeneratorOEBasic
249bb.siggen.SignatureGeneratorOEBasicHash = SignatureGeneratorOEBasicHash
250
251
252def find_siginfo(pn, taskname, taskhashlist, d):
253 """ Find signature data files for comparison purposes """
254
255 import fnmatch
256 import glob
257
258 if taskhashlist:
259 hashfiles = {}
260
261 if not taskname:
262 # We have to derive pn and taskname
263 key = pn
264 splitit = key.split('.bb.')
265 taskname = splitit[1]
266 pn = os.path.basename(splitit[0]).split('_')[0]
267 if key.startswith('virtual:native:'):
268 pn = pn + '-native'
269
270 filedates = {}
271
272 # First search in stamps dir
273 localdata = d.createCopy()
274 localdata.setVar('MULTIMACH_TARGET_SYS', '*')
275 localdata.setVar('PN', pn)
276 localdata.setVar('PV', '*')
277 localdata.setVar('PR', '*')
278 localdata.setVar('EXTENDPE', '')
279 stamp = localdata.getVar('STAMP', True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500280 if pn.startswith("gcc-source"):
281 # gcc-source shared workdir is a special case :(
282 stamp = localdata.expand("${STAMPS_DIR}/work-shared/gcc-${PV}-${PR}")
283
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284 filespec = '%s.%s.sigdata.*' % (stamp, taskname)
285 foundall = False
286 import glob
287 for fullpath in glob.glob(filespec):
288 match = False
289 if taskhashlist:
290 for taskhash in taskhashlist:
291 if fullpath.endswith('.%s' % taskhash):
292 hashfiles[taskhash] = fullpath
293 if len(hashfiles) == len(taskhashlist):
294 foundall = True
295 break
296 else:
297 try:
298 filedates[fullpath] = os.stat(fullpath).st_mtime
299 except OSError:
300 continue
301
302 if not taskhashlist or (len(filedates) < 2 and not foundall):
303 # That didn't work, look in sstate-cache
304 hashes = taskhashlist or ['*']
305 localdata = bb.data.createCopy(d)
306 for hashval in hashes:
307 localdata.setVar('PACKAGE_ARCH', '*')
308 localdata.setVar('TARGET_VENDOR', '*')
309 localdata.setVar('TARGET_OS', '*')
310 localdata.setVar('PN', pn)
311 localdata.setVar('PV', '*')
312 localdata.setVar('PR', '*')
313 localdata.setVar('BB_TASKHASH', hashval)
314 swspec = localdata.getVar('SSTATE_SWSPEC', True)
315 if taskname in ['do_fetch', 'do_unpack', 'do_patch', 'do_populate_lic', 'do_preconfigure'] and swspec:
316 localdata.setVar('SSTATE_PKGSPEC', '${SSTATE_SWSPEC}')
317 elif pn.endswith('-native') or "-cross-" in pn or "-crosssdk-" in pn:
318 localdata.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/")
319 sstatename = taskname[3:]
320 filespec = '%s_%s.*.siginfo' % (localdata.getVar('SSTATE_PKG', True), sstatename)
321
322 if hashval != '*':
323 sstatedir = "%s/%s" % (d.getVar('SSTATE_DIR', True), hashval[:2])
324 else:
325 sstatedir = d.getVar('SSTATE_DIR', True)
326
327 for root, dirs, files in os.walk(sstatedir):
328 for fn in files:
329 fullpath = os.path.join(root, fn)
330 if fnmatch.fnmatch(fullpath, filespec):
331 if taskhashlist:
332 hashfiles[hashval] = fullpath
333 else:
334 try:
335 filedates[fullpath] = os.stat(fullpath).st_mtime
336 except:
337 continue
338
339 if taskhashlist:
340 return hashfiles
341 else:
342 return filedates
343
344bb.siggen.find_siginfo = find_siginfo
345
346
347def sstate_get_manifest_filename(task, d):
348 """
349 Return the sstate manifest file path for a particular task.
350 Also returns the datastore that can be used to query related variables.
351 """
352 d2 = d.createCopy()
353 extrainf = d.getVarFlag("do_" + task, 'stamp-extra-info', True)
354 if extrainf:
355 d2.setVar("SSTATE_MANMACH", extrainf)
356 return (d2.expand("${SSTATE_MANFILEPREFIX}.%s" % task), d2)