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