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 BitBake Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0-only |
| 5 | # |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | import hashlib |
| 8 | import logging |
| 9 | import os |
| 10 | import re |
| 11 | import tempfile |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 12 | import pickle |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | import bb.data |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | import difflib |
| 15 | import simplediff |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 16 | import json |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 17 | import types |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 18 | import bb.compress.zstd |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 19 | from bb.checksum import FileChecksumCache |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 20 | from bb import runqueue |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 21 | import hashserv |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 22 | import hashserv.client |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | |
| 24 | logger = logging.getLogger('BitBake.SigGen') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 25 | hashequiv_logger = logging.getLogger('BitBake.SigGen.HashEquiv') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | |
Patrick Williams | 169d7bc | 2024-01-05 11:33:25 -0600 | [diff] [blame] | 27 | #find_siginfo and find_siginfo_version are set by the metadata siggen |
| 28 | # The minimum version of the find_siginfo function we need |
| 29 | find_siginfo_minversion = 2 |
| 30 | |
| 31 | def check_siggen_version(siggen): |
| 32 | if not hasattr(siggen, "find_siginfo_version"): |
| 33 | bb.fatal("Siggen from metadata (OE-Core?) is too old, please update it (no version found)") |
| 34 | if siggen.find_siginfo_version < siggen.find_siginfo_minversion: |
| 35 | bb.fatal("Siggen from metadata (OE-Core?) is too old, please update it (%s vs %s)" % (siggen.find_siginfo_version, siggen.find_siginfo_minversion)) |
| 36 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 37 | class SetEncoder(json.JSONEncoder): |
| 38 | def default(self, obj): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 39 | if isinstance(obj, set) or isinstance(obj, frozenset): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 40 | return dict(_set_object=list(sorted(obj))) |
| 41 | return json.JSONEncoder.default(self, obj) |
| 42 | |
| 43 | def SetDecoder(dct): |
| 44 | if '_set_object' in dct: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 45 | return frozenset(dct['_set_object']) |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 46 | return dct |
| 47 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | def init(d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 49 | siggens = [obj for obj in globals().values() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 50 | if type(obj) is type and issubclass(obj, SignatureGenerator)] |
| 51 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 52 | desired = d.getVar("BB_SIGNATURE_HANDLER") or "noop" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | for sg in siggens: |
| 54 | if desired == sg.name: |
| 55 | return sg(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | else: |
| 57 | logger.error("Invalid signature generator '%s', using default 'noop'\n" |
| 58 | "Available generators: %s", desired, |
| 59 | ', '.join(obj.name for obj in siggens)) |
| 60 | return SignatureGenerator(d) |
| 61 | |
| 62 | class SignatureGenerator(object): |
| 63 | """ |
| 64 | """ |
| 65 | name = "noop" |
| 66 | |
| 67 | def __init__(self, data): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 68 | self.basehash = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | self.taskhash = {} |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 70 | self.unihash = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | self.runtaskdeps = {} |
| 72 | self.file_checksum_values = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 73 | self.taints = {} |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 74 | self.unitaskhashes = {} |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 75 | self.tidtopn = {} |
| 76 | self.setscenetasks = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | |
| 78 | def finalise(self, fn, d, varient): |
| 79 | return |
| 80 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 81 | def postparsing_clean_cache(self): |
| 82 | return |
| 83 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 84 | def setup_datacache(self, datacaches): |
| 85 | self.datacaches = datacaches |
| 86 | |
| 87 | def setup_datacache_from_datastore(self, mcfn, d): |
| 88 | # In task context we have no cache so setup internal data structures |
| 89 | # from the fully parsed data store provided |
| 90 | |
| 91 | mc = d.getVar("__BBMULTICONFIG", False) or "" |
| 92 | tasks = d.getVar('__BBTASKS', False) |
| 93 | |
| 94 | self.datacaches = {} |
| 95 | self.datacaches[mc] = types.SimpleNamespace() |
| 96 | setattr(self.datacaches[mc], "stamp", {}) |
| 97 | self.datacaches[mc].stamp[mcfn] = d.getVar('STAMP') |
| 98 | setattr(self.datacaches[mc], "stamp_extrainfo", {}) |
| 99 | self.datacaches[mc].stamp_extrainfo[mcfn] = {} |
| 100 | for t in tasks: |
| 101 | flag = d.getVarFlag(t, "stamp-extra-info") |
| 102 | if flag: |
| 103 | self.datacaches[mc].stamp_extrainfo[mcfn][t] = flag |
| 104 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 105 | def get_unihash(self, tid): |
| 106 | return self.taskhash[tid] |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 107 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 108 | def prep_taskhash(self, tid, deps, dataCaches): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 109 | return |
| 110 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 111 | def get_taskhash(self, tid, deps, dataCaches): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 112 | self.taskhash[tid] = hashlib.sha256(tid.encode("utf-8")).hexdigest() |
| 113 | return self.taskhash[tid] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 115 | def writeout_file_checksum_cache(self): |
| 116 | """Write/update the file checksum cache onto disk""" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | return |
| 118 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 119 | def stampfile_base(self, mcfn): |
| 120 | mc = bb.runqueue.mc_from_tid(mcfn) |
| 121 | return self.datacaches[mc].stamp[mcfn] |
| 122 | |
| 123 | def stampfile_mcfn(self, taskname, mcfn, extrainfo=True): |
| 124 | mc = bb.runqueue.mc_from_tid(mcfn) |
| 125 | stamp = self.datacaches[mc].stamp[mcfn] |
| 126 | if not stamp: |
| 127 | return |
| 128 | |
| 129 | stamp_extrainfo = "" |
| 130 | if extrainfo: |
| 131 | taskflagname = taskname |
| 132 | if taskname.endswith("_setscene"): |
| 133 | taskflagname = taskname.replace("_setscene", "") |
| 134 | stamp_extrainfo = self.datacaches[mc].stamp_extrainfo[mcfn].get(taskflagname) or "" |
| 135 | |
| 136 | return self.stampfile(stamp, mcfn, taskname, stamp_extrainfo) |
| 137 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | def stampfile(self, stampbase, file_name, taskname, extrainfo): |
| 139 | return ("%s.%s.%s" % (stampbase, taskname, extrainfo)).rstrip('.') |
| 140 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 141 | def stampcleanmask_mcfn(self, taskname, mcfn): |
| 142 | mc = bb.runqueue.mc_from_tid(mcfn) |
| 143 | stamp = self.datacaches[mc].stamp[mcfn] |
| 144 | if not stamp: |
| 145 | return [] |
| 146 | |
| 147 | taskflagname = taskname |
| 148 | if taskname.endswith("_setscene"): |
| 149 | taskflagname = taskname.replace("_setscene", "") |
| 150 | stamp_extrainfo = self.datacaches[mc].stamp_extrainfo[mcfn].get(taskflagname) or "" |
| 151 | |
| 152 | return self.stampcleanmask(stamp, mcfn, taskname, stamp_extrainfo) |
| 153 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | def stampcleanmask(self, stampbase, file_name, taskname, extrainfo): |
| 155 | return ("%s.%s.%s" % (stampbase, taskname, extrainfo)).rstrip('.') |
| 156 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 157 | def dump_sigtask(self, mcfn, task, stampbase, runtime): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 158 | return |
| 159 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 160 | def invalidate_task(self, task, mcfn): |
| 161 | mc = bb.runqueue.mc_from_tid(mcfn) |
| 162 | stamp = self.datacaches[mc].stamp[mcfn] |
| 163 | bb.utils.remove(stamp) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 164 | |
| 165 | def dump_sigs(self, dataCache, options): |
| 166 | return |
| 167 | |
| 168 | def get_taskdata(self): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 169 | return (self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes, self.tidtopn, self.setscenetasks) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 170 | |
| 171 | def set_taskdata(self, data): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 172 | self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes, self.tidtopn, self.setscenetasks = data |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 173 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 174 | def reset(self, data): |
| 175 | self.__init__(data) |
| 176 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 177 | def get_taskhashes(self): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 178 | return self.taskhash, self.unihash, self.unitaskhashes, self.tidtopn |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 179 | |
| 180 | def set_taskhashes(self, hashes): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 181 | self.taskhash, self.unihash, self.unitaskhashes, self.tidtopn = hashes |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 182 | |
| 183 | def save_unitaskhashes(self): |
| 184 | return |
| 185 | |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 186 | def copy_unitaskhashes(self, targetdir): |
| 187 | return |
| 188 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 189 | def set_setscene_tasks(self, setscene_tasks): |
| 190 | return |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 191 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 192 | def exit(self): |
| 193 | return |
| 194 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 195 | def build_pnid(mc, pn, taskname): |
| 196 | if mc: |
| 197 | return "mc:" + mc + ":" + pn + ":" + taskname |
| 198 | return pn + ":" + taskname |
| 199 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | class SignatureGeneratorBasic(SignatureGenerator): |
| 201 | """ |
| 202 | """ |
| 203 | name = "basic" |
| 204 | |
| 205 | def __init__(self, data): |
| 206 | self.basehash = {} |
| 207 | self.taskhash = {} |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 208 | self.unihash = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | self.runtaskdeps = {} |
| 210 | self.file_checksum_values = {} |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 211 | self.taints = {} |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 212 | self.setscenetasks = set() |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 213 | self.basehash_ignore_vars = set((data.getVar("BB_BASEHASH_IGNORE_VARS") or "").split()) |
| 214 | self.taskhash_ignore_tasks = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 215 | self.init_rundepcheck(data) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 216 | checksum_cache_file = data.getVar("BB_HASH_CHECKSUM_CACHE_FILE") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 217 | if checksum_cache_file: |
| 218 | self.checksum_cache = FileChecksumCache() |
| 219 | self.checksum_cache.init_cache(data, checksum_cache_file) |
| 220 | else: |
| 221 | self.checksum_cache = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 222 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 223 | self.unihash_cache = bb.cache.SimpleCache("3") |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 224 | self.unitaskhashes = self.unihash_cache.init_cache(data, "bb_unihashes.dat", {}) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 225 | self.localdirsexclude = (data.getVar("BB_SIGNATURE_LOCAL_DIRS_EXCLUDE") or "CVS .bzr .git .hg .osc .p4 .repo .svn").split() |
| 226 | self.tidtopn = {} |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 227 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | def init_rundepcheck(self, data): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 229 | self.taskhash_ignore_tasks = data.getVar("BB_TASKHASH_IGNORE_TASKS") or None |
| 230 | if self.taskhash_ignore_tasks: |
| 231 | self.twl = re.compile(self.taskhash_ignore_tasks) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | else: |
| 233 | self.twl = None |
| 234 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 235 | def _build_data(self, mcfn, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 236 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 237 | ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') == '1') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 238 | tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d, self.basehash_ignore_vars) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 239 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 240 | taskdeps, basehash = bb.data.generate_dependency_hash(tasklist, gendeps, lookupcache, self.basehash_ignore_vars, mcfn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | |
| 242 | for task in tasklist: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 243 | tid = mcfn + ":" + task |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 244 | if not ignore_mismatch and tid in self.basehash and self.basehash[tid] != basehash[tid]: |
| 245 | bb.error("When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed." % (tid, self.basehash[tid], basehash[tid])) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 246 | bb.error("The following commands may help:") |
| 247 | cmd = "$ bitbake %s -c%s" % (d.getVar('PN'), task) |
| 248 | # Make sure sigdata is dumped before run printdiff |
| 249 | bb.error("%s -Snone" % cmd) |
| 250 | bb.error("Then:") |
| 251 | bb.error("%s -Sprintdiff\n" % cmd) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 252 | self.basehash[tid] = basehash[tid] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 253 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 254 | return taskdeps, gendeps, lookupcache |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 255 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 256 | def set_setscene_tasks(self, setscene_tasks): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 257 | self.setscenetasks = set(setscene_tasks) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 258 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | def finalise(self, fn, d, variant): |
| 260 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 261 | mc = d.getVar("__BBMULTICONFIG", False) or "" |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 262 | mcfn = fn |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 263 | if variant or mc: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 264 | mcfn = bb.cache.realfn2virtual(fn, variant, mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | |
| 266 | try: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 267 | taskdeps, gendeps, lookupcache = self._build_data(mcfn, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 268 | except bb.parse.SkipRecipe: |
| 269 | raise |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | except: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 271 | bb.warn("Error during finalise of %s" % mcfn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 272 | raise |
| 273 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 274 | basehashes = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | for task in taskdeps: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 276 | basehashes[task] = self.basehash[mcfn + ":" + task] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 277 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 278 | d.setVar("__siggen_basehashes", basehashes) |
| 279 | d.setVar("__siggen_gendeps", gendeps) |
| 280 | d.setVar("__siggen_varvals", lookupcache) |
| 281 | d.setVar("__siggen_taskdeps", taskdeps) |
| 282 | |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 283 | #Slow but can be useful for debugging mismatched basehashes |
| 284 | #self.setup_datacache_from_datastore(mcfn, d) |
| 285 | #for task in taskdeps: |
| 286 | # self.dump_sigtask(mcfn, task, d.getVar("STAMP"), False) |
| 287 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 288 | def setup_datacache_from_datastore(self, mcfn, d): |
| 289 | super().setup_datacache_from_datastore(mcfn, d) |
| 290 | |
| 291 | mc = bb.runqueue.mc_from_tid(mcfn) |
| 292 | for attr in ["siggen_varvals", "siggen_taskdeps", "siggen_gendeps"]: |
| 293 | if not hasattr(self.datacaches[mc], attr): |
| 294 | setattr(self.datacaches[mc], attr, {}) |
| 295 | self.datacaches[mc].siggen_varvals[mcfn] = d.getVar("__siggen_varvals") |
| 296 | self.datacaches[mc].siggen_taskdeps[mcfn] = d.getVar("__siggen_taskdeps") |
| 297 | self.datacaches[mc].siggen_gendeps[mcfn] = d.getVar("__siggen_gendeps") |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 298 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 299 | def rundep_check(self, fn, recipename, task, dep, depname, dataCaches): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 300 | # Return True if we should keep the dependency, False to drop it |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 301 | # We only manipulate the dependencies for packages not in the ignore |
| 302 | # list |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 303 | if self.twl and not self.twl.search(recipename): |
| 304 | # then process the actual dependencies |
| 305 | if self.twl.search(depname): |
| 306 | return False |
| 307 | return True |
| 308 | |
| 309 | def read_taint(self, fn, task, stampbase): |
| 310 | taint = None |
| 311 | try: |
| 312 | with open(stampbase + '.' + task + '.taint', 'r') as taintf: |
| 313 | taint = taintf.read() |
| 314 | except IOError: |
| 315 | pass |
| 316 | return taint |
| 317 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 318 | def prep_taskhash(self, tid, deps, dataCaches): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 319 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 320 | (mc, _, task, mcfn) = bb.runqueue.split_tid_mcfn(tid) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 321 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 322 | self.basehash[tid] = dataCaches[mc].basetaskhash[tid] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 323 | self.runtaskdeps[tid] = [] |
| 324 | self.file_checksum_values[tid] = [] |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 325 | recipename = dataCaches[mc].pkg_fn[mcfn] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 326 | |
| 327 | self.tidtopn[tid] = recipename |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 328 | # save hashfn for deps into siginfo? |
| 329 | for dep in deps: |
| 330 | (depmc, _, deptask, depmcfn) = bb.runqueue.split_tid_mcfn(dep) |
| 331 | dep_pn = dataCaches[depmc].pkg_fn[depmcfn] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 332 | |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 333 | if not self.rundep_check(mcfn, recipename, task, dep, dep_pn, dataCaches): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 334 | continue |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 335 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 336 | if dep not in self.taskhash: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 337 | bb.fatal("%s is not in taskhash, caller isn't calling in dependency order?" % dep) |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 338 | |
| 339 | dep_pnid = build_pnid(depmc, dep_pn, deptask) |
| 340 | self.runtaskdeps[tid].append((dep_pnid, dep)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 341 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 342 | if task in dataCaches[mc].file_checksums[mcfn]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 343 | if self.checksum_cache: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 344 | checksums = self.checksum_cache.get_checksums(dataCaches[mc].file_checksums[mcfn][task], recipename, self.localdirsexclude) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 345 | else: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 346 | checksums = bb.fetch2.get_file_checksums(dataCaches[mc].file_checksums[mcfn][task], recipename, self.localdirsexclude) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 347 | for (f,cs) in checksums: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 348 | self.file_checksum_values[tid].append((f,cs)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 349 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 350 | taskdep = dataCaches[mc].task_deps[mcfn] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | if 'nostamp' in taskdep and task in taskdep['nostamp']: |
| 352 | # Nostamp tasks need an implicit taint so that they force any dependent tasks to run |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 353 | if tid in self.taints and self.taints[tid].startswith("nostamp:"): |
| 354 | # Don't reset taint value upon every call |
| 355 | pass |
| 356 | else: |
| 357 | import uuid |
| 358 | taint = str(uuid.uuid4()) |
| 359 | self.taints[tid] = "nostamp:" + taint |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 360 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 361 | taint = self.read_taint(mcfn, task, dataCaches[mc].stamp[mcfn]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 362 | if taint: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 363 | self.taints[tid] = taint |
| 364 | logger.warning("%s is tainted from a forced run" % tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 365 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 366 | return |
| 367 | |
Andrew Geissler | 5a43b43 | 2020-06-13 10:46:56 -0500 | [diff] [blame] | 368 | def get_taskhash(self, tid, deps, dataCaches): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 369 | |
| 370 | data = self.basehash[tid] |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 371 | for dep in sorted(self.runtaskdeps[tid]): |
| 372 | data += self.get_unihash(dep[1]) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 373 | |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 374 | for (f, cs) in sorted(self.file_checksum_values[tid], key=clean_checksum_file_path): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 375 | if cs: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 376 | if "/./" in f: |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame] | 377 | data += "./" + f.split("/./")[1] |
| 378 | data += cs |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 379 | |
| 380 | if tid in self.taints: |
| 381 | if self.taints[tid].startswith("nostamp:"): |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame] | 382 | data += self.taints[tid][8:] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 383 | else: |
Patrick Williams | 864cc43 | 2023-02-09 14:54:44 -0600 | [diff] [blame] | 384 | data += self.taints[tid] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 385 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 386 | h = hashlib.sha256(data.encode("utf-8")).hexdigest() |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 387 | self.taskhash[tid] = h |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 388 | #d.setVar("BB_TASKHASH:task-%s" % task, taskhash[task]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 389 | return h |
| 390 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 391 | def writeout_file_checksum_cache(self): |
| 392 | """Write/update the file checksum cache onto disk""" |
| 393 | if self.checksum_cache: |
| 394 | self.checksum_cache.save_extras() |
| 395 | self.checksum_cache.save_merge() |
| 396 | else: |
| 397 | bb.fetch2.fetcher_parse_save() |
| 398 | bb.fetch2.fetcher_parse_done() |
| 399 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 400 | def save_unitaskhashes(self): |
| 401 | self.unihash_cache.save(self.unitaskhashes) |
| 402 | |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 403 | def copy_unitaskhashes(self, targetdir): |
| 404 | self.unihash_cache.copyfile(targetdir) |
| 405 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 406 | def dump_sigtask(self, mcfn, task, stampbase, runtime): |
| 407 | tid = mcfn + ":" + task |
| 408 | mc = bb.runqueue.mc_from_tid(mcfn) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 409 | referencestamp = stampbase |
| 410 | if isinstance(runtime, str) and runtime.startswith("customfile"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 411 | sigfile = stampbase |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 412 | referencestamp = runtime[11:] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 413 | elif runtime and tid in self.taskhash: |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 414 | sigfile = stampbase + "." + task + ".sigdata" + "." + self.get_unihash(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 415 | else: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 416 | sigfile = stampbase + "." + task + ".sigbasedata" + "." + self.basehash[tid] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 417 | |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 418 | with bb.utils.umask(0o002): |
| 419 | bb.utils.mkdirhier(os.path.dirname(sigfile)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 420 | |
| 421 | data = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 422 | data['task'] = task |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 423 | data['basehash_ignore_vars'] = self.basehash_ignore_vars |
| 424 | data['taskhash_ignore_tasks'] = self.taskhash_ignore_tasks |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 425 | data['taskdeps'] = self.datacaches[mc].siggen_taskdeps[mcfn][task] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 426 | data['basehash'] = self.basehash[tid] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 427 | data['gendeps'] = {} |
| 428 | data['varvals'] = {} |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 429 | data['varvals'][task] = self.datacaches[mc].siggen_varvals[mcfn][task] |
| 430 | for dep in self.datacaches[mc].siggen_taskdeps[mcfn][task]: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 431 | if dep in self.basehash_ignore_vars: |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 432 | continue |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 433 | data['gendeps'][dep] = self.datacaches[mc].siggen_gendeps[mcfn][dep] |
| 434 | data['varvals'][dep] = self.datacaches[mc].siggen_varvals[mcfn][dep] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 435 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 436 | if runtime and tid in self.taskhash: |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 437 | data['runtaskdeps'] = [dep[0] for dep in sorted(self.runtaskdeps[tid])] |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 438 | data['file_checksum_values'] = [] |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 439 | for f,cs in sorted(self.file_checksum_values[tid], key=clean_checksum_file_path): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 440 | if "/./" in f: |
| 441 | data['file_checksum_values'].append(("./" + f.split("/./")[1], cs)) |
| 442 | else: |
| 443 | data['file_checksum_values'].append((os.path.basename(f), cs)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 444 | data['runtaskhashes'] = {} |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 445 | for dep in self.runtaskdeps[tid]: |
| 446 | data['runtaskhashes'][dep[0]] = self.get_unihash(dep[1]) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 447 | data['taskhash'] = self.taskhash[tid] |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 448 | data['unihash'] = self.get_unihash(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 449 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 450 | taint = self.read_taint(mcfn, task, referencestamp) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 451 | if taint: |
| 452 | data['taint'] = taint |
| 453 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 454 | if runtime and tid in self.taints: |
| 455 | if 'nostamp:' in self.taints[tid]: |
| 456 | data['taint'] = self.taints[tid] |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 457 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 458 | computed_basehash = calc_basehash(data) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 459 | if computed_basehash != self.basehash[tid]: |
| 460 | bb.error("Basehash mismatch %s versus %s for %s" % (computed_basehash, self.basehash[tid], tid)) |
| 461 | if runtime and tid in self.taskhash: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 462 | computed_taskhash = calc_taskhash(data) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 463 | if computed_taskhash != self.taskhash[tid]: |
| 464 | bb.error("Taskhash mismatch %s versus %s for %s" % (computed_taskhash, self.taskhash[tid], tid)) |
| 465 | sigfile = sigfile.replace(self.taskhash[tid], computed_taskhash) |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 466 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 467 | fd, tmpfile = bb.utils.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 468 | try: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 469 | with bb.compress.zstd.open(fd, "wt", encoding="utf-8", num_threads=1) as f: |
| 470 | json.dump(data, f, sort_keys=True, separators=(",", ":"), cls=SetEncoder) |
| 471 | f.flush() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 472 | os.chmod(tmpfile, 0o664) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 473 | bb.utils.rename(tmpfile, sigfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 474 | except (OSError, IOError) as err: |
| 475 | try: |
| 476 | os.unlink(tmpfile) |
| 477 | except OSError: |
| 478 | pass |
| 479 | raise err |
| 480 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 481 | class SignatureGeneratorBasicHash(SignatureGeneratorBasic): |
| 482 | name = "basichash" |
| 483 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 484 | def get_stampfile_hash(self, tid): |
| 485 | if tid in self.taskhash: |
| 486 | return self.taskhash[tid] |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 487 | |
| 488 | # If task is not in basehash, then error |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 489 | return self.basehash[tid] |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 490 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 491 | def stampfile(self, stampbase, mcfn, taskname, extrainfo, clean=False): |
| 492 | if taskname.endswith("_setscene"): |
| 493 | tid = mcfn + ":" + taskname[:-9] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 494 | else: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 495 | tid = mcfn + ":" + taskname |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 496 | if clean: |
| 497 | h = "*" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 498 | else: |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 499 | h = self.get_stampfile_hash(tid) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 500 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 501 | return ("%s.%s.%s.%s" % (stampbase, taskname, h, extrainfo)).rstrip('.') |
| 502 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 503 | def stampcleanmask(self, stampbase, mcfn, taskname, extrainfo): |
| 504 | return self.stampfile(stampbase, mcfn, taskname, extrainfo, clean=True) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 505 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 506 | def invalidate_task(self, task, mcfn): |
| 507 | bb.note("Tainting hash to force rebuild of task %s, %s" % (mcfn, task)) |
| 508 | |
| 509 | mc = bb.runqueue.mc_from_tid(mcfn) |
| 510 | stamp = self.datacaches[mc].stamp[mcfn] |
| 511 | |
| 512 | taintfn = stamp + '.' + task + '.taint' |
| 513 | |
| 514 | import uuid |
| 515 | bb.utils.mkdirhier(os.path.dirname(taintfn)) |
| 516 | # The specific content of the taint file is not really important, |
| 517 | # we just need it to be random, so a random UUID is used |
| 518 | with open(taintfn, 'w') as taintf: |
| 519 | taintf.write(str(uuid.uuid4())) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 520 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 521 | class SignatureGeneratorUniHashMixIn(object): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 522 | def __init__(self, data): |
| 523 | self.extramethod = {} |
| 524 | super().__init__(data) |
| 525 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 526 | def get_taskdata(self): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 527 | return (self.server, self.method, self.extramethod) + super().get_taskdata() |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 528 | |
| 529 | def set_taskdata(self, data): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 530 | self.server, self.method, self.extramethod = data[:3] |
| 531 | super().set_taskdata(data[3:]) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 532 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 533 | def client(self): |
| 534 | if getattr(self, '_client', None) is None: |
| 535 | self._client = hashserv.create_client(self.server) |
| 536 | return self._client |
| 537 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 538 | def reset(self, data): |
| 539 | if getattr(self, '_client', None) is not None: |
| 540 | self._client.close() |
| 541 | self._client = None |
| 542 | return super().reset(data) |
| 543 | |
| 544 | def exit(self): |
| 545 | if getattr(self, '_client', None) is not None: |
| 546 | self._client.close() |
| 547 | self._client = None |
| 548 | return super().exit() |
| 549 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 550 | def get_stampfile_hash(self, tid): |
| 551 | if tid in self.taskhash: |
| 552 | # If a unique hash is reported, use it as the stampfile hash. This |
| 553 | # ensures that if a task won't be re-run if the taskhash changes, |
| 554 | # but it would result in the same output hash |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 555 | unihash = self._get_unihash(tid) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 556 | if unihash is not None: |
| 557 | return unihash |
| 558 | |
| 559 | return super().get_stampfile_hash(tid) |
| 560 | |
| 561 | def set_unihash(self, tid, unihash): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 562 | (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid) |
| 563 | key = mc + ":" + self.tidtopn[tid] + ":" + taskname |
| 564 | self.unitaskhashes[key] = (self.taskhash[tid], unihash) |
| 565 | self.unihash[tid] = unihash |
| 566 | |
| 567 | def _get_unihash(self, tid, checkkey=None): |
| 568 | if tid not in self.tidtopn: |
| 569 | return None |
| 570 | (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid) |
| 571 | key = mc + ":" + self.tidtopn[tid] + ":" + taskname |
| 572 | if key not in self.unitaskhashes: |
| 573 | return None |
| 574 | if not checkkey: |
| 575 | checkkey = self.taskhash[tid] |
| 576 | (key, unihash) = self.unitaskhashes[key] |
| 577 | if key != checkkey: |
| 578 | return None |
| 579 | return unihash |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 580 | |
| 581 | def get_unihash(self, tid): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 582 | taskhash = self.taskhash[tid] |
| 583 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 584 | # If its not a setscene task we can return |
| 585 | if self.setscenetasks and tid not in self.setscenetasks: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 586 | self.unihash[tid] = None |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 587 | return taskhash |
| 588 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 589 | # TODO: This cache can grow unbounded. It probably only needs to keep |
| 590 | # for each task |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 591 | unihash = self._get_unihash(tid) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 592 | if unihash is not None: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 593 | self.unihash[tid] = unihash |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 594 | return unihash |
| 595 | |
| 596 | # In the absence of being able to discover a unique hash from the |
| 597 | # server, make it be equivalent to the taskhash. The unique "hash" only |
| 598 | # really needs to be a unique string (not even necessarily a hash), but |
| 599 | # making it match the taskhash has a few advantages: |
| 600 | # |
| 601 | # 1) All of the sstate code that assumes hashes can be the same |
| 602 | # 2) It provides maximal compatibility with builders that don't use |
| 603 | # an equivalency server |
| 604 | # 3) The value is easy for multiple independent builders to derive the |
| 605 | # same unique hash from the same input. This means that if the |
| 606 | # independent builders find the same taskhash, but it isn't reported |
| 607 | # to the server, there is a better chance that they will agree on |
| 608 | # the unique hash. |
| 609 | unihash = taskhash |
| 610 | |
| 611 | try: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 612 | method = self.method |
| 613 | if tid in self.extramethod: |
| 614 | method = method + self.extramethod[tid] |
| 615 | data = self.client().get_unihash(method, self.taskhash[tid]) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 616 | if data: |
| 617 | unihash = data |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 618 | # A unique hash equal to the taskhash is not very interesting, |
| 619 | # so it is reported it at debug level 2. If they differ, that |
| 620 | # is much more interesting, so it is reported at debug level 1 |
Andrew Geissler | 6aa7eec | 2023-03-03 12:41:14 -0600 | [diff] [blame] | 621 | hashequiv_logger.bbdebug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server)) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 622 | else: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 623 | hashequiv_logger.debug2('No reported unihash for %s:%s from %s' % (tid, taskhash, self.server)) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 624 | except ConnectionError as e: |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 625 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 626 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 627 | self.set_unihash(tid, unihash) |
| 628 | self.unihash[tid] = unihash |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 629 | return unihash |
| 630 | |
| 631 | def report_unihash(self, path, task, d): |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 632 | import importlib |
| 633 | |
| 634 | taskhash = d.getVar('BB_TASKHASH') |
| 635 | unihash = d.getVar('BB_UNIHASH') |
| 636 | report_taskdata = d.getVar('SSTATE_HASHEQUIV_REPORT_TASKDATA') == '1' |
| 637 | tempdir = d.getVar('T') |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 638 | mcfn = d.getVar('BB_FILENAME') |
| 639 | tid = mcfn + ':do_' + task |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 640 | key = tid + ':' + taskhash |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 641 | |
| 642 | if self.setscenetasks and tid not in self.setscenetasks: |
| 643 | return |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 644 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 645 | # This can happen if locked sigs are in action. Detect and just exit |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 646 | if taskhash != self.taskhash[tid]: |
| 647 | return |
| 648 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 649 | # Sanity checks |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 650 | cache_unihash = self._get_unihash(tid, checkkey=taskhash) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 651 | if cache_unihash is None: |
| 652 | bb.fatal('%s not in unihash cache. Please report this error' % key) |
| 653 | |
| 654 | if cache_unihash != unihash: |
| 655 | bb.fatal("Cache unihash %s doesn't match BB_UNIHASH %s" % (cache_unihash, unihash)) |
| 656 | |
| 657 | sigfile = None |
| 658 | sigfile_name = "depsig.do_%s.%d" % (task, os.getpid()) |
| 659 | sigfile_link = "depsig.do_%s" % task |
| 660 | |
| 661 | try: |
| 662 | sigfile = open(os.path.join(tempdir, sigfile_name), 'w+b') |
| 663 | |
| 664 | locs = {'path': path, 'sigfile': sigfile, 'task': task, 'd': d} |
| 665 | |
| 666 | if "." in self.method: |
| 667 | (module, method) = self.method.rsplit('.', 1) |
| 668 | locs['method'] = getattr(importlib.import_module(module), method) |
| 669 | outhash = bb.utils.better_eval('method(path, sigfile, task, d)', locs) |
| 670 | else: |
| 671 | outhash = bb.utils.better_eval(self.method + '(path, sigfile, task, d)', locs) |
| 672 | |
| 673 | try: |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 674 | extra_data = {} |
| 675 | |
| 676 | owner = d.getVar('SSTATE_HASHEQUIV_OWNER') |
| 677 | if owner: |
| 678 | extra_data['owner'] = owner |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 679 | |
| 680 | if report_taskdata: |
| 681 | sigfile.seek(0) |
| 682 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 683 | extra_data['PN'] = d.getVar('PN') |
| 684 | extra_data['PV'] = d.getVar('PV') |
| 685 | extra_data['PR'] = d.getVar('PR') |
| 686 | extra_data['task'] = task |
| 687 | extra_data['outhash_siginfo'] = sigfile.read().decode('utf-8') |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 688 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 689 | method = self.method |
| 690 | if tid in self.extramethod: |
| 691 | method = method + self.extramethod[tid] |
| 692 | |
| 693 | data = self.client().report_unihash(taskhash, method, outhash, unihash, extra_data) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 694 | new_unihash = data['unihash'] |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 695 | |
| 696 | if new_unihash != unihash: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 697 | hashequiv_logger.debug('Task %s unihash changed %s -> %s by server %s' % (taskhash, unihash, new_unihash, self.server)) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 698 | bb.event.fire(bb.runqueue.taskUniHashUpdate(mcfn + ':do_' + task, new_unihash), d) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 699 | self.set_unihash(tid, new_unihash) |
| 700 | d.setVar('BB_UNIHASH', new_unihash) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 701 | else: |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 702 | hashequiv_logger.debug('Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server)) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 703 | except ConnectionError as e: |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 704 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 705 | finally: |
| 706 | if sigfile: |
| 707 | sigfile.close() |
| 708 | |
| 709 | sigfile_link_path = os.path.join(tempdir, sigfile_link) |
| 710 | bb.utils.remove(sigfile_link_path) |
| 711 | |
| 712 | try: |
| 713 | os.symlink(sigfile_name, sigfile_link_path) |
| 714 | except OSError: |
| 715 | pass |
| 716 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 717 | def report_unihash_equiv(self, tid, taskhash, wanted_unihash, current_unihash, datacaches): |
| 718 | try: |
| 719 | extra_data = {} |
| 720 | method = self.method |
| 721 | if tid in self.extramethod: |
| 722 | method = method + self.extramethod[tid] |
| 723 | |
| 724 | data = self.client().report_unihash_equiv(taskhash, method, wanted_unihash, extra_data) |
| 725 | hashequiv_logger.verbose('Reported task %s as unihash %s to %s (%s)' % (tid, wanted_unihash, self.server, str(data))) |
| 726 | |
| 727 | if data is None: |
| 728 | bb.warn("Server unable to handle unihash report") |
| 729 | return False |
| 730 | |
| 731 | finalunihash = data['unihash'] |
| 732 | |
| 733 | if finalunihash == current_unihash: |
| 734 | hashequiv_logger.verbose('Task %s unihash %s unchanged by server' % (tid, finalunihash)) |
| 735 | elif finalunihash == wanted_unihash: |
| 736 | hashequiv_logger.verbose('Task %s unihash changed %s -> %s as wanted' % (tid, current_unihash, finalunihash)) |
| 737 | self.set_unihash(tid, finalunihash) |
| 738 | return True |
| 739 | else: |
| 740 | # TODO: What to do here? |
| 741 | hashequiv_logger.verbose('Task %s unihash reported as unwanted hash %s' % (tid, finalunihash)) |
| 742 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 743 | except ConnectionError as e: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 744 | bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e))) |
| 745 | |
| 746 | return False |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 747 | |
| 748 | # |
| 749 | # Dummy class used for bitbake-selftest |
| 750 | # |
| 751 | class SignatureGeneratorTestEquivHash(SignatureGeneratorUniHashMixIn, SignatureGeneratorBasicHash): |
| 752 | name = "TestEquivHash" |
| 753 | def init_rundepcheck(self, data): |
| 754 | super().init_rundepcheck(data) |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 755 | self.server = data.getVar('BB_HASHSERVE') |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 756 | self.method = "sstate_output_hash" |
| 757 | |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 758 | def clean_checksum_file_path(file_checksum_tuple): |
| 759 | f, cs = file_checksum_tuple |
| 760 | if "/./" in f: |
| 761 | return "./" + f.split("/./")[1] |
| 762 | return f |
| 763 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 764 | def dump_this_task(outfile, d): |
| 765 | import bb.parse |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 766 | mcfn = d.getVar("BB_FILENAME") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 767 | task = "do_" + d.getVar("BB_CURRENTTASK") |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 768 | referencestamp = bb.parse.siggen.stampfile_base(mcfn) |
| 769 | bb.parse.siggen.dump_sigtask(mcfn, task, outfile, "customfile:" + referencestamp) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 770 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 771 | def init_colors(enable_color): |
| 772 | """Initialise colour dict for passing to compare_sigfiles()""" |
| 773 | # First set up the colours |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 774 | colors = {'color_title': '\033[1m', |
| 775 | 'color_default': '\033[0m', |
| 776 | 'color_add': '\033[0;32m', |
| 777 | 'color_remove': '\033[0;31m', |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 778 | } |
| 779 | # Leave all keys present but clear the values |
| 780 | if not enable_color: |
| 781 | for k in colors.keys(): |
| 782 | colors[k] = '' |
| 783 | return colors |
| 784 | |
| 785 | def worddiff_str(oldstr, newstr, colors=None): |
| 786 | if not colors: |
| 787 | colors = init_colors(False) |
| 788 | diff = simplediff.diff(oldstr.split(' '), newstr.split(' ')) |
| 789 | ret = [] |
| 790 | for change, value in diff: |
| 791 | value = ' '.join(value) |
| 792 | if change == '=': |
| 793 | ret.append(value) |
| 794 | elif change == '+': |
| 795 | item = '{color_add}{{+{value}+}}{color_default}'.format(value=value, **colors) |
| 796 | ret.append(item) |
| 797 | elif change == '-': |
| 798 | item = '{color_remove}[-{value}-]{color_default}'.format(value=value, **colors) |
| 799 | ret.append(item) |
| 800 | whitespace_note = '' |
| 801 | if oldstr != newstr and ' '.join(oldstr.split()) == ' '.join(newstr.split()): |
| 802 | whitespace_note = ' (whitespace changed)' |
| 803 | return '"%s"%s' % (' '.join(ret), whitespace_note) |
| 804 | |
| 805 | def list_inline_diff(oldlist, newlist, colors=None): |
| 806 | if not colors: |
| 807 | colors = init_colors(False) |
| 808 | diff = simplediff.diff(oldlist, newlist) |
| 809 | ret = [] |
| 810 | for change, value in diff: |
| 811 | value = ' '.join(value) |
| 812 | if change == '=': |
| 813 | ret.append("'%s'" % value) |
| 814 | elif change == '+': |
| 815 | item = '{color_add}+{value}{color_default}'.format(value=value, **colors) |
| 816 | ret.append(item) |
| 817 | elif change == '-': |
| 818 | item = '{color_remove}-{value}{color_default}'.format(value=value, **colors) |
| 819 | ret.append(item) |
| 820 | return '[%s]' % (', '.join(ret)) |
| 821 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 822 | # Handled renamed fields |
| 823 | def handle_renames(data): |
| 824 | if 'basewhitelist' in data: |
| 825 | data['basehash_ignore_vars'] = data['basewhitelist'] |
| 826 | del data['basewhitelist'] |
| 827 | if 'taskwhitelist' in data: |
| 828 | data['taskhash_ignore_tasks'] = data['taskwhitelist'] |
| 829 | del data['taskwhitelist'] |
| 830 | |
| 831 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 832 | def compare_sigfiles(a, b, recursecb=None, color=False, collapsed=False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 833 | output = [] |
| 834 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 835 | colors = init_colors(color) |
| 836 | def color_format(formatstr, **values): |
| 837 | """ |
| 838 | Return colour formatted string. |
| 839 | NOTE: call with the format string, not an already formatted string |
| 840 | containing values (otherwise you could have trouble with { and } |
| 841 | characters) |
| 842 | """ |
| 843 | if not formatstr.endswith('{color_default}'): |
| 844 | formatstr += '{color_default}' |
| 845 | # In newer python 3 versions you can pass both of these directly, |
| 846 | # but we only require 3.4 at the moment |
| 847 | formatparams = {} |
| 848 | formatparams.update(colors) |
| 849 | formatparams.update(values) |
| 850 | return formatstr.format(**formatparams) |
| 851 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 852 | with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f: |
| 853 | a_data = json.load(f, object_hook=SetDecoder) |
| 854 | with bb.compress.zstd.open(b, "rt", encoding="utf-8", num_threads=1) as f: |
| 855 | b_data = json.load(f, object_hook=SetDecoder) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 856 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 857 | for data in [a_data, b_data]: |
| 858 | handle_renames(data) |
| 859 | |
| 860 | def dict_diff(a, b, ignored_vars=set()): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 861 | sa = set(a.keys()) |
| 862 | sb = set(b.keys()) |
| 863 | common = sa & sb |
| 864 | changed = set() |
| 865 | for i in common: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 866 | if a[i] != b[i] and i not in ignored_vars: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 867 | changed.add(i) |
| 868 | added = sb - sa |
| 869 | removed = sa - sb |
| 870 | return changed, added, removed |
| 871 | |
| 872 | def file_checksums_diff(a, b): |
| 873 | from collections import Counter |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 874 | |
| 875 | # Convert lists back to tuples |
| 876 | a = [(f[0], f[1]) for f in a] |
| 877 | b = [(f[0], f[1]) for f in b] |
| 878 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 879 | # Compare lists, ensuring we can handle duplicate filenames if they exist |
| 880 | removedcount = Counter(a) |
| 881 | removedcount.subtract(b) |
| 882 | addedcount = Counter(b) |
| 883 | addedcount.subtract(a) |
| 884 | added = [] |
| 885 | for x in b: |
| 886 | if addedcount[x] > 0: |
| 887 | addedcount[x] -= 1 |
| 888 | added.append(x) |
| 889 | removed = [] |
| 890 | changed = [] |
| 891 | for x in a: |
| 892 | if removedcount[x] > 0: |
| 893 | removedcount[x] -= 1 |
| 894 | for y in added: |
| 895 | if y[0] == x[0]: |
| 896 | changed.append((x[0], x[1], y[1])) |
| 897 | added.remove(y) |
| 898 | break |
| 899 | else: |
| 900 | removed.append(x) |
| 901 | added = [x[0] for x in added] |
| 902 | removed = [x[0] for x in removed] |
| 903 | return changed, added, removed |
| 904 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 905 | if 'basehash_ignore_vars' in a_data and a_data['basehash_ignore_vars'] != b_data['basehash_ignore_vars']: |
| 906 | output.append(color_format("{color_title}basehash_ignore_vars changed{color_default} from '%s' to '%s'") % (a_data['basehash_ignore_vars'], b_data['basehash_ignore_vars'])) |
| 907 | if a_data['basehash_ignore_vars'] and b_data['basehash_ignore_vars']: |
| 908 | output.append("changed items: %s" % a_data['basehash_ignore_vars'].symmetric_difference(b_data['basehash_ignore_vars'])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 909 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 910 | if 'taskhash_ignore_tasks' in a_data and a_data['taskhash_ignore_tasks'] != b_data['taskhash_ignore_tasks']: |
| 911 | output.append(color_format("{color_title}taskhash_ignore_tasks changed{color_default} from '%s' to '%s'") % (a_data['taskhash_ignore_tasks'], b_data['taskhash_ignore_tasks'])) |
| 912 | if a_data['taskhash_ignore_tasks'] and b_data['taskhash_ignore_tasks']: |
| 913 | output.append("changed items: %s" % a_data['taskhash_ignore_tasks'].symmetric_difference(b_data['taskhash_ignore_tasks'])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 914 | |
| 915 | if a_data['taskdeps'] != b_data['taskdeps']: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 916 | output.append(color_format("{color_title}Task dependencies changed{color_default} from:\n%s\nto:\n%s") % (sorted(a_data['taskdeps']), sorted(b_data['taskdeps']))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 917 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 918 | if a_data['basehash'] != b_data['basehash'] and not collapsed: |
| 919 | output.append(color_format("{color_title}basehash changed{color_default} from %s to %s") % (a_data['basehash'], b_data['basehash'])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 920 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 921 | changed, added, removed = dict_diff(a_data['gendeps'], b_data['gendeps'], a_data['basehash_ignore_vars'] & b_data['basehash_ignore_vars']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 922 | if changed: |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 923 | for dep in sorted(changed): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 924 | output.append(color_format("{color_title}List of dependencies for variable %s changed from '{color_default}%s{color_title}' to '{color_default}%s{color_title}'") % (dep, a_data['gendeps'][dep], b_data['gendeps'][dep])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 925 | if a_data['gendeps'][dep] and b_data['gendeps'][dep]: |
| 926 | output.append("changed items: %s" % a_data['gendeps'][dep].symmetric_difference(b_data['gendeps'][dep])) |
| 927 | if added: |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 928 | for dep in sorted(added): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 929 | output.append(color_format("{color_title}Dependency on variable %s was added") % (dep)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 930 | if removed: |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 931 | for dep in sorted(removed): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 932 | output.append(color_format("{color_title}Dependency on Variable %s was removed") % (dep)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 933 | |
| 934 | |
| 935 | changed, added, removed = dict_diff(a_data['varvals'], b_data['varvals']) |
| 936 | if changed: |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 937 | for dep in sorted(changed): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 938 | oldval = a_data['varvals'][dep] |
| 939 | newval = b_data['varvals'][dep] |
| 940 | if newval and oldval and ('\n' in oldval or '\n' in newval): |
| 941 | diff = difflib.unified_diff(oldval.splitlines(), newval.splitlines(), lineterm='') |
| 942 | # Cut off the first two lines, since we aren't interested in |
| 943 | # the old/new filename (they are blank anyway in this case) |
| 944 | difflines = list(diff)[2:] |
| 945 | if color: |
| 946 | # Add colour to diff output |
| 947 | for i, line in enumerate(difflines): |
| 948 | if line.startswith('+'): |
| 949 | line = color_format('{color_add}{line}', line=line) |
| 950 | difflines[i] = line |
| 951 | elif line.startswith('-'): |
| 952 | line = color_format('{color_remove}{line}', line=line) |
| 953 | difflines[i] = line |
| 954 | output.append(color_format("{color_title}Variable {var} value changed:{color_default}\n{diff}", var=dep, diff='\n'.join(difflines))) |
| 955 | elif newval and oldval and (' ' in oldval or ' ' in newval): |
| 956 | output.append(color_format("{color_title}Variable {var} value changed:{color_default}\n{diff}", var=dep, diff=worddiff_str(oldval, newval, colors))) |
| 957 | else: |
| 958 | output.append(color_format("{color_title}Variable {var} value changed from '{color_default}{oldval}{color_title}' to '{color_default}{newval}{color_title}'{color_default}", var=dep, oldval=oldval, newval=newval)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 959 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 960 | if not 'file_checksum_values' in a_data: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 961 | a_data['file_checksum_values'] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 962 | if not 'file_checksum_values' in b_data: |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 963 | b_data['file_checksum_values'] = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 964 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 965 | changed, added, removed = file_checksums_diff(a_data['file_checksum_values'], b_data['file_checksum_values']) |
| 966 | if changed: |
| 967 | for f, old, new in changed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 968 | output.append(color_format("{color_title}Checksum for file %s changed{color_default} from %s to %s") % (f, old, new)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 969 | if added: |
| 970 | for f in added: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 971 | output.append(color_format("{color_title}Dependency on checksum of file %s was added") % (f)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 972 | if removed: |
| 973 | for f in removed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 974 | output.append(color_format("{color_title}Dependency on checksum of file %s was removed") % (f)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 975 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 976 | if not 'runtaskdeps' in a_data: |
| 977 | a_data['runtaskdeps'] = {} |
| 978 | if not 'runtaskdeps' in b_data: |
| 979 | b_data['runtaskdeps'] = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 980 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 981 | if not collapsed: |
| 982 | if len(a_data['runtaskdeps']) != len(b_data['runtaskdeps']): |
| 983 | changed = ["Number of task dependencies changed"] |
| 984 | else: |
| 985 | changed = [] |
| 986 | for idx, task in enumerate(a_data['runtaskdeps']): |
| 987 | a = a_data['runtaskdeps'][idx] |
| 988 | b = b_data['runtaskdeps'][idx] |
| 989 | if a_data['runtaskhashes'][a] != b_data['runtaskhashes'][b] and not collapsed: |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 990 | changed.append("%s with hash %s\n changed to\n%s with hash %s" % (a, a_data['runtaskhashes'][a], b, b_data['runtaskhashes'][b])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 991 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 992 | if changed: |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 993 | clean_a = a_data['runtaskdeps'] |
| 994 | clean_b = b_data['runtaskdeps'] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 995 | if clean_a != clean_b: |
| 996 | output.append(color_format("{color_title}runtaskdeps changed:{color_default}\n%s") % list_inline_diff(clean_a, clean_b, colors)) |
| 997 | else: |
| 998 | output.append(color_format("{color_title}runtaskdeps changed:")) |
| 999 | output.append("\n".join(changed)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1000 | |
| 1001 | |
| 1002 | if 'runtaskhashes' in a_data and 'runtaskhashes' in b_data: |
Patrick Williams | 2a25492 | 2023-08-11 09:48:11 -0500 | [diff] [blame] | 1003 | a = a_data['runtaskhashes'] |
| 1004 | b = b_data['runtaskhashes'] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1005 | changed, added, removed = dict_diff(a, b) |
| 1006 | if added: |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 1007 | for dep in sorted(added): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1008 | bdep_found = False |
| 1009 | if removed: |
| 1010 | for bdep in removed: |
| 1011 | if b[dep] == a[bdep]: |
| 1012 | #output.append("Dependency on task %s was replaced by %s with same hash" % (dep, bdep)) |
| 1013 | bdep_found = True |
| 1014 | if not bdep_found: |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 1015 | output.append(color_format("{color_title}Dependency on task %s was added{color_default} with hash %s") % (dep, b[dep])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1016 | if removed: |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 1017 | for dep in sorted(removed): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1018 | adep_found = False |
| 1019 | if added: |
| 1020 | for adep in added: |
| 1021 | if b[adep] == a[dep]: |
| 1022 | #output.append("Dependency on task %s was replaced by %s with same hash" % (adep, dep)) |
| 1023 | adep_found = True |
| 1024 | if not adep_found: |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 1025 | output.append(color_format("{color_title}Dependency on task %s was removed{color_default} with hash %s") % (dep, a[dep])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1026 | if changed: |
Patrick Williams | 93c203f | 2021-10-06 16:15:23 -0500 | [diff] [blame] | 1027 | for dep in sorted(changed): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1028 | if not collapsed: |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 1029 | output.append(color_format("{color_title}Hash for task dependency %s changed{color_default} from %s to %s") % (dep, a[dep], b[dep])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1030 | if callable(recursecb): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1031 | recout = recursecb(dep, a[dep], b[dep]) |
| 1032 | if recout: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1033 | if collapsed: |
| 1034 | output.extend(recout) |
| 1035 | else: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1036 | # If a dependent hash changed, might as well print the line above and then defer to the changes in |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1037 | # that hash since in all likelyhood, they're the same changes this task also saw. |
| 1038 | output = [output[-1]] + recout |
Andrew Geissler | d583833 | 2022-05-27 11:33:10 -0500 | [diff] [blame] | 1039 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1040 | |
| 1041 | a_taint = a_data.get('taint', None) |
| 1042 | b_taint = b_data.get('taint', None) |
| 1043 | if a_taint != b_taint: |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1044 | if a_taint and a_taint.startswith('nostamp:'): |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1045 | a_taint = a_taint.replace('nostamp:', 'nostamp(uuid4):') |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1046 | if b_taint and b_taint.startswith('nostamp:'): |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1047 | b_taint = b_taint.replace('nostamp:', 'nostamp(uuid4):') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1048 | output.append(color_format("{color_title}Taint (by forced/invalidated task) changed{color_default} from %s to %s") % (a_taint, b_taint)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1049 | |
| 1050 | return output |
| 1051 | |
| 1052 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1053 | def calc_basehash(sigdata): |
| 1054 | task = sigdata['task'] |
| 1055 | basedata = sigdata['varvals'][task] |
| 1056 | |
| 1057 | if basedata is None: |
| 1058 | basedata = '' |
| 1059 | |
| 1060 | alldeps = sigdata['taskdeps'] |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1061 | for dep in sorted(alldeps): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1062 | basedata = basedata + dep |
| 1063 | val = sigdata['varvals'][dep] |
| 1064 | if val is not None: |
| 1065 | basedata = basedata + str(val) |
| 1066 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1067 | return hashlib.sha256(basedata.encode("utf-8")).hexdigest() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1068 | |
| 1069 | def calc_taskhash(sigdata): |
| 1070 | data = sigdata['basehash'] |
| 1071 | |
| 1072 | for dep in sigdata['runtaskdeps']: |
| 1073 | data = data + sigdata['runtaskhashes'][dep] |
| 1074 | |
| 1075 | for c in sigdata['file_checksum_values']: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1076 | if c[1]: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1077 | if "./" in c[0]: |
| 1078 | data = data + c[0] |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 1079 | data = data + c[1] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1080 | |
| 1081 | if 'taint' in sigdata: |
| 1082 | if 'nostamp:' in sigdata['taint']: |
| 1083 | data = data + sigdata['taint'][8:] |
| 1084 | else: |
| 1085 | data = data + sigdata['taint'] |
| 1086 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1087 | return hashlib.sha256(data.encode("utf-8")).hexdigest() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1088 | |
| 1089 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1090 | def dump_sigfile(a): |
| 1091 | output = [] |
| 1092 | |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 1093 | with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f: |
| 1094 | a_data = json.load(f, object_hook=SetDecoder) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1095 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1096 | handle_renames(a_data) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1097 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1098 | output.append("basehash_ignore_vars: %s" % (sorted(a_data['basehash_ignore_vars']))) |
| 1099 | |
| 1100 | output.append("taskhash_ignore_tasks: %s" % (sorted(a_data['taskhash_ignore_tasks'] or []))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1101 | |
| 1102 | output.append("Task dependencies: %s" % (sorted(a_data['taskdeps']))) |
| 1103 | |
| 1104 | output.append("basehash: %s" % (a_data['basehash'])) |
| 1105 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1106 | for dep in sorted(a_data['gendeps']): |
| 1107 | output.append("List of dependencies for variable %s is %s" % (dep, sorted(a_data['gendeps'][dep]))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1108 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1109 | for dep in sorted(a_data['varvals']): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1110 | output.append("Variable %s value is %s" % (dep, a_data['varvals'][dep])) |
| 1111 | |
| 1112 | if 'runtaskdeps' in a_data: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1113 | output.append("Tasks this task depends on: %s" % (sorted(a_data['runtaskdeps']))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1114 | |
| 1115 | if 'file_checksum_values' in a_data: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1116 | output.append("This task depends on the checksums of files: %s" % (sorted(a_data['file_checksum_values']))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1117 | |
| 1118 | if 'runtaskhashes' in a_data: |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1119 | for dep in sorted(a_data['runtaskhashes']): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1120 | output.append("Hash for dependent task %s is %s" % (dep, a_data['runtaskhashes'][dep])) |
| 1121 | |
| 1122 | if 'taint' in a_data: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1123 | if a_data['taint'].startswith('nostamp:'): |
| 1124 | msg = a_data['taint'].replace('nostamp:', 'nostamp(uuid4):') |
| 1125 | else: |
| 1126 | msg = a_data['taint'] |
| 1127 | output.append("Tainted (by forced/invalidated task): %s" % msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1128 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1129 | if 'task' in a_data: |
| 1130 | computed_basehash = calc_basehash(a_data) |
| 1131 | output.append("Computed base hash is %s and from file %s" % (computed_basehash, a_data['basehash'])) |
| 1132 | else: |
| 1133 | output.append("Unable to compute base hash") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1134 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1135 | computed_taskhash = calc_taskhash(a_data) |
| 1136 | output.append("Computed task hash is %s" % computed_taskhash) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1137 | |
| 1138 | return output |