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