Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: GPL-2.0-only |
| 3 | # |
| 4 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | import hashlib |
| 6 | import logging |
| 7 | import os |
| 8 | import re |
| 9 | import tempfile |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 10 | import pickle |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | import bb.data |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | import difflib |
| 13 | import simplediff |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 14 | from bb.checksum import FileChecksumCache |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | |
| 16 | logger = logging.getLogger('BitBake.SigGen') |
| 17 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | def init(d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | siggens = [obj for obj in globals().values() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | if type(obj) is type and issubclass(obj, SignatureGenerator)] |
| 21 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 22 | desired = d.getVar("BB_SIGNATURE_HANDLER") or "noop" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 23 | for sg in siggens: |
| 24 | if desired == sg.name: |
| 25 | return sg(d) |
| 26 | break |
| 27 | else: |
| 28 | logger.error("Invalid signature generator '%s', using default 'noop'\n" |
| 29 | "Available generators: %s", desired, |
| 30 | ', '.join(obj.name for obj in siggens)) |
| 31 | return SignatureGenerator(d) |
| 32 | |
| 33 | class SignatureGenerator(object): |
| 34 | """ |
| 35 | """ |
| 36 | name = "noop" |
| 37 | |
| 38 | def __init__(self, data): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 39 | self.basehash = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | self.taskhash = {} |
| 41 | self.runtaskdeps = {} |
| 42 | self.file_checksum_values = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 43 | self.taints = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | |
| 45 | def finalise(self, fn, d, varient): |
| 46 | return |
| 47 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | def get_unihash(self, task): |
| 49 | return self.taskhash[task] |
| 50 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | def get_taskhash(self, fn, task, deps, dataCache): |
| 52 | return "0" |
| 53 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 54 | def writeout_file_checksum_cache(self): |
| 55 | """Write/update the file checksum cache onto disk""" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | return |
| 57 | |
| 58 | def stampfile(self, stampbase, file_name, taskname, extrainfo): |
| 59 | return ("%s.%s.%s" % (stampbase, taskname, extrainfo)).rstrip('.') |
| 60 | |
| 61 | def stampcleanmask(self, stampbase, file_name, taskname, extrainfo): |
| 62 | return ("%s.%s.%s" % (stampbase, taskname, extrainfo)).rstrip('.') |
| 63 | |
| 64 | def dump_sigtask(self, fn, task, stampbase, runtime): |
| 65 | return |
| 66 | |
| 67 | def invalidate_task(self, task, d, fn): |
| 68 | bb.build.del_stamp(task, d, fn) |
| 69 | |
| 70 | def dump_sigs(self, dataCache, options): |
| 71 | return |
| 72 | |
| 73 | def get_taskdata(self): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 74 | return (self.runtaskdeps, self.taskhash, self.file_checksum_values, self.taints, self.basehash) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | |
| 76 | def set_taskdata(self, data): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 77 | self.runtaskdeps, self.taskhash, self.file_checksum_values, self.taints, self.basehash = data |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 79 | def reset(self, data): |
| 80 | self.__init__(data) |
| 81 | |
| 82 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | class SignatureGeneratorBasic(SignatureGenerator): |
| 84 | """ |
| 85 | """ |
| 86 | name = "basic" |
| 87 | |
| 88 | def __init__(self, data): |
| 89 | self.basehash = {} |
| 90 | self.taskhash = {} |
| 91 | self.taskdeps = {} |
| 92 | self.runtaskdeps = {} |
| 93 | self.file_checksum_values = {} |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 94 | self.taints = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | self.gendeps = {} |
| 96 | self.lookupcache = {} |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 97 | self.pkgnameextract = re.compile(r"(?P<fn>.*)\..*") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 98 | self.basewhitelist = set((data.getVar("BB_HASHBASE_WHITELIST") or "").split()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 99 | self.taskwhitelist = None |
| 100 | self.init_rundepcheck(data) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 101 | checksum_cache_file = data.getVar("BB_HASH_CHECKSUM_CACHE_FILE") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 102 | if checksum_cache_file: |
| 103 | self.checksum_cache = FileChecksumCache() |
| 104 | self.checksum_cache.init_cache(data, checksum_cache_file) |
| 105 | else: |
| 106 | self.checksum_cache = None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | |
| 108 | def init_rundepcheck(self, data): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 109 | self.taskwhitelist = data.getVar("BB_HASHTASK_WHITELIST") or None |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | if self.taskwhitelist: |
| 111 | self.twl = re.compile(self.taskwhitelist) |
| 112 | else: |
| 113 | self.twl = None |
| 114 | |
| 115 | def _build_data(self, fn, d): |
| 116 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 117 | ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') == '1') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 118 | tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d) |
| 119 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 120 | taskdeps, basehash = bb.data.generate_dependency_hash(tasklist, gendeps, lookupcache, self.basewhitelist, fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | |
| 122 | for task in tasklist: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 123 | k = fn + "." + task |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 124 | if not ignore_mismatch and k in self.basehash and self.basehash[k] != basehash[k]: |
| 125 | bb.error("When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed." % (k, self.basehash[k], basehash[k])) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 126 | bb.error("The following commands may help:") |
| 127 | cmd = "$ bitbake %s -c%s" % (d.getVar('PN'), task) |
| 128 | # Make sure sigdata is dumped before run printdiff |
| 129 | bb.error("%s -Snone" % cmd) |
| 130 | bb.error("Then:") |
| 131 | bb.error("%s -Sprintdiff\n" % cmd) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 132 | self.basehash[k] = basehash[k] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | |
| 134 | self.taskdeps[fn] = taskdeps |
| 135 | self.gendeps[fn] = gendeps |
| 136 | self.lookupcache[fn] = lookupcache |
| 137 | |
| 138 | return taskdeps |
| 139 | |
| 140 | def finalise(self, fn, d, variant): |
| 141 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 142 | mc = d.getVar("__BBMULTICONFIG", False) or "" |
| 143 | if variant or mc: |
| 144 | fn = bb.cache.realfn2virtual(fn, variant, mc) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | |
| 146 | try: |
| 147 | taskdeps = self._build_data(fn, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 148 | except bb.parse.SkipRecipe: |
| 149 | raise |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | except: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 151 | bb.warn("Error during finalise of %s" % fn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 152 | raise |
| 153 | |
| 154 | #Slow but can be useful for debugging mismatched basehashes |
| 155 | #for task in self.taskdeps[fn]: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 156 | # self.dump_sigtask(fn, task, d.getVar("STAMP"), False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 157 | |
| 158 | for task in taskdeps: |
| 159 | d.setVar("BB_BASEHASH_task-%s" % task, self.basehash[fn + "." + task]) |
| 160 | |
| 161 | def rundep_check(self, fn, recipename, task, dep, depname, dataCache): |
| 162 | # Return True if we should keep the dependency, False to drop it |
| 163 | # We only manipulate the dependencies for packages not in the whitelist |
| 164 | if self.twl and not self.twl.search(recipename): |
| 165 | # then process the actual dependencies |
| 166 | if self.twl.search(depname): |
| 167 | return False |
| 168 | return True |
| 169 | |
| 170 | def read_taint(self, fn, task, stampbase): |
| 171 | taint = None |
| 172 | try: |
| 173 | with open(stampbase + '.' + task + '.taint', 'r') as taintf: |
| 174 | taint = taintf.read() |
| 175 | except IOError: |
| 176 | pass |
| 177 | return taint |
| 178 | |
| 179 | def get_taskhash(self, fn, task, deps, dataCache): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 180 | |
| 181 | mc = '' |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 182 | if fn.startswith('mc:'): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 183 | mc = fn.split(':')[1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | k = fn + "." + task |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 185 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 186 | data = dataCache.basetaskhash[k] |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 187 | self.basehash[k] = data |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 188 | self.runtaskdeps[k] = [] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 189 | self.file_checksum_values[k] = [] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 190 | recipename = dataCache.pkg_fn[fn] |
| 191 | for dep in sorted(deps, key=clean_basepath): |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 192 | pkgname = self.pkgnameextract.search(dep).group('fn') |
| 193 | if mc: |
| 194 | depmc = pkgname.split(':')[1] |
| 195 | if mc != depmc: |
| 196 | continue |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 197 | if dep.startswith("mc:") and not mc: |
Andrew Geissler | 99467da | 2019-02-25 18:54:23 -0600 | [diff] [blame] | 198 | continue |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 199 | depname = dataCache.pkg_fn[pkgname] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | if not self.rundep_check(fn, recipename, task, dep, depname, dataCache): |
| 201 | continue |
| 202 | if dep not in self.taskhash: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 203 | bb.fatal("%s is not in taskhash, caller isn't calling in dependency order?" % dep) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 204 | data = data + self.get_unihash(dep) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 205 | self.runtaskdeps[k].append(dep) |
| 206 | |
| 207 | if task in dataCache.file_checksums[fn]: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 208 | if self.checksum_cache: |
| 209 | checksums = self.checksum_cache.get_checksums(dataCache.file_checksums[fn][task], recipename) |
| 210 | else: |
| 211 | checksums = bb.fetch2.get_file_checksums(dataCache.file_checksums[fn][task], recipename) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 212 | for (f,cs) in checksums: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 213 | self.file_checksum_values[k].append((f,cs)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | if cs: |
| 215 | data = data + cs |
| 216 | |
| 217 | taskdep = dataCache.task_deps[fn] |
| 218 | if 'nostamp' in taskdep and task in taskdep['nostamp']: |
| 219 | # Nostamp tasks need an implicit taint so that they force any dependent tasks to run |
| 220 | import uuid |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 221 | taint = str(uuid.uuid4()) |
| 222 | data = data + taint |
| 223 | self.taints[k] = "nostamp:" + taint |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | |
| 225 | taint = self.read_taint(fn, task, dataCache.stamp[fn]) |
| 226 | if taint: |
| 227 | data = data + taint |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 228 | self.taints[k] = taint |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 229 | logger.warning("%s is tainted from a forced run" % k) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 231 | h = hashlib.sha256(data.encode("utf-8")).hexdigest() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | self.taskhash[k] = h |
| 233 | #d.setVar("BB_TASKHASH_task-%s" % task, taskhash[task]) |
| 234 | return h |
| 235 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 236 | def writeout_file_checksum_cache(self): |
| 237 | """Write/update the file checksum cache onto disk""" |
| 238 | if self.checksum_cache: |
| 239 | self.checksum_cache.save_extras() |
| 240 | self.checksum_cache.save_merge() |
| 241 | else: |
| 242 | bb.fetch2.fetcher_parse_save() |
| 243 | bb.fetch2.fetcher_parse_done() |
| 244 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 245 | def dump_sigtask(self, fn, task, stampbase, runtime): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 246 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 247 | k = fn + "." + task |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 248 | referencestamp = stampbase |
| 249 | if isinstance(runtime, str) and runtime.startswith("customfile"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 250 | sigfile = stampbase |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 251 | referencestamp = runtime[11:] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | elif runtime and k in self.taskhash: |
| 253 | sigfile = stampbase + "." + task + ".sigdata" + "." + self.taskhash[k] |
| 254 | else: |
| 255 | sigfile = stampbase + "." + task + ".sigbasedata" + "." + self.basehash[k] |
| 256 | |
| 257 | bb.utils.mkdirhier(os.path.dirname(sigfile)) |
| 258 | |
| 259 | data = {} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 260 | data['task'] = task |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 261 | data['basewhitelist'] = self.basewhitelist |
| 262 | data['taskwhitelist'] = self.taskwhitelist |
| 263 | data['taskdeps'] = self.taskdeps[fn][task] |
| 264 | data['basehash'] = self.basehash[k] |
| 265 | data['gendeps'] = {} |
| 266 | data['varvals'] = {} |
| 267 | data['varvals'][task] = self.lookupcache[fn][task] |
| 268 | for dep in self.taskdeps[fn][task]: |
| 269 | if dep in self.basewhitelist: |
| 270 | continue |
| 271 | data['gendeps'][dep] = self.gendeps[fn][dep] |
| 272 | data['varvals'][dep] = self.lookupcache[fn][dep] |
| 273 | |
| 274 | if runtime and k in self.taskhash: |
| 275 | data['runtaskdeps'] = self.runtaskdeps[k] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 276 | data['file_checksum_values'] = [(os.path.basename(f), cs) for f,cs in self.file_checksum_values[k]] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 277 | data['runtaskhashes'] = {} |
| 278 | for dep in data['runtaskdeps']: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 279 | data['runtaskhashes'][dep] = self.get_unihash(dep) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 280 | data['taskhash'] = self.taskhash[k] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 282 | taint = self.read_taint(fn, task, referencestamp) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 283 | if taint: |
| 284 | data['taint'] = taint |
| 285 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 286 | if runtime and k in self.taints: |
| 287 | if 'nostamp:' in self.taints[k]: |
| 288 | data['taint'] = self.taints[k] |
| 289 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 290 | computed_basehash = calc_basehash(data) |
| 291 | if computed_basehash != self.basehash[k]: |
| 292 | bb.error("Basehash mismatch %s versus %s for %s" % (computed_basehash, self.basehash[k], k)) |
| 293 | if runtime and k in self.taskhash: |
| 294 | computed_taskhash = calc_taskhash(data) |
| 295 | if computed_taskhash != self.taskhash[k]: |
| 296 | bb.error("Taskhash mismatch %s versus %s for %s" % (computed_taskhash, self.taskhash[k], k)) |
| 297 | sigfile = sigfile.replace(self.taskhash[k], computed_taskhash) |
| 298 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 299 | fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.") |
| 300 | try: |
| 301 | with os.fdopen(fd, "wb") as stream: |
| 302 | p = pickle.dump(data, stream, -1) |
| 303 | stream.flush() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 304 | os.chmod(tmpfile, 0o664) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 305 | os.rename(tmpfile, sigfile) |
| 306 | except (OSError, IOError) as err: |
| 307 | try: |
| 308 | os.unlink(tmpfile) |
| 309 | except OSError: |
| 310 | pass |
| 311 | raise err |
| 312 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 313 | def dump_sigfn(self, fn, dataCaches, options): |
| 314 | if fn in self.taskdeps: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 315 | for task in self.taskdeps[fn]: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 316 | tid = fn + ":" + task |
| 317 | (mc, _, _) = bb.runqueue.split_tid(tid) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | k = fn + "." + task |
| 319 | if k not in self.taskhash: |
| 320 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 321 | if dataCaches[mc].basetaskhash[k] != self.basehash[k]: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 322 | bb.error("Bitbake's cached basehash does not match the one we just generated (%s)!" % k) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 323 | bb.error("The mismatched hashes were %s and %s" % (dataCaches[mc].basetaskhash[k], self.basehash[k])) |
| 324 | self.dump_sigtask(fn, task, dataCaches[mc].stamp[fn], True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 325 | |
| 326 | class SignatureGeneratorBasicHash(SignatureGeneratorBasic): |
| 327 | name = "basichash" |
| 328 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 329 | def get_stampfile_hash(self, task): |
| 330 | if task in self.taskhash: |
| 331 | return self.taskhash[task] |
| 332 | |
| 333 | # If task is not in basehash, then error |
| 334 | return self.basehash[task] |
| 335 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 336 | def stampfile(self, stampbase, fn, taskname, extrainfo, clean=False): |
| 337 | if taskname != "do_setscene" and taskname.endswith("_setscene"): |
| 338 | k = fn + "." + taskname[:-9] |
| 339 | else: |
| 340 | k = fn + "." + taskname |
| 341 | if clean: |
| 342 | h = "*" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 343 | else: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 344 | h = self.get_stampfile_hash(k) |
| 345 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 346 | return ("%s.%s.%s.%s" % (stampbase, taskname, h, extrainfo)).rstrip('.') |
| 347 | |
| 348 | def stampcleanmask(self, stampbase, fn, taskname, extrainfo): |
| 349 | return self.stampfile(stampbase, fn, taskname, extrainfo, clean=True) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 350 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | def invalidate_task(self, task, d, fn): |
| 352 | bb.note("Tainting hash to force rebuild of task %s, %s" % (fn, task)) |
| 353 | bb.build.write_taint(task, d, fn) |
| 354 | |
| 355 | def dump_this_task(outfile, d): |
| 356 | import bb.parse |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 357 | fn = d.getVar("BB_FILENAME") |
| 358 | task = "do_" + d.getVar("BB_CURRENTTASK") |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 359 | referencestamp = bb.build.stamp_internal(task, d, None, True) |
| 360 | bb.parse.siggen.dump_sigtask(fn, task, outfile, "customfile:" + referencestamp) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 361 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 362 | def init_colors(enable_color): |
| 363 | """Initialise colour dict for passing to compare_sigfiles()""" |
| 364 | # First set up the colours |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 365 | colors = {'color_title': '\033[1m', |
| 366 | 'color_default': '\033[0m', |
| 367 | 'color_add': '\033[0;32m', |
| 368 | 'color_remove': '\033[0;31m', |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 369 | } |
| 370 | # Leave all keys present but clear the values |
| 371 | if not enable_color: |
| 372 | for k in colors.keys(): |
| 373 | colors[k] = '' |
| 374 | return colors |
| 375 | |
| 376 | def worddiff_str(oldstr, newstr, colors=None): |
| 377 | if not colors: |
| 378 | colors = init_colors(False) |
| 379 | diff = simplediff.diff(oldstr.split(' '), newstr.split(' ')) |
| 380 | ret = [] |
| 381 | for change, value in diff: |
| 382 | value = ' '.join(value) |
| 383 | if change == '=': |
| 384 | ret.append(value) |
| 385 | elif change == '+': |
| 386 | item = '{color_add}{{+{value}+}}{color_default}'.format(value=value, **colors) |
| 387 | ret.append(item) |
| 388 | elif change == '-': |
| 389 | item = '{color_remove}[-{value}-]{color_default}'.format(value=value, **colors) |
| 390 | ret.append(item) |
| 391 | whitespace_note = '' |
| 392 | if oldstr != newstr and ' '.join(oldstr.split()) == ' '.join(newstr.split()): |
| 393 | whitespace_note = ' (whitespace changed)' |
| 394 | return '"%s"%s' % (' '.join(ret), whitespace_note) |
| 395 | |
| 396 | def list_inline_diff(oldlist, newlist, colors=None): |
| 397 | if not colors: |
| 398 | colors = init_colors(False) |
| 399 | diff = simplediff.diff(oldlist, newlist) |
| 400 | ret = [] |
| 401 | for change, value in diff: |
| 402 | value = ' '.join(value) |
| 403 | if change == '=': |
| 404 | ret.append("'%s'" % value) |
| 405 | elif change == '+': |
| 406 | item = '{color_add}+{value}{color_default}'.format(value=value, **colors) |
| 407 | ret.append(item) |
| 408 | elif change == '-': |
| 409 | item = '{color_remove}-{value}{color_default}'.format(value=value, **colors) |
| 410 | ret.append(item) |
| 411 | return '[%s]' % (', '.join(ret)) |
| 412 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 413 | def clean_basepath(a): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 414 | mc = None |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 415 | if a.startswith("mc:"): |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 416 | _, mc, a = a.split(":", 2) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 417 | b = a.rsplit("/", 2)[1] + '/' + a.rsplit("/", 2)[2] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 418 | if a.startswith("virtual:"): |
| 419 | b = b + ":" + a.rsplit(":", 1)[0] |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 420 | if mc: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 421 | b = b + ":mc:" + mc |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 422 | return b |
| 423 | |
| 424 | def clean_basepaths(a): |
| 425 | b = {} |
| 426 | for x in a: |
| 427 | b[clean_basepath(x)] = a[x] |
| 428 | return b |
| 429 | |
| 430 | def clean_basepaths_list(a): |
| 431 | b = [] |
| 432 | for x in a: |
| 433 | b.append(clean_basepath(x)) |
| 434 | return b |
| 435 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 436 | def compare_sigfiles(a, b, recursecb=None, color=False, collapsed=False): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 437 | output = [] |
| 438 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 439 | colors = init_colors(color) |
| 440 | def color_format(formatstr, **values): |
| 441 | """ |
| 442 | Return colour formatted string. |
| 443 | NOTE: call with the format string, not an already formatted string |
| 444 | containing values (otherwise you could have trouble with { and } |
| 445 | characters) |
| 446 | """ |
| 447 | if not formatstr.endswith('{color_default}'): |
| 448 | formatstr += '{color_default}' |
| 449 | # In newer python 3 versions you can pass both of these directly, |
| 450 | # but we only require 3.4 at the moment |
| 451 | formatparams = {} |
| 452 | formatparams.update(colors) |
| 453 | formatparams.update(values) |
| 454 | return formatstr.format(**formatparams) |
| 455 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 456 | with open(a, 'rb') as f: |
| 457 | p1 = pickle.Unpickler(f) |
| 458 | a_data = p1.load() |
| 459 | with open(b, 'rb') as f: |
| 460 | p2 = pickle.Unpickler(f) |
| 461 | b_data = p2.load() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 462 | |
| 463 | def dict_diff(a, b, whitelist=set()): |
| 464 | sa = set(a.keys()) |
| 465 | sb = set(b.keys()) |
| 466 | common = sa & sb |
| 467 | changed = set() |
| 468 | for i in common: |
| 469 | if a[i] != b[i] and i not in whitelist: |
| 470 | changed.add(i) |
| 471 | added = sb - sa |
| 472 | removed = sa - sb |
| 473 | return changed, added, removed |
| 474 | |
| 475 | def file_checksums_diff(a, b): |
| 476 | from collections import Counter |
| 477 | # Handle old siginfo format |
| 478 | if isinstance(a, dict): |
| 479 | a = [(os.path.basename(f), cs) for f, cs in a.items()] |
| 480 | if isinstance(b, dict): |
| 481 | b = [(os.path.basename(f), cs) for f, cs in b.items()] |
| 482 | # Compare lists, ensuring we can handle duplicate filenames if they exist |
| 483 | removedcount = Counter(a) |
| 484 | removedcount.subtract(b) |
| 485 | addedcount = Counter(b) |
| 486 | addedcount.subtract(a) |
| 487 | added = [] |
| 488 | for x in b: |
| 489 | if addedcount[x] > 0: |
| 490 | addedcount[x] -= 1 |
| 491 | added.append(x) |
| 492 | removed = [] |
| 493 | changed = [] |
| 494 | for x in a: |
| 495 | if removedcount[x] > 0: |
| 496 | removedcount[x] -= 1 |
| 497 | for y in added: |
| 498 | if y[0] == x[0]: |
| 499 | changed.append((x[0], x[1], y[1])) |
| 500 | added.remove(y) |
| 501 | break |
| 502 | else: |
| 503 | removed.append(x) |
| 504 | added = [x[0] for x in added] |
| 505 | removed = [x[0] for x in removed] |
| 506 | return changed, added, removed |
| 507 | |
| 508 | if 'basewhitelist' in a_data and a_data['basewhitelist'] != b_data['basewhitelist']: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 509 | output.append(color_format("{color_title}basewhitelist changed{color_default} from '%s' to '%s'") % (a_data['basewhitelist'], b_data['basewhitelist'])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 510 | if a_data['basewhitelist'] and b_data['basewhitelist']: |
| 511 | output.append("changed items: %s" % a_data['basewhitelist'].symmetric_difference(b_data['basewhitelist'])) |
| 512 | |
| 513 | if 'taskwhitelist' in a_data and a_data['taskwhitelist'] != b_data['taskwhitelist']: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 514 | output.append(color_format("{color_title}taskwhitelist changed{color_default} from '%s' to '%s'") % (a_data['taskwhitelist'], b_data['taskwhitelist'])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 515 | if a_data['taskwhitelist'] and b_data['taskwhitelist']: |
| 516 | output.append("changed items: %s" % a_data['taskwhitelist'].symmetric_difference(b_data['taskwhitelist'])) |
| 517 | |
| 518 | if a_data['taskdeps'] != b_data['taskdeps']: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 519 | 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] | 520 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 521 | if a_data['basehash'] != b_data['basehash'] and not collapsed: |
| 522 | 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] | 523 | |
| 524 | changed, added, removed = dict_diff(a_data['gendeps'], b_data['gendeps'], a_data['basewhitelist'] & b_data['basewhitelist']) |
| 525 | if changed: |
| 526 | for dep in changed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 527 | 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] | 528 | if a_data['gendeps'][dep] and b_data['gendeps'][dep]: |
| 529 | output.append("changed items: %s" % a_data['gendeps'][dep].symmetric_difference(b_data['gendeps'][dep])) |
| 530 | if added: |
| 531 | for dep in added: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 532 | 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] | 533 | if removed: |
| 534 | for dep in removed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 535 | 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] | 536 | |
| 537 | |
| 538 | changed, added, removed = dict_diff(a_data['varvals'], b_data['varvals']) |
| 539 | if changed: |
| 540 | for dep in changed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 541 | oldval = a_data['varvals'][dep] |
| 542 | newval = b_data['varvals'][dep] |
| 543 | if newval and oldval and ('\n' in oldval or '\n' in newval): |
| 544 | diff = difflib.unified_diff(oldval.splitlines(), newval.splitlines(), lineterm='') |
| 545 | # Cut off the first two lines, since we aren't interested in |
| 546 | # the old/new filename (they are blank anyway in this case) |
| 547 | difflines = list(diff)[2:] |
| 548 | if color: |
| 549 | # Add colour to diff output |
| 550 | for i, line in enumerate(difflines): |
| 551 | if line.startswith('+'): |
| 552 | line = color_format('{color_add}{line}', line=line) |
| 553 | difflines[i] = line |
| 554 | elif line.startswith('-'): |
| 555 | line = color_format('{color_remove}{line}', line=line) |
| 556 | difflines[i] = line |
| 557 | output.append(color_format("{color_title}Variable {var} value changed:{color_default}\n{diff}", var=dep, diff='\n'.join(difflines))) |
| 558 | elif newval and oldval and (' ' in oldval or ' ' in newval): |
| 559 | output.append(color_format("{color_title}Variable {var} value changed:{color_default}\n{diff}", var=dep, diff=worddiff_str(oldval, newval, colors))) |
| 560 | else: |
| 561 | 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] | 562 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 563 | if not 'file_checksum_values' in a_data: |
| 564 | a_data['file_checksum_values'] = {} |
| 565 | if not 'file_checksum_values' in b_data: |
| 566 | b_data['file_checksum_values'] = {} |
| 567 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 568 | changed, added, removed = file_checksums_diff(a_data['file_checksum_values'], b_data['file_checksum_values']) |
| 569 | if changed: |
| 570 | for f, old, new in changed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 571 | 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] | 572 | if added: |
| 573 | for f in added: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 574 | 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] | 575 | if removed: |
| 576 | for f in removed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 577 | 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] | 578 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 579 | if not 'runtaskdeps' in a_data: |
| 580 | a_data['runtaskdeps'] = {} |
| 581 | if not 'runtaskdeps' in b_data: |
| 582 | b_data['runtaskdeps'] = {} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 583 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 584 | if not collapsed: |
| 585 | if len(a_data['runtaskdeps']) != len(b_data['runtaskdeps']): |
| 586 | changed = ["Number of task dependencies changed"] |
| 587 | else: |
| 588 | changed = [] |
| 589 | for idx, task in enumerate(a_data['runtaskdeps']): |
| 590 | a = a_data['runtaskdeps'][idx] |
| 591 | b = b_data['runtaskdeps'][idx] |
| 592 | if a_data['runtaskhashes'][a] != b_data['runtaskhashes'][b] and not collapsed: |
| 593 | changed.append("%s with hash %s\n changed to\n%s with hash %s" % (clean_basepath(a), a_data['runtaskhashes'][a], clean_basepath(b), b_data['runtaskhashes'][b])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 594 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 595 | if changed: |
| 596 | clean_a = clean_basepaths_list(a_data['runtaskdeps']) |
| 597 | clean_b = clean_basepaths_list(b_data['runtaskdeps']) |
| 598 | if clean_a != clean_b: |
| 599 | output.append(color_format("{color_title}runtaskdeps changed:{color_default}\n%s") % list_inline_diff(clean_a, clean_b, colors)) |
| 600 | else: |
| 601 | output.append(color_format("{color_title}runtaskdeps changed:")) |
| 602 | output.append("\n".join(changed)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 603 | |
| 604 | |
| 605 | if 'runtaskhashes' in a_data and 'runtaskhashes' in b_data: |
| 606 | a = a_data['runtaskhashes'] |
| 607 | b = b_data['runtaskhashes'] |
| 608 | changed, added, removed = dict_diff(a, b) |
| 609 | if added: |
| 610 | for dep in added: |
| 611 | bdep_found = False |
| 612 | if removed: |
| 613 | for bdep in removed: |
| 614 | if b[dep] == a[bdep]: |
| 615 | #output.append("Dependency on task %s was replaced by %s with same hash" % (dep, bdep)) |
| 616 | bdep_found = True |
| 617 | if not bdep_found: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 618 | output.append(color_format("{color_title}Dependency on task %s was added{color_default} with hash %s") % (clean_basepath(dep), b[dep])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 619 | if removed: |
| 620 | for dep in removed: |
| 621 | adep_found = False |
| 622 | if added: |
| 623 | for adep in added: |
| 624 | if b[adep] == a[dep]: |
| 625 | #output.append("Dependency on task %s was replaced by %s with same hash" % (adep, dep)) |
| 626 | adep_found = True |
| 627 | if not adep_found: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 628 | output.append(color_format("{color_title}Dependency on task %s was removed{color_default} with hash %s") % (clean_basepath(dep), a[dep])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 629 | if changed: |
| 630 | for dep in changed: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 631 | if not collapsed: |
| 632 | output.append(color_format("{color_title}Hash for dependent task %s changed{color_default} from %s to %s") % (clean_basepath(dep), a[dep], b[dep])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 633 | if callable(recursecb): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 634 | recout = recursecb(dep, a[dep], b[dep]) |
| 635 | if recout: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 636 | if collapsed: |
| 637 | output.extend(recout) |
| 638 | else: |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 639 | # 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] | 640 | # that hash since in all likelyhood, they're the same changes this task also saw. |
| 641 | output = [output[-1]] + recout |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 642 | |
| 643 | a_taint = a_data.get('taint', None) |
| 644 | b_taint = b_data.get('taint', None) |
| 645 | if a_taint != b_taint: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 646 | if a_taint.startswith('nostamp:'): |
| 647 | a_taint = a_taint.replace('nostamp:', 'nostamp(uuid4):') |
| 648 | if b_taint.startswith('nostamp:'): |
| 649 | b_taint = b_taint.replace('nostamp:', 'nostamp(uuid4):') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 650 | 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] | 651 | |
| 652 | return output |
| 653 | |
| 654 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 655 | def calc_basehash(sigdata): |
| 656 | task = sigdata['task'] |
| 657 | basedata = sigdata['varvals'][task] |
| 658 | |
| 659 | if basedata is None: |
| 660 | basedata = '' |
| 661 | |
| 662 | alldeps = sigdata['taskdeps'] |
| 663 | for dep in alldeps: |
| 664 | basedata = basedata + dep |
| 665 | val = sigdata['varvals'][dep] |
| 666 | if val is not None: |
| 667 | basedata = basedata + str(val) |
| 668 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 669 | return hashlib.sha256(basedata.encode("utf-8")).hexdigest() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 670 | |
| 671 | def calc_taskhash(sigdata): |
| 672 | data = sigdata['basehash'] |
| 673 | |
| 674 | for dep in sigdata['runtaskdeps']: |
| 675 | data = data + sigdata['runtaskhashes'][dep] |
| 676 | |
| 677 | for c in sigdata['file_checksum_values']: |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 678 | if c[1]: |
| 679 | data = data + c[1] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 680 | |
| 681 | if 'taint' in sigdata: |
| 682 | if 'nostamp:' in sigdata['taint']: |
| 683 | data = data + sigdata['taint'][8:] |
| 684 | else: |
| 685 | data = data + sigdata['taint'] |
| 686 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 687 | return hashlib.sha256(data.encode("utf-8")).hexdigest() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 688 | |
| 689 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 690 | def dump_sigfile(a): |
| 691 | output = [] |
| 692 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 693 | with open(a, 'rb') as f: |
| 694 | p1 = pickle.Unpickler(f) |
| 695 | a_data = p1.load() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 696 | |
| 697 | output.append("basewhitelist: %s" % (a_data['basewhitelist'])) |
| 698 | |
| 699 | output.append("taskwhitelist: %s" % (a_data['taskwhitelist'])) |
| 700 | |
| 701 | output.append("Task dependencies: %s" % (sorted(a_data['taskdeps']))) |
| 702 | |
| 703 | output.append("basehash: %s" % (a_data['basehash'])) |
| 704 | |
| 705 | for dep in a_data['gendeps']: |
| 706 | output.append("List of dependencies for variable %s is %s" % (dep, a_data['gendeps'][dep])) |
| 707 | |
| 708 | for dep in a_data['varvals']: |
| 709 | output.append("Variable %s value is %s" % (dep, a_data['varvals'][dep])) |
| 710 | |
| 711 | if 'runtaskdeps' in a_data: |
| 712 | output.append("Tasks this task depends on: %s" % (a_data['runtaskdeps'])) |
| 713 | |
| 714 | if 'file_checksum_values' in a_data: |
| 715 | output.append("This task depends on the checksums of files: %s" % (a_data['file_checksum_values'])) |
| 716 | |
| 717 | if 'runtaskhashes' in a_data: |
| 718 | for dep in a_data['runtaskhashes']: |
| 719 | output.append("Hash for dependent task %s is %s" % (dep, a_data['runtaskhashes'][dep])) |
| 720 | |
| 721 | if 'taint' in a_data: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 722 | if a_data['taint'].startswith('nostamp:'): |
| 723 | msg = a_data['taint'].replace('nostamp:', 'nostamp(uuid4):') |
| 724 | else: |
| 725 | msg = a_data['taint'] |
| 726 | output.append("Tainted (by forced/invalidated task): %s" % msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 727 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 728 | if 'task' in a_data: |
| 729 | computed_basehash = calc_basehash(a_data) |
| 730 | output.append("Computed base hash is %s and from file %s" % (computed_basehash, a_data['basehash'])) |
| 731 | else: |
| 732 | output.append("Unable to compute base hash") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 733 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 734 | computed_taskhash = calc_taskhash(a_data) |
| 735 | output.append("Computed task hash is %s" % computed_taskhash) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 736 | |
| 737 | return output |