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