Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 4 | import bb.siggen |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 5 | import oe |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | |
| 7 | def sstate_rundepfilter(siggen, fn, recipename, task, dep, depname, dataCache): |
| 8 | # Return True if we should keep the dependency, False to drop it |
| 9 | def isNative(x): |
| 10 | return x.endswith("-native") |
| 11 | def isCross(x): |
| 12 | return "-cross-" in x |
| 13 | def isNativeSDK(x): |
| 14 | return x.startswith("nativesdk-") |
| 15 | def isKernel(fn): |
| 16 | inherits = " ".join(dataCache.inherits[fn]) |
| 17 | return inherits.find("/module-base.bbclass") != -1 or inherits.find("/linux-kernel-base.bbclass") != -1 |
| 18 | def isPackageGroup(fn): |
| 19 | inherits = " ".join(dataCache.inherits[fn]) |
| 20 | return "/packagegroup.bbclass" in inherits |
| 21 | def isAllArch(fn): |
| 22 | inherits = " ".join(dataCache.inherits[fn]) |
| 23 | return "/allarch.bbclass" in inherits |
| 24 | def isImage(fn): |
| 25 | return "/image.bbclass" in " ".join(dataCache.inherits[fn]) |
| 26 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | # (Almost) always include our own inter-task dependencies. |
| 28 | # The exception is the special do_kernel_configme->do_unpack_and_patch |
| 29 | # dependency from archiver.bbclass. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | if recipename == depname: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | if task == "do_kernel_configme" and dep.endswith(".do_unpack_and_patch"): |
| 32 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | return True |
| 34 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | # Exclude well defined recipe->dependency |
| 36 | if "%s->%s" % (recipename, depname) in siggen.saferecipedeps: |
| 37 | return False |
| 38 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 39 | # Check for special wildcard |
| 40 | if "*->%s" % depname in siggen.saferecipedeps and recipename != depname: |
| 41 | return False |
| 42 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | # Don't change native/cross/nativesdk recipe dependencies any further |
| 44 | if isNative(recipename) or isCross(recipename) or isNativeSDK(recipename): |
| 45 | return True |
| 46 | |
| 47 | # Only target packages beyond here |
| 48 | |
| 49 | # allarch packagegroups are assumed to have well behaved names which don't change between architecures/tunes |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | if isPackageGroup(fn) and isAllArch(fn) and not isNative(depname): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 51 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | |
| 53 | # Exclude well defined machine specific configurations which don't change ABI |
| 54 | if depname in siggen.abisaferecipes and not isImage(fn): |
| 55 | return False |
| 56 | |
| 57 | # Kernel modules are well namespaced. We don't want to depend on the kernel's checksum |
| 58 | # if we're just doing an RRECOMMENDS_xxx = "kernel-module-*", not least because the checksum |
| 59 | # is machine specific. |
| 60 | # Therefore if we're not a kernel or a module recipe (inheriting the kernel classes) |
| 61 | # and we reccomend a kernel-module, we exclude the dependency. |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 62 | depfn = dep.rsplit(":", 1)[0] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | if dataCache and isKernel(depfn) and not isKernel(fn): |
| 64 | for pkg in dataCache.runrecs[fn]: |
| 65 | if " ".join(dataCache.runrecs[fn][pkg]).find("kernel-module-") != -1: |
| 66 | return False |
| 67 | |
| 68 | # Default to keep dependencies |
| 69 | return True |
| 70 | |
| 71 | def sstate_lockedsigs(d): |
| 72 | sigs = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 73 | types = (d.getVar("SIGGEN_LOCKEDSIGS_TYPES") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 74 | for t in types: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 75 | siggen_lockedsigs_var = "SIGGEN_LOCKEDSIGS_%s" % t |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 76 | lockedsigs = (d.getVar(siggen_lockedsigs_var) or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | for ls in lockedsigs: |
| 78 | pn, task, h = ls.split(":", 2) |
| 79 | if pn not in sigs: |
| 80 | sigs[pn] = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 81 | sigs[pn][task] = [h, siggen_lockedsigs_var] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | return sigs |
| 83 | |
| 84 | class SignatureGeneratorOEBasic(bb.siggen.SignatureGeneratorBasic): |
| 85 | name = "OEBasic" |
| 86 | def init_rundepcheck(self, data): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 87 | self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split() |
| 88 | self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | pass |
| 90 | def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None): |
| 91 | return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache) |
| 92 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 93 | class SignatureGeneratorOEBasicHashMixIn(object): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | def init_rundepcheck(self, data): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 95 | self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split() |
| 96 | self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 97 | self.lockedsigs = sstate_lockedsigs(data) |
| 98 | self.lockedhashes = {} |
| 99 | self.lockedpnmap = {} |
| 100 | self.lockedhashfn = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 101 | self.machine = data.getVar("MACHINE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | self.mismatch_msgs = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 103 | self.unlockedrecipes = (data.getVar("SIGGEN_UNLOCKED_RECIPES") or |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 104 | "").split() |
| 105 | self.unlockedrecipes = { k: "" for k in self.unlockedrecipes } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | pass |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 107 | |
| 108 | def tasks_resolved(self, virtmap, virtpnmap, dataCache): |
| 109 | # Translate virtual/xxx entries to PN values |
| 110 | newabisafe = [] |
| 111 | for a in self.abisaferecipes: |
| 112 | if a in virtpnmap: |
| 113 | newabisafe.append(virtpnmap[a]) |
| 114 | else: |
| 115 | newabisafe.append(a) |
| 116 | self.abisaferecipes = newabisafe |
| 117 | newsafedeps = [] |
| 118 | for a in self.saferecipedeps: |
| 119 | a1, a2 = a.split("->") |
| 120 | if a1 in virtpnmap: |
| 121 | a1 = virtpnmap[a1] |
| 122 | if a2 in virtpnmap: |
| 123 | a2 = virtpnmap[a2] |
| 124 | newsafedeps.append(a1 + "->" + a2) |
| 125 | self.saferecipedeps = newsafedeps |
| 126 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | def rundep_check(self, fn, recipename, task, dep, depname, dataCache = None): |
| 128 | return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCache) |
| 129 | |
| 130 | def get_taskdata(self): |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 131 | return (self.lockedpnmap, self.lockedhashfn, self.lockedhashes) + super().get_taskdata() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 132 | |
| 133 | def set_taskdata(self, data): |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 134 | self.lockedpnmap, self.lockedhashfn, self.lockedhashes = data[:3] |
| 135 | super().set_taskdata(data[3:]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 136 | |
| 137 | def dump_sigs(self, dataCache, options): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 138 | sigfile = os.getcwd() + "/locked-sigs.inc" |
| 139 | bb.plain("Writing locked sigs to %s" % sigfile) |
| 140 | self.dump_lockedsigs(sigfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | return super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigs(dataCache, options) |
| 142 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 143 | def get_taskhash(self, tid, deps, dataCache): |
| 144 | h = super(bb.siggen.SignatureGeneratorBasicHash, self).get_taskhash(tid, deps, dataCache) |
| 145 | |
| 146 | (mc, _, task, fn) = bb.runqueue.split_tid_mcfn(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 147 | |
| 148 | recipename = dataCache.pkg_fn[fn] |
| 149 | self.lockedpnmap[fn] = recipename |
| 150 | self.lockedhashfn[fn] = dataCache.hashfn[fn] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 151 | |
| 152 | unlocked = False |
| 153 | if recipename in self.unlockedrecipes: |
| 154 | unlocked = True |
| 155 | else: |
| 156 | def recipename_from_dep(dep): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 157 | fn = bb.runqueue.fn_from_tid(dep) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 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. |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 162 | depnames = [ recipename_from_dep(x) for x in deps if mc == bb.runqueue.mc_from_tid(x)] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | if task in self.lockedsigs[recipename]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 169 | h_locked = self.lockedsigs[recipename][task][0] |
| 170 | var = self.lockedsigs[recipename][task][1] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 171 | self.lockedhashes[tid] = h_locked |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 172 | unihash = super().get_unihash(tid) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 173 | self.taskhash[tid] = h_locked |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | #bb.warn("Using %s %s %s" % (recipename, task, h)) |
| 175 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 176 | if h != h_locked and h_locked != unihash: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 177 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 179 | |
| 180 | return h_locked |
| 181 | #bb.warn("%s %s %s" % (recipename, task, h)) |
| 182 | return h |
| 183 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 184 | def get_unihash(self, tid): |
| 185 | if tid in self.lockedhashes: |
| 186 | return self.lockedhashes[tid] |
| 187 | return super().get_unihash(tid) |
| 188 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | def dump_sigtask(self, fn, task, stampbase, runtime): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 190 | tid = fn + ":" + task |
| 191 | if tid in self.lockedhashes: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 192 | return |
| 193 | super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigtask(fn, task, stampbase, runtime) |
| 194 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 195 | def dump_lockedsigs(self, sigfile, taskfilter=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | types = {} |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 197 | for tid in self.runtaskdeps: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 198 | if taskfilter: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 199 | if not tid in taskfilter: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | continue |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 201 | fn = bb.runqueue.fn_from_tid(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 202 | t = self.lockedhashfn[fn].split(" ")[1].split(":")[5] |
| 203 | t = 't-' + t.replace('_', '-') |
| 204 | if t not in types: |
| 205 | types[t] = [] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 206 | types[t].append(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 207 | |
| 208 | with open(sigfile, "w") as f: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 209 | l = sorted(types) |
| 210 | for t in l: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 211 | f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t) |
| 212 | types[t].sort() |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 213 | sortedtid = sorted(types[t], key=lambda tid: self.lockedpnmap[bb.runqueue.fn_from_tid(tid)]) |
| 214 | for tid in sortedtid: |
| 215 | (_, _, task, fn) = bb.runqueue.split_tid_mcfn(tid) |
| 216 | if tid not in self.taskhash: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 217 | continue |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 218 | f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.get_unihash(tid) + " \\\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 219 | f.write(' "\n') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 220 | f.write('SIGGEN_LOCKEDSIGS_TYPES_%s = "%s"' % (self.machine, " ".join(l))) |
| 221 | |
| 222 | def dump_siglist(self, sigfile): |
| 223 | with open(sigfile, "w") as f: |
| 224 | tasks = [] |
| 225 | for taskitem in self.taskhash: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 226 | (fn, task) = taskitem.rsplit(":", 1) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 227 | pn = self.lockedpnmap[fn] |
| 228 | tasks.append((pn, task, fn, self.taskhash[taskitem])) |
| 229 | for (pn, task, fn, taskhash) in sorted(tasks): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 230 | f.write('%s:%s %s %s\n' % (pn, task, fn, taskhash)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 231 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 232 | def checkhashes(self, sq_data, missed, found, d): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 233 | warn_msgs = [] |
| 234 | error_msgs = [] |
| 235 | sstate_missing_msgs = [] |
| 236 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 237 | for tid in sq_data['hash']: |
| 238 | if tid not in found: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | for pn in self.lockedsigs: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 240 | taskname = bb.runqueue.taskname_from_tid(tid) |
| 241 | if sq_data['hash'][tid] in iter(self.lockedsigs[pn].values()): |
| 242 | if taskname == 'do_shared_workdir': |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 243 | continue |
| 244 | sstate_missing_msgs.append("Locked sig is set for %s:%s (%s) yet not in sstate cache?" |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 245 | % (pn, taskname, sq_data['hash'][tid])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 247 | checklevel = d.getVar("SIGGEN_LOCKEDSIGS_TASKSIG_CHECK") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 248 | if checklevel == 'warn': |
| 249 | warn_msgs += self.mismatch_msgs |
| 250 | elif checklevel == 'error': |
| 251 | error_msgs += self.mismatch_msgs |
| 252 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 253 | checklevel = d.getVar("SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 254 | if checklevel == 'warn': |
| 255 | warn_msgs += sstate_missing_msgs |
| 256 | elif checklevel == 'error': |
| 257 | error_msgs += sstate_missing_msgs |
| 258 | |
| 259 | if warn_msgs: |
| 260 | bb.warn("\n".join(warn_msgs)) |
| 261 | if error_msgs: |
| 262 | bb.fatal("\n".join(error_msgs)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 263 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 264 | class SignatureGeneratorOEBasicHash(SignatureGeneratorOEBasicHashMixIn, bb.siggen.SignatureGeneratorBasicHash): |
| 265 | name = "OEBasicHash" |
| 266 | |
| 267 | class SignatureGeneratorOEEquivHash(SignatureGeneratorOEBasicHashMixIn, bb.siggen.SignatureGeneratorUniHashMixIn, bb.siggen.SignatureGeneratorBasicHash): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 268 | name = "OEEquivHash" |
| 269 | |
| 270 | def init_rundepcheck(self, data): |
| 271 | super().init_rundepcheck(data) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 272 | self.server = data.getVar('BB_HASHSERVE') |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 273 | if not self.server: |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 274 | bb.fatal("OEEquivHash requires BB_HASHSERVE to be set") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 275 | self.method = data.getVar('SSTATE_HASHEQUIV_METHOD') |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 276 | if not self.method: |
| 277 | bb.fatal("OEEquivHash requires SSTATE_HASHEQUIV_METHOD to be set") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | |
| 279 | # Insert these classes into siggen's namespace so it can see and select them |
| 280 | bb.siggen.SignatureGeneratorOEBasic = SignatureGeneratorOEBasic |
| 281 | bb.siggen.SignatureGeneratorOEBasicHash = SignatureGeneratorOEBasicHash |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 282 | bb.siggen.SignatureGeneratorOEEquivHash = SignatureGeneratorOEEquivHash |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 283 | |
| 284 | |
| 285 | def find_siginfo(pn, taskname, taskhashlist, d): |
| 286 | """ Find signature data files for comparison purposes """ |
| 287 | |
| 288 | import fnmatch |
| 289 | import glob |
| 290 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 291 | if not taskname: |
| 292 | # We have to derive pn and taskname |
| 293 | key = pn |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 294 | splitit = key.split('.bb:') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | taskname = splitit[1] |
| 296 | pn = os.path.basename(splitit[0]).split('_')[0] |
| 297 | if key.startswith('virtual:native:'): |
| 298 | pn = pn + '-native' |
| 299 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 300 | hashfiles = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 301 | filedates = {} |
| 302 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 303 | def get_hashval(siginfo): |
| 304 | if siginfo.endswith('.siginfo'): |
| 305 | return siginfo.rpartition(':')[2].partition('_')[0] |
| 306 | else: |
| 307 | return siginfo.rpartition('.')[2] |
| 308 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 309 | # First search in stamps dir |
| 310 | localdata = d.createCopy() |
| 311 | localdata.setVar('MULTIMACH_TARGET_SYS', '*') |
| 312 | localdata.setVar('PN', pn) |
| 313 | localdata.setVar('PV', '*') |
| 314 | localdata.setVar('PR', '*') |
| 315 | localdata.setVar('EXTENDPE', '') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 316 | stamp = localdata.getVar('STAMP') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 317 | if pn.startswith("gcc-source"): |
| 318 | # gcc-source shared workdir is a special case :( |
| 319 | stamp = localdata.expand("${STAMPS_DIR}/work-shared/gcc-${PV}-${PR}") |
| 320 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 321 | filespec = '%s.%s.sigdata.*' % (stamp, taskname) |
| 322 | foundall = False |
| 323 | import glob |
| 324 | for fullpath in glob.glob(filespec): |
| 325 | match = False |
| 326 | if taskhashlist: |
| 327 | for taskhash in taskhashlist: |
| 328 | if fullpath.endswith('.%s' % taskhash): |
| 329 | hashfiles[taskhash] = fullpath |
| 330 | if len(hashfiles) == len(taskhashlist): |
| 331 | foundall = True |
| 332 | break |
| 333 | else: |
| 334 | try: |
| 335 | filedates[fullpath] = os.stat(fullpath).st_mtime |
| 336 | except OSError: |
| 337 | continue |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 338 | hashval = get_hashval(fullpath) |
| 339 | hashfiles[hashval] = fullpath |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 340 | |
| 341 | if not taskhashlist or (len(filedates) < 2 and not foundall): |
| 342 | # That didn't work, look in sstate-cache |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 343 | hashes = taskhashlist or ['?' * 64] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 344 | localdata = bb.data.createCopy(d) |
| 345 | for hashval in hashes: |
| 346 | localdata.setVar('PACKAGE_ARCH', '*') |
| 347 | localdata.setVar('TARGET_VENDOR', '*') |
| 348 | localdata.setVar('TARGET_OS', '*') |
| 349 | localdata.setVar('PN', pn) |
| 350 | localdata.setVar('PV', '*') |
| 351 | localdata.setVar('PR', '*') |
| 352 | localdata.setVar('BB_TASKHASH', hashval) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 353 | swspec = localdata.getVar('SSTATE_SWSPEC') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 354 | if taskname in ['do_fetch', 'do_unpack', 'do_patch', 'do_populate_lic', 'do_preconfigure'] and swspec: |
| 355 | localdata.setVar('SSTATE_PKGSPEC', '${SSTATE_SWSPEC}') |
| 356 | elif pn.endswith('-native') or "-cross-" in pn or "-crosssdk-" in pn: |
| 357 | localdata.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/") |
| 358 | sstatename = taskname[3:] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 359 | filespec = '%s_%s.*.siginfo' % (localdata.getVar('SSTATE_PKG'), sstatename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 360 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 361 | matchedfiles = glob.glob(filespec) |
| 362 | for fullpath in matchedfiles: |
| 363 | actual_hashval = get_hashval(fullpath) |
| 364 | if actual_hashval in hashfiles: |
| 365 | continue |
| 366 | hashfiles[hashval] = fullpath |
| 367 | if not taskhashlist: |
| 368 | try: |
| 369 | filedates[fullpath] = os.stat(fullpath).st_mtime |
| 370 | except: |
| 371 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | |
| 373 | if taskhashlist: |
| 374 | return hashfiles |
| 375 | else: |
| 376 | return filedates |
| 377 | |
| 378 | bb.siggen.find_siginfo = find_siginfo |
| 379 | |
| 380 | |
| 381 | def sstate_get_manifest_filename(task, d): |
| 382 | """ |
| 383 | Return the sstate manifest file path for a particular task. |
| 384 | Also returns the datastore that can be used to query related variables. |
| 385 | """ |
| 386 | d2 = d.createCopy() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 387 | extrainf = d.getVarFlag("do_" + task, 'stamp-extra-info') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 388 | if extrainf: |
| 389 | d2.setVar("SSTATE_MANMACH", extrainf) |
| 390 | return (d2.expand("${SSTATE_MANFILEPREFIX}.%s" % task), d2) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 391 | |
| 392 | def find_sstate_manifest(taskdata, taskdata2, taskname, d, multilibcache): |
| 393 | d2 = d |
| 394 | variant = '' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 395 | curr_variant = '' |
| 396 | if d.getVar("BBEXTENDCURR") == "multilib": |
| 397 | curr_variant = d.getVar("BBEXTENDVARIANT") |
| 398 | if "virtclass-multilib" not in d.getVar("OVERRIDES"): |
| 399 | curr_variant = "invalid" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 400 | if taskdata2.startswith("virtual:multilib"): |
| 401 | variant = taskdata2.split(":")[2] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 402 | if curr_variant != variant: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 403 | if variant not in multilibcache: |
| 404 | multilibcache[variant] = oe.utils.get_multilib_datastore(variant, d) |
| 405 | d2 = multilibcache[variant] |
| 406 | |
| 407 | if taskdata.endswith("-native"): |
| 408 | pkgarchs = ["${BUILD_ARCH}"] |
| 409 | elif taskdata.startswith("nativesdk-"): |
| 410 | pkgarchs = ["${SDK_ARCH}_${SDK_OS}", "allarch"] |
| 411 | elif "-cross-canadian" in taskdata: |
| 412 | pkgarchs = ["${SDK_ARCH}_${SDK_ARCH}-${SDKPKGSUFFIX}"] |
| 413 | elif "-cross-" in taskdata: |
| 414 | pkgarchs = ["${BUILD_ARCH}_${TARGET_ARCH}"] |
| 415 | elif "-crosssdk" in taskdata: |
| 416 | pkgarchs = ["${BUILD_ARCH}_${SDK_ARCH}_${SDK_OS}"] |
| 417 | else: |
| 418 | pkgarchs = ['${MACHINE_ARCH}'] |
| 419 | pkgarchs = pkgarchs + list(reversed(d2.getVar("PACKAGE_EXTRA_ARCHS").split())) |
| 420 | pkgarchs.append('allarch') |
| 421 | pkgarchs.append('${SDK_ARCH}_${SDK_ARCH}-${SDKPKGSUFFIX}') |
| 422 | |
| 423 | for pkgarch in pkgarchs: |
| 424 | manifest = d2.expand("${SSTATE_MANIFESTS}/manifest-%s-%s.%s" % (pkgarch, taskdata, taskname)) |
| 425 | if os.path.exists(manifest): |
| 426 | return manifest, d2 |
| 427 | bb.warn("Manifest %s not found in %s (variant '%s')?" % (manifest, d2.expand(" ".join(pkgarchs)), variant)) |
| 428 | return None, d2 |
| 429 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 430 | def OEOuthashBasic(path, sigfile, task, d): |
| 431 | """ |
| 432 | Basic output hash function |
| 433 | |
| 434 | Calculates the output hash of a task by hashing all output file metadata, |
| 435 | and file contents. |
| 436 | """ |
| 437 | import hashlib |
| 438 | import stat |
| 439 | import pwd |
| 440 | import grp |
| 441 | |
| 442 | def update_hash(s): |
| 443 | s = s.encode('utf-8') |
| 444 | h.update(s) |
| 445 | if sigfile: |
| 446 | sigfile.write(s) |
| 447 | |
| 448 | h = hashlib.sha256() |
| 449 | prev_dir = os.getcwd() |
| 450 | include_owners = os.environ.get('PSEUDO_DISABLED') == '0' |
| 451 | |
| 452 | try: |
| 453 | os.chdir(path) |
| 454 | |
| 455 | update_hash("OEOuthashBasic\n") |
| 456 | |
| 457 | # It is only currently useful to get equivalent hashes for things that |
| 458 | # can be restored from sstate. Since the sstate object is named using |
| 459 | # SSTATE_PKGSPEC and the task name, those should be included in the |
| 460 | # output hash calculation. |
| 461 | update_hash("SSTATE_PKGSPEC=%s\n" % d.getVar('SSTATE_PKGSPEC')) |
| 462 | update_hash("task=%s\n" % task) |
| 463 | |
| 464 | for root, dirs, files in os.walk('.', topdown=True): |
| 465 | # Sort directories to ensure consistent ordering when recursing |
| 466 | dirs.sort() |
| 467 | files.sort() |
| 468 | |
| 469 | def process(path): |
| 470 | s = os.lstat(path) |
| 471 | |
| 472 | if stat.S_ISDIR(s.st_mode): |
| 473 | update_hash('d') |
| 474 | elif stat.S_ISCHR(s.st_mode): |
| 475 | update_hash('c') |
| 476 | elif stat.S_ISBLK(s.st_mode): |
| 477 | update_hash('b') |
| 478 | elif stat.S_ISSOCK(s.st_mode): |
| 479 | update_hash('s') |
| 480 | elif stat.S_ISLNK(s.st_mode): |
| 481 | update_hash('l') |
| 482 | elif stat.S_ISFIFO(s.st_mode): |
| 483 | update_hash('p') |
| 484 | else: |
| 485 | update_hash('-') |
| 486 | |
| 487 | def add_perm(mask, on, off='-'): |
| 488 | if mask & s.st_mode: |
| 489 | update_hash(on) |
| 490 | else: |
| 491 | update_hash(off) |
| 492 | |
| 493 | add_perm(stat.S_IRUSR, 'r') |
| 494 | add_perm(stat.S_IWUSR, 'w') |
| 495 | if stat.S_ISUID & s.st_mode: |
| 496 | add_perm(stat.S_IXUSR, 's', 'S') |
| 497 | else: |
| 498 | add_perm(stat.S_IXUSR, 'x') |
| 499 | |
| 500 | add_perm(stat.S_IRGRP, 'r') |
| 501 | add_perm(stat.S_IWGRP, 'w') |
| 502 | if stat.S_ISGID & s.st_mode: |
| 503 | add_perm(stat.S_IXGRP, 's', 'S') |
| 504 | else: |
| 505 | add_perm(stat.S_IXGRP, 'x') |
| 506 | |
| 507 | add_perm(stat.S_IROTH, 'r') |
| 508 | add_perm(stat.S_IWOTH, 'w') |
| 509 | if stat.S_ISVTX & s.st_mode: |
| 510 | update_hash('t') |
| 511 | else: |
| 512 | add_perm(stat.S_IXOTH, 'x') |
| 513 | |
| 514 | if include_owners: |
| 515 | update_hash(" %10s" % pwd.getpwuid(s.st_uid).pw_name) |
| 516 | update_hash(" %10s" % grp.getgrgid(s.st_gid).gr_name) |
| 517 | |
| 518 | update_hash(" ") |
| 519 | if stat.S_ISBLK(s.st_mode) or stat.S_ISCHR(s.st_mode): |
| 520 | update_hash("%9s" % ("%d.%d" % (os.major(s.st_rdev), os.minor(s.st_rdev)))) |
| 521 | else: |
| 522 | update_hash(" " * 9) |
| 523 | |
| 524 | update_hash(" ") |
| 525 | if stat.S_ISREG(s.st_mode): |
| 526 | update_hash("%10d" % s.st_size) |
| 527 | else: |
| 528 | update_hash(" " * 10) |
| 529 | |
| 530 | update_hash(" ") |
| 531 | fh = hashlib.sha256() |
| 532 | if stat.S_ISREG(s.st_mode): |
| 533 | # Hash file contents |
| 534 | with open(path, 'rb') as d: |
| 535 | for chunk in iter(lambda: d.read(4096), b""): |
| 536 | fh.update(chunk) |
| 537 | update_hash(fh.hexdigest()) |
| 538 | else: |
| 539 | update_hash(" " * len(fh.hexdigest())) |
| 540 | |
| 541 | update_hash(" %s" % path) |
| 542 | |
| 543 | if stat.S_ISLNK(s.st_mode): |
| 544 | update_hash(" -> %s" % os.readlink(path)) |
| 545 | |
| 546 | update_hash("\n") |
| 547 | |
| 548 | # Process this directory and all its child files |
| 549 | process(root) |
| 550 | for f in files: |
| 551 | if f == 'fixmepath': |
| 552 | continue |
| 553 | process(os.path.join(root, f)) |
| 554 | finally: |
| 555 | os.chdir(prev_dir) |
| 556 | |
| 557 | return h.hexdigest() |
| 558 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 559 | |