Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | import bb.siggen |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 7 | import bb.runqueue |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 8 | import oe |
Patrick Williams | 03514f1 | 2024-04-05 07:04:11 -0500 | [diff] [blame] | 9 | import netrc |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 11 | def sstate_rundepfilter(siggen, fn, recipename, task, dep, depname, dataCaches): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | # Return True if we should keep the dependency, False to drop it |
| 13 | def isNative(x): |
| 14 | return x.endswith("-native") |
| 15 | def isCross(x): |
| 16 | return "-cross-" in x |
| 17 | def isNativeSDK(x): |
| 18 | return x.startswith("nativesdk-") |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 19 | def isKernel(mc, fn): |
| 20 | inherits = " ".join(dataCaches[mc].inherits[fn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | return inherits.find("/module-base.bbclass") != -1 or inherits.find("/linux-kernel-base.bbclass") != -1 |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 22 | def isPackageGroup(mc, fn): |
| 23 | inherits = " ".join(dataCaches[mc].inherits[fn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | return "/packagegroup.bbclass" in inherits |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 25 | def isAllArch(mc, fn): |
| 26 | inherits = " ".join(dataCaches[mc].inherits[fn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 27 | return "/allarch.bbclass" in inherits |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 28 | def isImage(mc, fn): |
| 29 | return "/image.bbclass" in " ".join(dataCaches[mc].inherits[fn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 31 | depmc, _, deptaskname, depmcfn = bb.runqueue.split_tid_mcfn(dep) |
| 32 | mc, _ = bb.runqueue.split_mc(fn) |
| 33 | |
Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 34 | # We can skip the rm_work task signature to avoid running the task |
| 35 | # when we remove some tasks from the dependencie chain |
| 36 | # i.e INHERIT:remove = "create-spdx" will trigger the do_rm_work |
| 37 | if task == "do_rm_work": |
| 38 | return False |
| 39 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 40 | # (Almost) always include our own inter-task dependencies (unless it comes |
| 41 | # from a mcdepends). The exception is the special |
| 42 | # do_kernel_configme->do_unpack_and_patch dependency from archiver.bbclass. |
| 43 | if recipename == depname and depmc == mc: |
| 44 | if task == "do_kernel_configme" and deptaskname == "do_unpack_and_patch": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 45 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | return True |
| 47 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | # Exclude well defined recipe->dependency |
| 49 | if "%s->%s" % (recipename, depname) in siggen.saferecipedeps: |
| 50 | return False |
| 51 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 52 | # Check for special wildcard |
| 53 | if "*->%s" % depname in siggen.saferecipedeps and recipename != depname: |
| 54 | return False |
| 55 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | # Don't change native/cross/nativesdk recipe dependencies any further |
| 57 | if isNative(recipename) or isCross(recipename) or isNativeSDK(recipename): |
| 58 | return True |
| 59 | |
| 60 | # Only target packages beyond here |
| 61 | |
| 62 | # allarch packagegroups are assumed to have well behaved names which don't change between architecures/tunes |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 63 | if isPackageGroup(mc, fn) and isAllArch(mc, fn) and not isNative(depname): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 64 | return False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | |
| 66 | # Exclude well defined machine specific configurations which don't change ABI |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 67 | if depname in siggen.abisaferecipes and not isImage(mc, fn): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 68 | return False |
| 69 | |
| 70 | # Kernel modules are well namespaced. We don't want to depend on the kernel's checksum |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 71 | # if we're just doing an RRECOMMENDS:xxx = "kernel-module-*", not least because the checksum |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | # is machine specific. |
| 73 | # Therefore if we're not a kernel or a module recipe (inheriting the kernel classes) |
| 74 | # and we reccomend a kernel-module, we exclude the dependency. |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 75 | if dataCaches and isKernel(depmc, depmcfn) and not isKernel(mc, fn): |
| 76 | for pkg in dataCaches[mc].runrecs[fn]: |
| 77 | if " ".join(dataCaches[mc].runrecs[fn][pkg]).find("kernel-module-") != -1: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | return False |
| 79 | |
| 80 | # Default to keep dependencies |
| 81 | return True |
| 82 | |
| 83 | def sstate_lockedsigs(d): |
| 84 | sigs = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 85 | types = (d.getVar("SIGGEN_LOCKEDSIGS_TYPES") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 86 | for t in types: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 87 | siggen_lockedsigs_var = "SIGGEN_LOCKEDSIGS_%s" % t |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | lockedsigs = (d.getVar(siggen_lockedsigs_var) or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | for ls in lockedsigs: |
| 90 | pn, task, h = ls.split(":", 2) |
| 91 | if pn not in sigs: |
| 92 | sigs[pn] = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 93 | sigs[pn][task] = [h, siggen_lockedsigs_var] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | return sigs |
| 95 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 96 | class SignatureGeneratorOEBasicHashMixIn(object): |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 97 | supports_multiconfig_datacaches = True |
| 98 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | def init_rundepcheck(self, data): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 100 | self.abisaferecipes = (data.getVar("SIGGEN_EXCLUDERECIPES_ABISAFE") or "").split() |
| 101 | self.saferecipedeps = (data.getVar("SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS") or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | self.lockedsigs = sstate_lockedsigs(data) |
| 103 | self.lockedhashes = {} |
| 104 | self.lockedpnmap = {} |
| 105 | self.lockedhashfn = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 106 | self.machine = data.getVar("MACHINE") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | self.mismatch_msgs = [] |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 108 | self.mismatch_number = 0 |
| 109 | self.lockedsigs_msgs = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 110 | self.unlockedrecipes = (data.getVar("SIGGEN_UNLOCKED_RECIPES") or |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 111 | "").split() |
| 112 | self.unlockedrecipes = { k: "" for k in self.unlockedrecipes } |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 113 | self._internal = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | pass |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 115 | |
| 116 | def tasks_resolved(self, virtmap, virtpnmap, dataCache): |
| 117 | # Translate virtual/xxx entries to PN values |
| 118 | newabisafe = [] |
| 119 | for a in self.abisaferecipes: |
| 120 | if a in virtpnmap: |
| 121 | newabisafe.append(virtpnmap[a]) |
| 122 | else: |
| 123 | newabisafe.append(a) |
| 124 | self.abisaferecipes = newabisafe |
| 125 | newsafedeps = [] |
| 126 | for a in self.saferecipedeps: |
| 127 | a1, a2 = a.split("->") |
| 128 | if a1 in virtpnmap: |
| 129 | a1 = virtpnmap[a1] |
| 130 | if a2 in virtpnmap: |
| 131 | a2 = virtpnmap[a2] |
| 132 | newsafedeps.append(a1 + "->" + a2) |
| 133 | self.saferecipedeps = newsafedeps |
| 134 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 135 | def rundep_check(self, fn, recipename, task, dep, depname, dataCaches = None): |
| 136 | return sstate_rundepfilter(self, fn, recipename, task, dep, depname, dataCaches) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 137 | |
| 138 | def get_taskdata(self): |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 139 | return (self.lockedpnmap, self.lockedhashfn, self.lockedhashes) + super().get_taskdata() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | |
| 141 | def set_taskdata(self, data): |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 142 | self.lockedpnmap, self.lockedhashfn, self.lockedhashes = data[:3] |
| 143 | super().set_taskdata(data[3:]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | |
| 145 | def dump_sigs(self, dataCache, options): |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 146 | if 'lockedsigs' in options: |
| 147 | sigfile = os.getcwd() + "/locked-sigs.inc" |
| 148 | bb.plain("Writing locked sigs to %s" % sigfile) |
| 149 | self.dump_lockedsigs(sigfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | return super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigs(dataCache, options) |
| 151 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 152 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 153 | def get_taskhash(self, tid, deps, dataCaches): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 154 | if tid in self.lockedhashes: |
| 155 | if self.lockedhashes[tid]: |
| 156 | return self.lockedhashes[tid] |
| 157 | else: |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 158 | return super().get_taskhash(tid, deps, dataCaches) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 159 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 160 | h = super().get_taskhash(tid, deps, dataCaches) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 161 | |
| 162 | (mc, _, task, fn) = bb.runqueue.split_tid_mcfn(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 163 | |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 164 | recipename = dataCaches[mc].pkg_fn[fn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | self.lockedpnmap[fn] = recipename |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 166 | self.lockedhashfn[fn] = dataCaches[mc].hashfn[fn] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 167 | |
| 168 | unlocked = False |
| 169 | if recipename in self.unlockedrecipes: |
| 170 | unlocked = True |
| 171 | else: |
| 172 | def recipename_from_dep(dep): |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 173 | (depmc, _, _, depfn) = bb.runqueue.split_tid_mcfn(dep) |
| 174 | return dataCaches[depmc].pkg_fn[depfn] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 175 | |
| 176 | # If any unlocked recipe is in the direct dependencies then the |
| 177 | # current recipe should be unlocked as well. |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 178 | 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] | 179 | if any(x in y for y in depnames for x in self.unlockedrecipes): |
| 180 | self.unlockedrecipes[recipename] = '' |
| 181 | unlocked = True |
| 182 | |
| 183 | if not unlocked and recipename in self.lockedsigs: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | if task in self.lockedsigs[recipename]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 185 | h_locked = self.lockedsigs[recipename][task][0] |
| 186 | var = self.lockedsigs[recipename][task][1] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 187 | self.lockedhashes[tid] = h_locked |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 188 | self._internal = True |
| 189 | unihash = self.get_unihash(tid) |
| 190 | self._internal = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | #bb.warn("Using %s %s %s" % (recipename, task, h)) |
| 192 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 193 | if h != h_locked and h_locked != unihash: |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 194 | self.mismatch_number += 1 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 195 | self.mismatch_msgs.append('The %s:%s sig is computed to be %s, but the sig is locked to %s in %s' |
| 196 | % (recipename, task, h, h_locked, var)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 197 | |
| 198 | return h_locked |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 199 | |
| 200 | self.lockedhashes[tid] = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 201 | #bb.warn("%s %s %s" % (recipename, task, h)) |
| 202 | return h |
| 203 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 204 | def get_stampfile_hash(self, tid): |
| 205 | if tid in self.lockedhashes and self.lockedhashes[tid]: |
| 206 | return self.lockedhashes[tid] |
| 207 | return super().get_stampfile_hash(tid) |
| 208 | |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 209 | def get_cached_unihash(self, tid): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 210 | if tid in self.lockedhashes and self.lockedhashes[tid] and not self._internal: |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 211 | return self.lockedhashes[tid] |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 212 | return super().get_cached_unihash(tid) |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 213 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | def dump_sigtask(self, fn, task, stampbase, runtime): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 215 | tid = fn + ":" + task |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 216 | if tid in self.lockedhashes and self.lockedhashes[tid]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 217 | return |
| 218 | super(bb.siggen.SignatureGeneratorBasicHash, self).dump_sigtask(fn, task, stampbase, runtime) |
| 219 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 220 | def dump_lockedsigs(self, sigfile, taskfilter=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 221 | types = {} |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 222 | for tid in self.runtaskdeps: |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 223 | # Bitbake changed this to a tuple in newer versions |
| 224 | if isinstance(tid, tuple): |
| 225 | tid = tid[1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 226 | if taskfilter: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 227 | if not tid in taskfilter: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | continue |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 229 | fn = bb.runqueue.fn_from_tid(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | t = self.lockedhashfn[fn].split(" ")[1].split(":")[5] |
| 231 | t = 't-' + t.replace('_', '-') |
| 232 | if t not in types: |
| 233 | types[t] = [] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 234 | types[t].append(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 235 | |
| 236 | with open(sigfile, "w") as f: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 237 | l = sorted(types) |
| 238 | for t in l: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | f.write('SIGGEN_LOCKEDSIGS_%s = "\\\n' % t) |
| 240 | types[t].sort() |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 241 | sortedtid = sorted(types[t], key=lambda tid: self.lockedpnmap[bb.runqueue.fn_from_tid(tid)]) |
| 242 | for tid in sortedtid: |
| 243 | (_, _, task, fn) = bb.runqueue.split_tid_mcfn(tid) |
| 244 | if tid not in self.taskhash: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 245 | continue |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 246 | f.write(" " + self.lockedpnmap[fn] + ":" + task + ":" + self.get_unihash(tid) + " \\\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 247 | f.write(' "\n') |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 248 | f.write('SIGGEN_LOCKEDSIGS_TYPES:%s = "%s"' % (self.machine, " ".join(l))) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 249 | |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 250 | def dump_siglist(self, sigfile, path_prefix_strip=None): |
| 251 | def strip_fn(fn): |
| 252 | nonlocal path_prefix_strip |
| 253 | if not path_prefix_strip: |
| 254 | return fn |
| 255 | |
| 256 | fn_exp = fn.split(":") |
| 257 | if fn_exp[-1].startswith(path_prefix_strip): |
| 258 | fn_exp[-1] = fn_exp[-1][len(path_prefix_strip):] |
| 259 | |
| 260 | return ":".join(fn_exp) |
| 261 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 262 | with open(sigfile, "w") as f: |
| 263 | tasks = [] |
| 264 | for taskitem in self.taskhash: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 265 | (fn, task) = taskitem.rsplit(":", 1) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 266 | pn = self.lockedpnmap[fn] |
Andrew Geissler | 0903674 | 2021-06-25 14:25:14 -0500 | [diff] [blame] | 267 | tasks.append((pn, task, strip_fn(fn), self.taskhash[taskitem])) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 268 | for (pn, task, fn, taskhash) in sorted(tasks): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 269 | f.write('%s:%s %s %s\n' % (pn, task, fn, taskhash)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 271 | def checkhashes(self, sq_data, missed, found, d): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 272 | warn_msgs = [] |
| 273 | error_msgs = [] |
| 274 | sstate_missing_msgs = [] |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 275 | info_msgs = None |
| 276 | |
| 277 | if self.lockedsigs: |
| 278 | if len(self.lockedsigs) > 10: |
| 279 | self.lockedsigs_msgs = "There are %s recipes with locked tasks (%s task(s) have non matching signature)" % (len(self.lockedsigs), self.mismatch_number) |
| 280 | else: |
| 281 | self.lockedsigs_msgs = "The following recipes have locked tasks:" |
| 282 | for pn in self.lockedsigs: |
| 283 | self.lockedsigs_msgs += " %s" % (pn) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 284 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 285 | for tid in sq_data['hash']: |
| 286 | if tid not in found: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | for pn in self.lockedsigs: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 288 | taskname = bb.runqueue.taskname_from_tid(tid) |
| 289 | if sq_data['hash'][tid] in iter(self.lockedsigs[pn].values()): |
| 290 | if taskname == 'do_shared_workdir': |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 291 | continue |
| 292 | 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] | 293 | % (pn, taskname, sq_data['hash'][tid])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 295 | checklevel = d.getVar("SIGGEN_LOCKEDSIGS_TASKSIG_CHECK") |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 296 | if checklevel == 'info': |
| 297 | info_msgs = self.lockedsigs_msgs |
| 298 | if checklevel == 'warn' or checklevel == 'info': |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 299 | warn_msgs += self.mismatch_msgs |
| 300 | elif checklevel == 'error': |
| 301 | error_msgs += self.mismatch_msgs |
| 302 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 303 | checklevel = d.getVar("SIGGEN_LOCKEDSIGS_SSTATE_EXISTS_CHECK") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 304 | if checklevel == 'warn': |
| 305 | warn_msgs += sstate_missing_msgs |
| 306 | elif checklevel == 'error': |
| 307 | error_msgs += sstate_missing_msgs |
| 308 | |
Andrew Geissler | 2013739 | 2023-10-12 04:59:14 -0600 | [diff] [blame] | 309 | if info_msgs: |
| 310 | bb.note(info_msgs) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 311 | if warn_msgs: |
| 312 | bb.warn("\n".join(warn_msgs)) |
| 313 | if error_msgs: |
| 314 | bb.fatal("\n".join(error_msgs)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 315 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 316 | class SignatureGeneratorOEBasicHash(SignatureGeneratorOEBasicHashMixIn, bb.siggen.SignatureGeneratorBasicHash): |
| 317 | name = "OEBasicHash" |
| 318 | |
| 319 | class SignatureGeneratorOEEquivHash(SignatureGeneratorOEBasicHashMixIn, bb.siggen.SignatureGeneratorUniHashMixIn, bb.siggen.SignatureGeneratorBasicHash): |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 320 | name = "OEEquivHash" |
| 321 | |
| 322 | def init_rundepcheck(self, data): |
| 323 | super().init_rundepcheck(data) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 324 | self.server = data.getVar('BB_HASHSERVE') |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 325 | if not self.server: |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 326 | bb.fatal("OEEquivHash requires BB_HASHSERVE to be set") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 327 | self.method = data.getVar('SSTATE_HASHEQUIV_METHOD') |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 328 | if not self.method: |
| 329 | bb.fatal("OEEquivHash requires SSTATE_HASHEQUIV_METHOD to be set") |
Patrick Williams | 73bd93f | 2024-02-20 08:07:48 -0600 | [diff] [blame] | 330 | self.max_parallel = int(data.getVar('BB_HASHSERVE_MAX_PARALLEL') or 1) |
Patrick Williams | 03514f1 | 2024-04-05 07:04:11 -0500 | [diff] [blame] | 331 | self.username = data.getVar("BB_HASHSERVE_USERNAME") |
| 332 | self.password = data.getVar("BB_HASHSERVE_PASSWORD") |
| 333 | if not self.username or not self.password: |
| 334 | try: |
| 335 | n = netrc.netrc() |
| 336 | auth = n.authenticators(self.server) |
| 337 | if auth is not None: |
| 338 | self.username, _, self.password = auth |
| 339 | except FileNotFoundError: |
| 340 | pass |
| 341 | except netrc.NetrcParseError as e: |
| 342 | bb.warn("Error parsing %s:%s: %s" % (e.filename, str(e.lineno), e.msg)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | |
| 344 | # Insert these classes into siggen's namespace so it can see and select them |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 345 | bb.siggen.SignatureGeneratorOEBasicHash = SignatureGeneratorOEBasicHash |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 346 | bb.siggen.SignatureGeneratorOEEquivHash = SignatureGeneratorOEEquivHash |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 347 | |
| 348 | |
| 349 | def find_siginfo(pn, taskname, taskhashlist, d): |
| 350 | """ Find signature data files for comparison purposes """ |
| 351 | |
| 352 | import fnmatch |
| 353 | import glob |
| 354 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 355 | if not taskname: |
| 356 | # We have to derive pn and taskname |
| 357 | key = pn |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 358 | if key.startswith("mc:"): |
| 359 | # mc:<mc>:<pn>:<task> |
| 360 | _, _, pn, taskname = key.split(':', 3) |
| 361 | else: |
| 362 | # <pn>:<task> |
| 363 | pn, taskname = key.split(':', 1) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 364 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 365 | hashfiles = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 366 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 367 | def get_hashval(siginfo): |
| 368 | if siginfo.endswith('.siginfo'): |
| 369 | return siginfo.rpartition(':')[2].partition('_')[0] |
| 370 | else: |
| 371 | return siginfo.rpartition('.')[2] |
| 372 | |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 373 | def get_time(fullpath): |
| 374 | return os.stat(fullpath).st_mtime |
| 375 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | # First search in stamps dir |
| 377 | localdata = d.createCopy() |
| 378 | localdata.setVar('MULTIMACH_TARGET_SYS', '*') |
| 379 | localdata.setVar('PN', pn) |
| 380 | localdata.setVar('PV', '*') |
| 381 | localdata.setVar('PR', '*') |
| 382 | localdata.setVar('EXTENDPE', '') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 383 | stamp = localdata.getVar('STAMP') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 384 | if pn.startswith("gcc-source"): |
| 385 | # gcc-source shared workdir is a special case :( |
| 386 | stamp = localdata.expand("${STAMPS_DIR}/work-shared/gcc-${PV}-${PR}") |
| 387 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 388 | filespec = '%s.%s.sigdata.*' % (stamp, taskname) |
| 389 | foundall = False |
| 390 | import glob |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 391 | bb.debug(1, "Calling glob.glob on {}".format(filespec)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 392 | for fullpath in glob.glob(filespec): |
| 393 | match = False |
| 394 | if taskhashlist: |
| 395 | for taskhash in taskhashlist: |
| 396 | if fullpath.endswith('.%s' % taskhash): |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 397 | hashfiles[taskhash] = {'path':fullpath, 'sstate':False, 'time':get_time(fullpath)} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 398 | if len(hashfiles) == len(taskhashlist): |
| 399 | foundall = True |
| 400 | break |
| 401 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 402 | hashval = get_hashval(fullpath) |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 403 | hashfiles[hashval] = {'path':fullpath, 'sstate':False, 'time':get_time(fullpath)} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 404 | |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 405 | if not taskhashlist or (len(hashfiles) < 2 and not foundall): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 406 | # That didn't work, look in sstate-cache |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 407 | hashes = taskhashlist or ['?' * 64] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 408 | localdata = bb.data.createCopy(d) |
| 409 | for hashval in hashes: |
| 410 | localdata.setVar('PACKAGE_ARCH', '*') |
| 411 | localdata.setVar('TARGET_VENDOR', '*') |
| 412 | localdata.setVar('TARGET_OS', '*') |
| 413 | localdata.setVar('PN', pn) |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 414 | # gcc-source is a special case, same as with local stamps above |
| 415 | if pn.startswith("gcc-source"): |
| 416 | localdata.setVar('PN', "gcc") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 417 | localdata.setVar('PV', '*') |
| 418 | localdata.setVar('PR', '*') |
| 419 | localdata.setVar('BB_TASKHASH', hashval) |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 420 | localdata.setVar('SSTATE_CURRTASK', taskname[3:]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 421 | swspec = localdata.getVar('SSTATE_SWSPEC') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 422 | if taskname in ['do_fetch', 'do_unpack', 'do_patch', 'do_populate_lic', 'do_preconfigure'] and swspec: |
| 423 | localdata.setVar('SSTATE_PKGSPEC', '${SSTATE_SWSPEC}') |
| 424 | elif pn.endswith('-native') or "-cross-" in pn or "-crosssdk-" in pn: |
| 425 | localdata.setVar('SSTATE_EXTRAPATH', "${NATIVELSBSTRING}/") |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 426 | filespec = '%s.siginfo' % localdata.getVar('SSTATE_PKG') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 427 | |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 428 | bb.debug(1, "Calling glob.glob on {}".format(filespec)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 429 | matchedfiles = glob.glob(filespec) |
| 430 | for fullpath in matchedfiles: |
| 431 | actual_hashval = get_hashval(fullpath) |
| 432 | if actual_hashval in hashfiles: |
| 433 | continue |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame^] | 434 | try: |
| 435 | hashfiles[actual_hashval] = {'path':fullpath, 'sstate':True, 'time':get_time(fullpath)} |
| 436 | except FileNotFoundError: |
| 437 | bb.warn("Could not obtain mtime for {}".format(fullpath)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 438 | |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 439 | return hashfiles |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 440 | |
| 441 | bb.siggen.find_siginfo = find_siginfo |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 442 | bb.siggen.find_siginfo_version = 2 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 443 | |
| 444 | |
| 445 | def sstate_get_manifest_filename(task, d): |
| 446 | """ |
| 447 | Return the sstate manifest file path for a particular task. |
| 448 | Also returns the datastore that can be used to query related variables. |
| 449 | """ |
| 450 | d2 = d.createCopy() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 451 | extrainf = d.getVarFlag("do_" + task, 'stamp-extra-info') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 452 | if extrainf: |
| 453 | d2.setVar("SSTATE_MANMACH", extrainf) |
| 454 | return (d2.expand("${SSTATE_MANFILEPREFIX}.%s" % task), d2) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 455 | |
| 456 | def find_sstate_manifest(taskdata, taskdata2, taskname, d, multilibcache): |
| 457 | d2 = d |
| 458 | variant = '' |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 459 | curr_variant = '' |
| 460 | if d.getVar("BBEXTENDCURR") == "multilib": |
| 461 | curr_variant = d.getVar("BBEXTENDVARIANT") |
| 462 | if "virtclass-multilib" not in d.getVar("OVERRIDES"): |
| 463 | curr_variant = "invalid" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 464 | if taskdata2.startswith("virtual:multilib"): |
| 465 | variant = taskdata2.split(":")[2] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 466 | if curr_variant != variant: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 467 | if variant not in multilibcache: |
| 468 | multilibcache[variant] = oe.utils.get_multilib_datastore(variant, d) |
| 469 | d2 = multilibcache[variant] |
| 470 | |
| 471 | if taskdata.endswith("-native"): |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 472 | pkgarchs = ["${BUILD_ARCH}", "${BUILD_ARCH}_${ORIGNATIVELSBSTRING}"] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 473 | elif taskdata.startswith("nativesdk-"): |
| 474 | pkgarchs = ["${SDK_ARCH}_${SDK_OS}", "allarch"] |
| 475 | elif "-cross-canadian" in taskdata: |
| 476 | pkgarchs = ["${SDK_ARCH}_${SDK_ARCH}-${SDKPKGSUFFIX}"] |
| 477 | elif "-cross-" in taskdata: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 478 | pkgarchs = ["${BUILD_ARCH}"] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 479 | elif "-crosssdk" in taskdata: |
| 480 | pkgarchs = ["${BUILD_ARCH}_${SDK_ARCH}_${SDK_OS}"] |
| 481 | else: |
| 482 | pkgarchs = ['${MACHINE_ARCH}'] |
| 483 | pkgarchs = pkgarchs + list(reversed(d2.getVar("PACKAGE_EXTRA_ARCHS").split())) |
| 484 | pkgarchs.append('allarch') |
| 485 | pkgarchs.append('${SDK_ARCH}_${SDK_ARCH}-${SDKPKGSUFFIX}') |
| 486 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 487 | searched_manifests = [] |
| 488 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 489 | for pkgarch in pkgarchs: |
| 490 | manifest = d2.expand("${SSTATE_MANIFESTS}/manifest-%s-%s.%s" % (pkgarch, taskdata, taskname)) |
| 491 | if os.path.exists(manifest): |
| 492 | return manifest, d2 |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 493 | searched_manifests.append(manifest) |
| 494 | bb.fatal("The sstate manifest for task '%s:%s' (multilib variant '%s') could not be found.\nThe pkgarchs considered were: %s.\nBut none of these manifests exists:\n %s" |
| 495 | % (taskdata, taskname, variant, d2.expand(", ".join(pkgarchs)),"\n ".join(searched_manifests))) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 496 | return None, d2 |
| 497 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 498 | def OEOuthashBasic(path, sigfile, task, d): |
| 499 | """ |
| 500 | Basic output hash function |
| 501 | |
| 502 | Calculates the output hash of a task by hashing all output file metadata, |
| 503 | and file contents. |
| 504 | """ |
| 505 | import hashlib |
| 506 | import stat |
| 507 | import pwd |
| 508 | import grp |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 509 | import re |
| 510 | import fnmatch |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 511 | |
| 512 | def update_hash(s): |
| 513 | s = s.encode('utf-8') |
| 514 | h.update(s) |
| 515 | if sigfile: |
| 516 | sigfile.write(s) |
| 517 | |
| 518 | h = hashlib.sha256() |
| 519 | prev_dir = os.getcwd() |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 520 | corebase = d.getVar("COREBASE") |
| 521 | tmpdir = d.getVar("TMPDIR") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 522 | include_owners = os.environ.get('PSEUDO_DISABLED') == '0' |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 523 | if "package_write_" in task or task == "package_qa": |
| 524 | include_owners = False |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 525 | include_timestamps = False |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 526 | include_root = True |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 527 | if task == "package": |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 528 | include_timestamps = True |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 529 | include_root = False |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 530 | hash_version = d.getVar('HASHEQUIV_HASH_VERSION') |
| 531 | extra_sigdata = d.getVar("HASHEQUIV_EXTRA_SIGDATA") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 532 | |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 533 | filemaps = {} |
| 534 | for m in (d.getVar('SSTATE_HASHEQUIV_FILEMAP') or '').split(): |
| 535 | entry = m.split(":") |
| 536 | if len(entry) != 3 or entry[0] != task: |
| 537 | continue |
| 538 | filemaps.setdefault(entry[1], []) |
| 539 | filemaps[entry[1]].append(entry[2]) |
| 540 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 541 | try: |
| 542 | os.chdir(path) |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 543 | basepath = os.path.normpath(path) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 544 | |
| 545 | update_hash("OEOuthashBasic\n") |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 546 | if hash_version: |
| 547 | update_hash(hash_version + "\n") |
| 548 | |
| 549 | if extra_sigdata: |
| 550 | update_hash(extra_sigdata + "\n") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 551 | |
| 552 | # It is only currently useful to get equivalent hashes for things that |
| 553 | # can be restored from sstate. Since the sstate object is named using |
| 554 | # SSTATE_PKGSPEC and the task name, those should be included in the |
| 555 | # output hash calculation. |
| 556 | update_hash("SSTATE_PKGSPEC=%s\n" % d.getVar('SSTATE_PKGSPEC')) |
| 557 | update_hash("task=%s\n" % task) |
| 558 | |
| 559 | for root, dirs, files in os.walk('.', topdown=True): |
| 560 | # Sort directories to ensure consistent ordering when recursing |
| 561 | dirs.sort() |
| 562 | files.sort() |
| 563 | |
| 564 | def process(path): |
| 565 | s = os.lstat(path) |
| 566 | |
| 567 | if stat.S_ISDIR(s.st_mode): |
| 568 | update_hash('d') |
| 569 | elif stat.S_ISCHR(s.st_mode): |
| 570 | update_hash('c') |
| 571 | elif stat.S_ISBLK(s.st_mode): |
| 572 | update_hash('b') |
| 573 | elif stat.S_ISSOCK(s.st_mode): |
| 574 | update_hash('s') |
| 575 | elif stat.S_ISLNK(s.st_mode): |
| 576 | update_hash('l') |
| 577 | elif stat.S_ISFIFO(s.st_mode): |
| 578 | update_hash('p') |
| 579 | else: |
| 580 | update_hash('-') |
| 581 | |
| 582 | def add_perm(mask, on, off='-'): |
| 583 | if mask & s.st_mode: |
| 584 | update_hash(on) |
| 585 | else: |
| 586 | update_hash(off) |
| 587 | |
| 588 | add_perm(stat.S_IRUSR, 'r') |
| 589 | add_perm(stat.S_IWUSR, 'w') |
| 590 | if stat.S_ISUID & s.st_mode: |
| 591 | add_perm(stat.S_IXUSR, 's', 'S') |
| 592 | else: |
| 593 | add_perm(stat.S_IXUSR, 'x') |
| 594 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 595 | if include_owners: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 596 | # Group/other permissions are only relevant in pseudo context |
| 597 | add_perm(stat.S_IRGRP, 'r') |
| 598 | add_perm(stat.S_IWGRP, 'w') |
| 599 | if stat.S_ISGID & s.st_mode: |
| 600 | add_perm(stat.S_IXGRP, 's', 'S') |
| 601 | else: |
| 602 | add_perm(stat.S_IXGRP, 'x') |
| 603 | |
| 604 | add_perm(stat.S_IROTH, 'r') |
| 605 | add_perm(stat.S_IWOTH, 'w') |
| 606 | if stat.S_ISVTX & s.st_mode: |
| 607 | update_hash('t') |
| 608 | else: |
| 609 | add_perm(stat.S_IXOTH, 'x') |
| 610 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 611 | try: |
| 612 | update_hash(" %10s" % pwd.getpwuid(s.st_uid).pw_name) |
| 613 | update_hash(" %10s" % grp.getgrgid(s.st_gid).gr_name) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 614 | except KeyError as e: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 615 | msg = ("KeyError: %s\nPath %s is owned by uid %d, gid %d, which doesn't match " |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 616 | "any user/group on target. This may be due to host contamination." % |
| 617 | (e, os.path.abspath(path), s.st_uid, s.st_gid)) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 618 | raise Exception(msg).with_traceback(e.__traceback__) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 619 | |
Andrew Geissler | 6ce62a2 | 2020-11-30 19:58:47 -0600 | [diff] [blame] | 620 | if include_timestamps: |
| 621 | update_hash(" %10d" % s.st_mtime) |
| 622 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 623 | update_hash(" ") |
| 624 | if stat.S_ISBLK(s.st_mode) or stat.S_ISCHR(s.st_mode): |
| 625 | update_hash("%9s" % ("%d.%d" % (os.major(s.st_rdev), os.minor(s.st_rdev)))) |
| 626 | else: |
| 627 | update_hash(" " * 9) |
| 628 | |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 629 | filterfile = False |
| 630 | for entry in filemaps: |
| 631 | if fnmatch.fnmatch(path, entry): |
| 632 | filterfile = True |
| 633 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 634 | update_hash(" ") |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 635 | if stat.S_ISREG(s.st_mode) and not filterfile: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 636 | update_hash("%10d" % s.st_size) |
| 637 | else: |
| 638 | update_hash(" " * 10) |
| 639 | |
| 640 | update_hash(" ") |
| 641 | fh = hashlib.sha256() |
| 642 | if stat.S_ISREG(s.st_mode): |
| 643 | # Hash file contents |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 644 | if filterfile: |
| 645 | # Need to ignore paths in crossscripts and postinst-useradd files. |
| 646 | with open(path, 'rb') as d: |
| 647 | chunk = d.read() |
| 648 | chunk = chunk.replace(bytes(basepath, encoding='utf8'), b'') |
| 649 | for entry in filemaps: |
| 650 | if not fnmatch.fnmatch(path, entry): |
| 651 | continue |
| 652 | for r in filemaps[entry]: |
| 653 | if r.startswith("regex-"): |
| 654 | chunk = re.sub(bytes(r[6:], encoding='utf8'), b'', chunk) |
| 655 | else: |
| 656 | chunk = chunk.replace(bytes(r, encoding='utf8'), b'') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 657 | fh.update(chunk) |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 658 | else: |
| 659 | with open(path, 'rb') as d: |
| 660 | for chunk in iter(lambda: d.read(4096), b""): |
| 661 | fh.update(chunk) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 662 | update_hash(fh.hexdigest()) |
| 663 | else: |
| 664 | update_hash(" " * len(fh.hexdigest())) |
| 665 | |
| 666 | update_hash(" %s" % path) |
| 667 | |
| 668 | if stat.S_ISLNK(s.st_mode): |
| 669 | update_hash(" -> %s" % os.readlink(path)) |
| 670 | |
| 671 | update_hash("\n") |
| 672 | |
| 673 | # Process this directory and all its child files |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 674 | if include_root or root != ".": |
| 675 | process(root) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 676 | for f in files: |
| 677 | if f == 'fixmepath': |
| 678 | continue |
| 679 | process(os.path.join(root, f)) |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 680 | |
| 681 | for dir in dirs: |
| 682 | if os.path.islink(os.path.join(root, dir)): |
| 683 | process(os.path.join(root, dir)) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 684 | finally: |
| 685 | os.chdir(prev_dir) |
| 686 | |
| 687 | return h.hexdigest() |
| 688 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 689 | |