blob: d0a555654b59cd6bbe1ae3b7b10f25e5c3c52512 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright BitBake Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: GPL-2.0-only
5#
6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007import hashlib
8import logging
9import os
10import re
11import tempfile
Patrick Williamsc0f7c042017-02-23 20:41:17 -060012import pickle
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013import bb.data
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014import difflib
15import simplediff
Andrew Geisslereff27472021-10-29 15:35:00 -050016import json
Andrew Geissler517393d2023-01-13 08:55:19 -060017import types
Andrew Geisslereff27472021-10-29 15:35:00 -050018import bb.compress.zstd
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050019from bb.checksum import FileChecksumCache
Brad Bishop08902b02019-08-20 09:16:51 -040020from bb import runqueue
Brad Bishopa34c0302019-09-23 22:34:48 -040021import hashserv
Andrew Geissler475cb722020-07-10 16:00:51 -050022import hashserv.client
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023
24logger = logging.getLogger('BitBake.SigGen')
Andrew Geissler82c905d2020-04-13 13:39:40 -050025hashequiv_logger = logging.getLogger('BitBake.SigGen.HashEquiv')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026
Andrew Geisslereff27472021-10-29 15:35:00 -050027class SetEncoder(json.JSONEncoder):
28 def default(self, obj):
Andrew Geissler517393d2023-01-13 08:55:19 -060029 if isinstance(obj, set) or isinstance(obj, frozenset):
Andrew Geisslereff27472021-10-29 15:35:00 -050030 return dict(_set_object=list(sorted(obj)))
31 return json.JSONEncoder.default(self, obj)
32
33def SetDecoder(dct):
34 if '_set_object' in dct:
Andrew Geissler517393d2023-01-13 08:55:19 -060035 return frozenset(dct['_set_object'])
Andrew Geisslereff27472021-10-29 15:35:00 -050036 return dct
37
Patrick Williamsc124f4f2015-09-15 14:41:29 -050038def init(d):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060039 siggens = [obj for obj in globals().values()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040 if type(obj) is type and issubclass(obj, SignatureGenerator)]
41
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042 desired = d.getVar("BB_SIGNATURE_HANDLER") or "noop"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 for sg in siggens:
44 if desired == sg.name:
45 return sg(d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046 else:
47 logger.error("Invalid signature generator '%s', using default 'noop'\n"
48 "Available generators: %s", desired,
49 ', '.join(obj.name for obj in siggens))
50 return SignatureGenerator(d)
51
52class SignatureGenerator(object):
53 """
54 """
55 name = "noop"
56
57 def __init__(self, data):
Brad Bishop37a0e4d2017-12-04 01:01:44 -050058 self.basehash = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059 self.taskhash = {}
Andrew Geissler82c905d2020-04-13 13:39:40 -050060 self.unihash = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061 self.runtaskdeps = {}
62 self.file_checksum_values = {}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063 self.taints = {}
Brad Bishop08902b02019-08-20 09:16:51 -040064 self.unitaskhashes = {}
Andrew Geissler82c905d2020-04-13 13:39:40 -050065 self.tidtopn = {}
66 self.setscenetasks = set()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067
68 def finalise(self, fn, d, varient):
69 return
70
Andrew Geissler82c905d2020-04-13 13:39:40 -050071 def postparsing_clean_cache(self):
72 return
73
Andrew Geissler517393d2023-01-13 08:55:19 -060074 def setup_datacache(self, datacaches):
75 self.datacaches = datacaches
76
77 def setup_datacache_from_datastore(self, mcfn, d):
78 # In task context we have no cache so setup internal data structures
79 # from the fully parsed data store provided
80
81 mc = d.getVar("__BBMULTICONFIG", False) or ""
82 tasks = d.getVar('__BBTASKS', False)
83
84 self.datacaches = {}
85 self.datacaches[mc] = types.SimpleNamespace()
86 setattr(self.datacaches[mc], "stamp", {})
87 self.datacaches[mc].stamp[mcfn] = d.getVar('STAMP')
88 setattr(self.datacaches[mc], "stamp_extrainfo", {})
89 self.datacaches[mc].stamp_extrainfo[mcfn] = {}
90 for t in tasks:
91 flag = d.getVarFlag(t, "stamp-extra-info")
92 if flag:
93 self.datacaches[mc].stamp_extrainfo[mcfn][t] = flag
94
Brad Bishop08902b02019-08-20 09:16:51 -040095 def get_unihash(self, tid):
96 return self.taskhash[tid]
Brad Bishop19323692019-04-05 15:28:33 -040097
Andrew Geissler5a43b432020-06-13 10:46:56 -050098 def prep_taskhash(self, tid, deps, dataCaches):
Andrew Geissler82c905d2020-04-13 13:39:40 -050099 return
100
Andrew Geissler5a43b432020-06-13 10:46:56 -0500101 def get_taskhash(self, tid, deps, dataCaches):
Brad Bishop08902b02019-08-20 09:16:51 -0400102 self.taskhash[tid] = hashlib.sha256(tid.encode("utf-8")).hexdigest()
103 return self.taskhash[tid]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500105 def writeout_file_checksum_cache(self):
106 """Write/update the file checksum cache onto disk"""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 return
108
Andrew Geissler517393d2023-01-13 08:55:19 -0600109 def stampfile_base(self, mcfn):
110 mc = bb.runqueue.mc_from_tid(mcfn)
111 return self.datacaches[mc].stamp[mcfn]
112
113 def stampfile_mcfn(self, taskname, mcfn, extrainfo=True):
114 mc = bb.runqueue.mc_from_tid(mcfn)
115 stamp = self.datacaches[mc].stamp[mcfn]
116 if not stamp:
117 return
118
119 stamp_extrainfo = ""
120 if extrainfo:
121 taskflagname = taskname
122 if taskname.endswith("_setscene"):
123 taskflagname = taskname.replace("_setscene", "")
124 stamp_extrainfo = self.datacaches[mc].stamp_extrainfo[mcfn].get(taskflagname) or ""
125
126 return self.stampfile(stamp, mcfn, taskname, stamp_extrainfo)
127
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500128 def stampfile(self, stampbase, file_name, taskname, extrainfo):
129 return ("%s.%s.%s" % (stampbase, taskname, extrainfo)).rstrip('.')
130
Andrew Geissler517393d2023-01-13 08:55:19 -0600131 def stampcleanmask_mcfn(self, taskname, mcfn):
132 mc = bb.runqueue.mc_from_tid(mcfn)
133 stamp = self.datacaches[mc].stamp[mcfn]
134 if not stamp:
135 return []
136
137 taskflagname = taskname
138 if taskname.endswith("_setscene"):
139 taskflagname = taskname.replace("_setscene", "")
140 stamp_extrainfo = self.datacaches[mc].stamp_extrainfo[mcfn].get(taskflagname) or ""
141
142 return self.stampcleanmask(stamp, mcfn, taskname, stamp_extrainfo)
143
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 def stampcleanmask(self, stampbase, file_name, taskname, extrainfo):
145 return ("%s.%s.%s" % (stampbase, taskname, extrainfo)).rstrip('.')
146
Andrew Geissler517393d2023-01-13 08:55:19 -0600147 def dump_sigtask(self, mcfn, task, stampbase, runtime):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 return
149
Andrew Geissler517393d2023-01-13 08:55:19 -0600150 def invalidate_task(self, task, mcfn):
151 mc = bb.runqueue.mc_from_tid(mcfn)
152 stamp = self.datacaches[mc].stamp[mcfn]
153 bb.utils.remove(stamp)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154
155 def dump_sigs(self, dataCache, options):
156 return
157
158 def get_taskdata(self):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500159 return (self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes, self.tidtopn, self.setscenetasks)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160
161 def set_taskdata(self, data):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500162 self.runtaskdeps, self.taskhash, self.unihash, self.file_checksum_values, self.taints, self.basehash, self.unitaskhashes, self.tidtopn, self.setscenetasks = data
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164 def reset(self, data):
165 self.__init__(data)
166
Brad Bishop08902b02019-08-20 09:16:51 -0400167 def get_taskhashes(self):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500168 return self.taskhash, self.unihash, self.unitaskhashes, self.tidtopn
Brad Bishop08902b02019-08-20 09:16:51 -0400169
170 def set_taskhashes(self, hashes):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500171 self.taskhash, self.unihash, self.unitaskhashes, self.tidtopn = hashes
Brad Bishop08902b02019-08-20 09:16:51 -0400172
173 def save_unitaskhashes(self):
174 return
175
Andrew Geissler78b72792022-06-14 06:47:25 -0500176 def copy_unitaskhashes(self, targetdir):
177 return
178
Brad Bishopa34c0302019-09-23 22:34:48 -0400179 def set_setscene_tasks(self, setscene_tasks):
180 return
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500181
Andrew Geissler9aee5002022-03-30 16:27:02 +0000182 def exit(self):
183 return
184
Patrick Williams2a254922023-08-11 09:48:11 -0500185def build_pnid(mc, pn, taskname):
186 if mc:
187 return "mc:" + mc + ":" + pn + ":" + taskname
188 return pn + ":" + taskname
189
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190class SignatureGeneratorBasic(SignatureGenerator):
191 """
192 """
193 name = "basic"
194
195 def __init__(self, data):
196 self.basehash = {}
197 self.taskhash = {}
Andrew Geissler82c905d2020-04-13 13:39:40 -0500198 self.unihash = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199 self.runtaskdeps = {}
200 self.file_checksum_values = {}
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500201 self.taints = {}
Andrew Geissler82c905d2020-04-13 13:39:40 -0500202 self.setscenetasks = set()
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000203 self.basehash_ignore_vars = set((data.getVar("BB_BASEHASH_IGNORE_VARS") or "").split())
204 self.taskhash_ignore_tasks = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205 self.init_rundepcheck(data)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500206 checksum_cache_file = data.getVar("BB_HASH_CHECKSUM_CACHE_FILE")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500207 if checksum_cache_file:
208 self.checksum_cache = FileChecksumCache()
209 self.checksum_cache.init_cache(data, checksum_cache_file)
210 else:
211 self.checksum_cache = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212
Andrew Geissler82c905d2020-04-13 13:39:40 -0500213 self.unihash_cache = bb.cache.SimpleCache("3")
Brad Bishop08902b02019-08-20 09:16:51 -0400214 self.unitaskhashes = self.unihash_cache.init_cache(data, "bb_unihashes.dat", {})
Andrew Geissler82c905d2020-04-13 13:39:40 -0500215 self.localdirsexclude = (data.getVar("BB_SIGNATURE_LOCAL_DIRS_EXCLUDE") or "CVS .bzr .git .hg .osc .p4 .repo .svn").split()
216 self.tidtopn = {}
Brad Bishop08902b02019-08-20 09:16:51 -0400217
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500218 def init_rundepcheck(self, data):
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000219 self.taskhash_ignore_tasks = data.getVar("BB_TASKHASH_IGNORE_TASKS") or None
220 if self.taskhash_ignore_tasks:
221 self.twl = re.compile(self.taskhash_ignore_tasks)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222 else:
223 self.twl = None
224
Andrew Geissler517393d2023-01-13 08:55:19 -0600225 def _build_data(self, mcfn, d):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500227 ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') == '1')
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000228 tasklist, gendeps, lookupcache = bb.data.generate_dependencies(d, self.basehash_ignore_vars)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500229
Andrew Geissler517393d2023-01-13 08:55:19 -0600230 taskdeps, basehash = bb.data.generate_dependency_hash(tasklist, gendeps, lookupcache, self.basehash_ignore_vars, mcfn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231
232 for task in tasklist:
Andrew Geissler517393d2023-01-13 08:55:19 -0600233 tid = mcfn + ":" + task
Brad Bishop08902b02019-08-20 09:16:51 -0400234 if not ignore_mismatch and tid in self.basehash and self.basehash[tid] != basehash[tid]:
235 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 Bishopc342db32019-05-15 21:57:59 -0400236 bb.error("The following commands may help:")
237 cmd = "$ bitbake %s -c%s" % (d.getVar('PN'), task)
238 # Make sure sigdata is dumped before run printdiff
239 bb.error("%s -Snone" % cmd)
240 bb.error("Then:")
241 bb.error("%s -Sprintdiff\n" % cmd)
Brad Bishop08902b02019-08-20 09:16:51 -0400242 self.basehash[tid] = basehash[tid]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500243
Andrew Geissler517393d2023-01-13 08:55:19 -0600244 return taskdeps, gendeps, lookupcache
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500245
Brad Bishopa34c0302019-09-23 22:34:48 -0400246 def set_setscene_tasks(self, setscene_tasks):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500247 self.setscenetasks = set(setscene_tasks)
Brad Bishopa34c0302019-09-23 22:34:48 -0400248
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500249 def finalise(self, fn, d, variant):
250
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600251 mc = d.getVar("__BBMULTICONFIG", False) or ""
Andrew Geissler517393d2023-01-13 08:55:19 -0600252 mcfn = fn
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600253 if variant or mc:
Andrew Geissler517393d2023-01-13 08:55:19 -0600254 mcfn = bb.cache.realfn2virtual(fn, variant, mc)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500255
256 try:
Andrew Geissler517393d2023-01-13 08:55:19 -0600257 taskdeps, gendeps, lookupcache = self._build_data(mcfn, d)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500258 except bb.parse.SkipRecipe:
259 raise
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260 except:
Andrew Geissler517393d2023-01-13 08:55:19 -0600261 bb.warn("Error during finalise of %s" % mcfn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 raise
263
264 #Slow but can be useful for debugging mismatched basehashes
Andrew Geissler517393d2023-01-13 08:55:19 -0600265 #for task in self.taskdeps[mcfn]:
266 # self.dump_sigtask(mcfn, task, d.getVar("STAMP"), False)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267
Andrew Geissler517393d2023-01-13 08:55:19 -0600268 basehashes = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500269 for task in taskdeps:
Andrew Geissler517393d2023-01-13 08:55:19 -0600270 basehashes[task] = self.basehash[mcfn + ":" + task]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500271
Andrew Geissler517393d2023-01-13 08:55:19 -0600272 d.setVar("__siggen_basehashes", basehashes)
273 d.setVar("__siggen_gendeps", gendeps)
274 d.setVar("__siggen_varvals", lookupcache)
275 d.setVar("__siggen_taskdeps", taskdeps)
276
277 def setup_datacache_from_datastore(self, mcfn, d):
278 super().setup_datacache_from_datastore(mcfn, d)
279
280 mc = bb.runqueue.mc_from_tid(mcfn)
281 for attr in ["siggen_varvals", "siggen_taskdeps", "siggen_gendeps"]:
282 if not hasattr(self.datacaches[mc], attr):
283 setattr(self.datacaches[mc], attr, {})
284 self.datacaches[mc].siggen_varvals[mcfn] = d.getVar("__siggen_varvals")
285 self.datacaches[mc].siggen_taskdeps[mcfn] = d.getVar("__siggen_taskdeps")
286 self.datacaches[mc].siggen_gendeps[mcfn] = d.getVar("__siggen_gendeps")
Andrew Geissler82c905d2020-04-13 13:39:40 -0500287
Andrew Geissler5a43b432020-06-13 10:46:56 -0500288 def rundep_check(self, fn, recipename, task, dep, depname, dataCaches):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289 # Return True if we should keep the dependency, False to drop it
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000290 # We only manipulate the dependencies for packages not in the ignore
291 # list
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292 if self.twl and not self.twl.search(recipename):
293 # then process the actual dependencies
294 if self.twl.search(depname):
295 return False
296 return True
297
298 def read_taint(self, fn, task, stampbase):
299 taint = None
300 try:
301 with open(stampbase + '.' + task + '.taint', 'r') as taintf:
302 taint = taintf.read()
303 except IOError:
304 pass
305 return taint
306
Andrew Geissler5a43b432020-06-13 10:46:56 -0500307 def prep_taskhash(self, tid, deps, dataCaches):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800308
Andrew Geissler517393d2023-01-13 08:55:19 -0600309 (mc, _, task, mcfn) = bb.runqueue.split_tid_mcfn(tid)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800310
Andrew Geissler5a43b432020-06-13 10:46:56 -0500311 self.basehash[tid] = dataCaches[mc].basetaskhash[tid]
Brad Bishop08902b02019-08-20 09:16:51 -0400312 self.runtaskdeps[tid] = []
313 self.file_checksum_values[tid] = []
Andrew Geissler517393d2023-01-13 08:55:19 -0600314 recipename = dataCaches[mc].pkg_fn[mcfn]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500315
316 self.tidtopn[tid] = recipename
Patrick Williams2a254922023-08-11 09:48:11 -0500317 # save hashfn for deps into siginfo?
318 for dep in deps:
319 (depmc, _, deptask, depmcfn) = bb.runqueue.split_tid_mcfn(dep)
320 dep_pn = dataCaches[depmc].pkg_fn[depmcfn]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500321
Patrick Williams2a254922023-08-11 09:48:11 -0500322 if not self.rundep_check(mcfn, recipename, task, dep, dep_pn, dataCaches):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500323 continue
Patrick Williams2a254922023-08-11 09:48:11 -0500324
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500325 if dep not in self.taskhash:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800326 bb.fatal("%s is not in taskhash, caller isn't calling in dependency order?" % dep)
Patrick Williams2a254922023-08-11 09:48:11 -0500327
328 dep_pnid = build_pnid(depmc, dep_pn, deptask)
329 self.runtaskdeps[tid].append((dep_pnid, dep))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330
Andrew Geissler517393d2023-01-13 08:55:19 -0600331 if task in dataCaches[mc].file_checksums[mcfn]:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500332 if self.checksum_cache:
Andrew Geissler517393d2023-01-13 08:55:19 -0600333 checksums = self.checksum_cache.get_checksums(dataCaches[mc].file_checksums[mcfn][task], recipename, self.localdirsexclude)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500334 else:
Andrew Geissler517393d2023-01-13 08:55:19 -0600335 checksums = bb.fetch2.get_file_checksums(dataCaches[mc].file_checksums[mcfn][task], recipename, self.localdirsexclude)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336 for (f,cs) in checksums:
Brad Bishop08902b02019-08-20 09:16:51 -0400337 self.file_checksum_values[tid].append((f,cs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500338
Andrew Geissler517393d2023-01-13 08:55:19 -0600339 taskdep = dataCaches[mc].task_deps[mcfn]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340 if 'nostamp' in taskdep and task in taskdep['nostamp']:
341 # Nostamp tasks need an implicit taint so that they force any dependent tasks to run
Andrew Geissler82c905d2020-04-13 13:39:40 -0500342 if tid in self.taints and self.taints[tid].startswith("nostamp:"):
343 # Don't reset taint value upon every call
344 pass
345 else:
346 import uuid
347 taint = str(uuid.uuid4())
348 self.taints[tid] = "nostamp:" + taint
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500349
Andrew Geissler517393d2023-01-13 08:55:19 -0600350 taint = self.read_taint(mcfn, task, dataCaches[mc].stamp[mcfn])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351 if taint:
Brad Bishop08902b02019-08-20 09:16:51 -0400352 self.taints[tid] = taint
353 logger.warning("%s is tainted from a forced run" % tid)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500354
Andrew Geissler82c905d2020-04-13 13:39:40 -0500355 return
356
Andrew Geissler5a43b432020-06-13 10:46:56 -0500357 def get_taskhash(self, tid, deps, dataCaches):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500358
359 data = self.basehash[tid]
Patrick Williams2a254922023-08-11 09:48:11 -0500360 for dep in sorted(self.runtaskdeps[tid]):
361 data += self.get_unihash(dep[1])
Andrew Geissler82c905d2020-04-13 13:39:40 -0500362
363 for (f, cs) in self.file_checksum_values[tid]:
364 if cs:
Andrew Geissler595f6302022-01-24 19:11:47 +0000365 if "/./" in f:
Patrick Williams864cc432023-02-09 14:54:44 -0600366 data += "./" + f.split("/./")[1]
367 data += cs
Andrew Geissler82c905d2020-04-13 13:39:40 -0500368
369 if tid in self.taints:
370 if self.taints[tid].startswith("nostamp:"):
Patrick Williams864cc432023-02-09 14:54:44 -0600371 data += self.taints[tid][8:]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500372 else:
Patrick Williams864cc432023-02-09 14:54:44 -0600373 data += self.taints[tid]
Andrew Geissler82c905d2020-04-13 13:39:40 -0500374
Brad Bishop19323692019-04-05 15:28:33 -0400375 h = hashlib.sha256(data.encode("utf-8")).hexdigest()
Brad Bishop08902b02019-08-20 09:16:51 -0400376 self.taskhash[tid] = h
Patrick Williams213cb262021-08-07 19:21:33 -0500377 #d.setVar("BB_TASKHASH:task-%s" % task, taskhash[task])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378 return h
379
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500380 def writeout_file_checksum_cache(self):
381 """Write/update the file checksum cache onto disk"""
382 if self.checksum_cache:
383 self.checksum_cache.save_extras()
384 self.checksum_cache.save_merge()
385 else:
386 bb.fetch2.fetcher_parse_save()
387 bb.fetch2.fetcher_parse_done()
388
Brad Bishop08902b02019-08-20 09:16:51 -0400389 def save_unitaskhashes(self):
390 self.unihash_cache.save(self.unitaskhashes)
391
Andrew Geissler78b72792022-06-14 06:47:25 -0500392 def copy_unitaskhashes(self, targetdir):
393 self.unihash_cache.copyfile(targetdir)
394
Andrew Geissler517393d2023-01-13 08:55:19 -0600395 def dump_sigtask(self, mcfn, task, stampbase, runtime):
396 tid = mcfn + ":" + task
397 mc = bb.runqueue.mc_from_tid(mcfn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500398 referencestamp = stampbase
399 if isinstance(runtime, str) and runtime.startswith("customfile"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400 sigfile = stampbase
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500401 referencestamp = runtime[11:]
Brad Bishop08902b02019-08-20 09:16:51 -0400402 elif runtime and tid in self.taskhash:
Brad Bishop00e122a2019-10-05 11:10:57 -0400403 sigfile = stampbase + "." + task + ".sigdata" + "." + self.get_unihash(tid)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500404 else:
Brad Bishop08902b02019-08-20 09:16:51 -0400405 sigfile = stampbase + "." + task + ".sigbasedata" + "." + self.basehash[tid]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500406
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500407 with bb.utils.umask(0o002):
408 bb.utils.mkdirhier(os.path.dirname(sigfile))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500409
410 data = {}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500411 data['task'] = task
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000412 data['basehash_ignore_vars'] = self.basehash_ignore_vars
413 data['taskhash_ignore_tasks'] = self.taskhash_ignore_tasks
Andrew Geissler517393d2023-01-13 08:55:19 -0600414 data['taskdeps'] = self.datacaches[mc].siggen_taskdeps[mcfn][task]
Brad Bishop08902b02019-08-20 09:16:51 -0400415 data['basehash'] = self.basehash[tid]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500416 data['gendeps'] = {}
417 data['varvals'] = {}
Andrew Geissler517393d2023-01-13 08:55:19 -0600418 data['varvals'][task] = self.datacaches[mc].siggen_varvals[mcfn][task]
419 for dep in self.datacaches[mc].siggen_taskdeps[mcfn][task]:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000420 if dep in self.basehash_ignore_vars:
Andrew Geissler517393d2023-01-13 08:55:19 -0600421 continue
422 data['gendeps'][dep] = self.datacaches[mc].siggen_gendeps[mcfn][dep]
423 data['varvals'][dep] = self.datacaches[mc].siggen_varvals[mcfn][dep]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500424
Brad Bishop08902b02019-08-20 09:16:51 -0400425 if runtime and tid in self.taskhash:
Patrick Williams2a254922023-08-11 09:48:11 -0500426 data['runtaskdeps'] = [dep[0] for dep in sorted(self.runtaskdeps[tid])]
Andrew Geissler595f6302022-01-24 19:11:47 +0000427 data['file_checksum_values'] = []
428 for f,cs in self.file_checksum_values[tid]:
429 if "/./" in f:
430 data['file_checksum_values'].append(("./" + f.split("/./")[1], cs))
431 else:
432 data['file_checksum_values'].append((os.path.basename(f), cs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500433 data['runtaskhashes'] = {}
Patrick Williams2a254922023-08-11 09:48:11 -0500434 for dep in self.runtaskdeps[tid]:
435 data['runtaskhashes'][dep[0]] = self.get_unihash(dep[1])
Brad Bishop08902b02019-08-20 09:16:51 -0400436 data['taskhash'] = self.taskhash[tid]
Brad Bishop00e122a2019-10-05 11:10:57 -0400437 data['unihash'] = self.get_unihash(tid)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500438
Andrew Geissler517393d2023-01-13 08:55:19 -0600439 taint = self.read_taint(mcfn, task, referencestamp)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500440 if taint:
441 data['taint'] = taint
442
Brad Bishop08902b02019-08-20 09:16:51 -0400443 if runtime and tid in self.taints:
444 if 'nostamp:' in self.taints[tid]:
445 data['taint'] = self.taints[tid]
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500446
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500447 computed_basehash = calc_basehash(data)
Brad Bishop08902b02019-08-20 09:16:51 -0400448 if computed_basehash != self.basehash[tid]:
449 bb.error("Basehash mismatch %s versus %s for %s" % (computed_basehash, self.basehash[tid], tid))
450 if runtime and tid in self.taskhash:
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500451 computed_taskhash = calc_taskhash(data)
Brad Bishop08902b02019-08-20 09:16:51 -0400452 if computed_taskhash != self.taskhash[tid]:
453 bb.error("Taskhash mismatch %s versus %s for %s" % (computed_taskhash, self.taskhash[tid], tid))
454 sigfile = sigfile.replace(self.taskhash[tid], computed_taskhash)
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500455
Patrick Williams92b42cb2022-09-03 06:53:57 -0500456 fd, tmpfile = bb.utils.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500457 try:
Andrew Geisslereff27472021-10-29 15:35:00 -0500458 with bb.compress.zstd.open(fd, "wt", encoding="utf-8", num_threads=1) as f:
459 json.dump(data, f, sort_keys=True, separators=(",", ":"), cls=SetEncoder)
460 f.flush()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600461 os.chmod(tmpfile, 0o664)
Andrew Geisslerc926e172021-05-07 16:11:35 -0500462 bb.utils.rename(tmpfile, sigfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500463 except (OSError, IOError) as err:
464 try:
465 os.unlink(tmpfile)
466 except OSError:
467 pass
468 raise err
469
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500470class SignatureGeneratorBasicHash(SignatureGeneratorBasic):
471 name = "basichash"
472
Brad Bishop08902b02019-08-20 09:16:51 -0400473 def get_stampfile_hash(self, tid):
474 if tid in self.taskhash:
475 return self.taskhash[tid]
Brad Bishop19323692019-04-05 15:28:33 -0400476
477 # If task is not in basehash, then error
Brad Bishop08902b02019-08-20 09:16:51 -0400478 return self.basehash[tid]
Brad Bishop19323692019-04-05 15:28:33 -0400479
Andrew Geissler517393d2023-01-13 08:55:19 -0600480 def stampfile(self, stampbase, mcfn, taskname, extrainfo, clean=False):
481 if taskname.endswith("_setscene"):
482 tid = mcfn + ":" + taskname[:-9]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500483 else:
Andrew Geissler517393d2023-01-13 08:55:19 -0600484 tid = mcfn + ":" + taskname
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500485 if clean:
486 h = "*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500487 else:
Brad Bishop08902b02019-08-20 09:16:51 -0400488 h = self.get_stampfile_hash(tid)
Brad Bishop19323692019-04-05 15:28:33 -0400489
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500490 return ("%s.%s.%s.%s" % (stampbase, taskname, h, extrainfo)).rstrip('.')
491
Andrew Geissler517393d2023-01-13 08:55:19 -0600492 def stampcleanmask(self, stampbase, mcfn, taskname, extrainfo):
493 return self.stampfile(stampbase, mcfn, taskname, extrainfo, clean=True)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800494
Andrew Geissler517393d2023-01-13 08:55:19 -0600495 def invalidate_task(self, task, mcfn):
496 bb.note("Tainting hash to force rebuild of task %s, %s" % (mcfn, task))
497
498 mc = bb.runqueue.mc_from_tid(mcfn)
499 stamp = self.datacaches[mc].stamp[mcfn]
500
501 taintfn = stamp + '.' + task + '.taint'
502
503 import uuid
504 bb.utils.mkdirhier(os.path.dirname(taintfn))
505 # The specific content of the taint file is not really important,
506 # we just need it to be random, so a random UUID is used
507 with open(taintfn, 'w') as taintf:
508 taintf.write(str(uuid.uuid4()))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500509
Brad Bishop08902b02019-08-20 09:16:51 -0400510class SignatureGeneratorUniHashMixIn(object):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500511 def __init__(self, data):
512 self.extramethod = {}
513 super().__init__(data)
514
Brad Bishop08902b02019-08-20 09:16:51 -0400515 def get_taskdata(self):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500516 return (self.server, self.method, self.extramethod) + super().get_taskdata()
Brad Bishop08902b02019-08-20 09:16:51 -0400517
518 def set_taskdata(self, data):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500519 self.server, self.method, self.extramethod = data[:3]
520 super().set_taskdata(data[3:])
Brad Bishop08902b02019-08-20 09:16:51 -0400521
Brad Bishopa34c0302019-09-23 22:34:48 -0400522 def client(self):
523 if getattr(self, '_client', None) is None:
524 self._client = hashserv.create_client(self.server)
525 return self._client
526
Andrew Geissler9aee5002022-03-30 16:27:02 +0000527 def reset(self, data):
528 if getattr(self, '_client', None) is not None:
529 self._client.close()
530 self._client = None
531 return super().reset(data)
532
533 def exit(self):
534 if getattr(self, '_client', None) is not None:
535 self._client.close()
536 self._client = None
537 return super().exit()
538
Brad Bishop08902b02019-08-20 09:16:51 -0400539 def get_stampfile_hash(self, tid):
540 if tid in self.taskhash:
541 # If a unique hash is reported, use it as the stampfile hash. This
542 # ensures that if a task won't be re-run if the taskhash changes,
543 # but it would result in the same output hash
Andrew Geissler82c905d2020-04-13 13:39:40 -0500544 unihash = self._get_unihash(tid)
Brad Bishop08902b02019-08-20 09:16:51 -0400545 if unihash is not None:
546 return unihash
547
548 return super().get_stampfile_hash(tid)
549
550 def set_unihash(self, tid, unihash):
Andrew Geissler82c905d2020-04-13 13:39:40 -0500551 (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid)
552 key = mc + ":" + self.tidtopn[tid] + ":" + taskname
553 self.unitaskhashes[key] = (self.taskhash[tid], unihash)
554 self.unihash[tid] = unihash
555
556 def _get_unihash(self, tid, checkkey=None):
557 if tid not in self.tidtopn:
558 return None
559 (mc, fn, taskname, taskfn) = bb.runqueue.split_tid_mcfn(tid)
560 key = mc + ":" + self.tidtopn[tid] + ":" + taskname
561 if key not in self.unitaskhashes:
562 return None
563 if not checkkey:
564 checkkey = self.taskhash[tid]
565 (key, unihash) = self.unitaskhashes[key]
566 if key != checkkey:
567 return None
568 return unihash
Brad Bishop08902b02019-08-20 09:16:51 -0400569
570 def get_unihash(self, tid):
Brad Bishop08902b02019-08-20 09:16:51 -0400571 taskhash = self.taskhash[tid]
572
Brad Bishopa34c0302019-09-23 22:34:48 -0400573 # If its not a setscene task we can return
574 if self.setscenetasks and tid not in self.setscenetasks:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500575 self.unihash[tid] = None
Brad Bishopa34c0302019-09-23 22:34:48 -0400576 return taskhash
577
Brad Bishop08902b02019-08-20 09:16:51 -0400578 # TODO: This cache can grow unbounded. It probably only needs to keep
579 # for each task
Andrew Geissler82c905d2020-04-13 13:39:40 -0500580 unihash = self._get_unihash(tid)
Brad Bishop08902b02019-08-20 09:16:51 -0400581 if unihash is not None:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500582 self.unihash[tid] = unihash
Brad Bishop08902b02019-08-20 09:16:51 -0400583 return unihash
584
585 # In the absence of being able to discover a unique hash from the
586 # server, make it be equivalent to the taskhash. The unique "hash" only
587 # really needs to be a unique string (not even necessarily a hash), but
588 # making it match the taskhash has a few advantages:
589 #
590 # 1) All of the sstate code that assumes hashes can be the same
591 # 2) It provides maximal compatibility with builders that don't use
592 # an equivalency server
593 # 3) The value is easy for multiple independent builders to derive the
594 # same unique hash from the same input. This means that if the
595 # independent builders find the same taskhash, but it isn't reported
596 # to the server, there is a better chance that they will agree on
597 # the unique hash.
598 unihash = taskhash
599
600 try:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500601 method = self.method
602 if tid in self.extramethod:
603 method = method + self.extramethod[tid]
604 data = self.client().get_unihash(method, self.taskhash[tid])
Brad Bishopa34c0302019-09-23 22:34:48 -0400605 if data:
606 unihash = data
Brad Bishop08902b02019-08-20 09:16:51 -0400607 # A unique hash equal to the taskhash is not very interesting,
608 # so it is reported it at debug level 2. If they differ, that
609 # is much more interesting, so it is reported at debug level 1
Andrew Geissler6aa7eec2023-03-03 12:41:14 -0600610 hashequiv_logger.bbdebug((1, 2)[unihash == taskhash], 'Found unihash %s in place of %s for %s from %s' % (unihash, taskhash, tid, self.server))
Brad Bishop08902b02019-08-20 09:16:51 -0400611 else:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600612 hashequiv_logger.debug2('No reported unihash for %s:%s from %s' % (tid, taskhash, self.server))
Andrew Geisslerc926e172021-05-07 16:11:35 -0500613 except ConnectionError as e:
Brad Bishopa34c0302019-09-23 22:34:48 -0400614 bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
Brad Bishop08902b02019-08-20 09:16:51 -0400615
Andrew Geissler82c905d2020-04-13 13:39:40 -0500616 self.set_unihash(tid, unihash)
617 self.unihash[tid] = unihash
Brad Bishop08902b02019-08-20 09:16:51 -0400618 return unihash
619
620 def report_unihash(self, path, task, d):
Brad Bishop08902b02019-08-20 09:16:51 -0400621 import importlib
622
623 taskhash = d.getVar('BB_TASKHASH')
624 unihash = d.getVar('BB_UNIHASH')
625 report_taskdata = d.getVar('SSTATE_HASHEQUIV_REPORT_TASKDATA') == '1'
626 tempdir = d.getVar('T')
Andrew Geissler517393d2023-01-13 08:55:19 -0600627 mcfn = d.getVar('BB_FILENAME')
628 tid = mcfn + ':do_' + task
Andrew Geissler82c905d2020-04-13 13:39:40 -0500629 key = tid + ':' + taskhash
Brad Bishop00e122a2019-10-05 11:10:57 -0400630
631 if self.setscenetasks and tid not in self.setscenetasks:
632 return
Brad Bishop08902b02019-08-20 09:16:51 -0400633
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000634 # This can happen if locked sigs are in action. Detect and just exit
Andrew Geissler82c905d2020-04-13 13:39:40 -0500635 if taskhash != self.taskhash[tid]:
636 return
637
Brad Bishop08902b02019-08-20 09:16:51 -0400638 # Sanity checks
Andrew Geissler82c905d2020-04-13 13:39:40 -0500639 cache_unihash = self._get_unihash(tid, checkkey=taskhash)
Brad Bishop08902b02019-08-20 09:16:51 -0400640 if cache_unihash is None:
641 bb.fatal('%s not in unihash cache. Please report this error' % key)
642
643 if cache_unihash != unihash:
644 bb.fatal("Cache unihash %s doesn't match BB_UNIHASH %s" % (cache_unihash, unihash))
645
646 sigfile = None
647 sigfile_name = "depsig.do_%s.%d" % (task, os.getpid())
648 sigfile_link = "depsig.do_%s" % task
649
650 try:
651 sigfile = open(os.path.join(tempdir, sigfile_name), 'w+b')
652
653 locs = {'path': path, 'sigfile': sigfile, 'task': task, 'd': d}
654
655 if "." in self.method:
656 (module, method) = self.method.rsplit('.', 1)
657 locs['method'] = getattr(importlib.import_module(module), method)
658 outhash = bb.utils.better_eval('method(path, sigfile, task, d)', locs)
659 else:
660 outhash = bb.utils.better_eval(self.method + '(path, sigfile, task, d)', locs)
661
662 try:
Brad Bishopa34c0302019-09-23 22:34:48 -0400663 extra_data = {}
664
665 owner = d.getVar('SSTATE_HASHEQUIV_OWNER')
666 if owner:
667 extra_data['owner'] = owner
Brad Bishop08902b02019-08-20 09:16:51 -0400668
669 if report_taskdata:
670 sigfile.seek(0)
671
Brad Bishopa34c0302019-09-23 22:34:48 -0400672 extra_data['PN'] = d.getVar('PN')
673 extra_data['PV'] = d.getVar('PV')
674 extra_data['PR'] = d.getVar('PR')
675 extra_data['task'] = task
676 extra_data['outhash_siginfo'] = sigfile.read().decode('utf-8')
Brad Bishop08902b02019-08-20 09:16:51 -0400677
Andrew Geissler82c905d2020-04-13 13:39:40 -0500678 method = self.method
679 if tid in self.extramethod:
680 method = method + self.extramethod[tid]
681
682 data = self.client().report_unihash(taskhash, method, outhash, unihash, extra_data)
Brad Bishopa34c0302019-09-23 22:34:48 -0400683 new_unihash = data['unihash']
Brad Bishop08902b02019-08-20 09:16:51 -0400684
685 if new_unihash != unihash:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600686 hashequiv_logger.debug('Task %s unihash changed %s -> %s by server %s' % (taskhash, unihash, new_unihash, self.server))
Andrew Geissler517393d2023-01-13 08:55:19 -0600687 bb.event.fire(bb.runqueue.taskUniHashUpdate(mcfn + ':do_' + task, new_unihash), d)
Andrew Geissler82c905d2020-04-13 13:39:40 -0500688 self.set_unihash(tid, new_unihash)
689 d.setVar('BB_UNIHASH', new_unihash)
Brad Bishop08902b02019-08-20 09:16:51 -0400690 else:
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600691 hashequiv_logger.debug('Reported task %s as unihash %s to %s' % (taskhash, unihash, self.server))
Andrew Geisslerc926e172021-05-07 16:11:35 -0500692 except ConnectionError as e:
Brad Bishopa34c0302019-09-23 22:34:48 -0400693 bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
Brad Bishop08902b02019-08-20 09:16:51 -0400694 finally:
695 if sigfile:
696 sigfile.close()
697
698 sigfile_link_path = os.path.join(tempdir, sigfile_link)
699 bb.utils.remove(sigfile_link_path)
700
701 try:
702 os.symlink(sigfile_name, sigfile_link_path)
703 except OSError:
704 pass
705
Andrew Geissler82c905d2020-04-13 13:39:40 -0500706 def report_unihash_equiv(self, tid, taskhash, wanted_unihash, current_unihash, datacaches):
707 try:
708 extra_data = {}
709 method = self.method
710 if tid in self.extramethod:
711 method = method + self.extramethod[tid]
712
713 data = self.client().report_unihash_equiv(taskhash, method, wanted_unihash, extra_data)
714 hashequiv_logger.verbose('Reported task %s as unihash %s to %s (%s)' % (tid, wanted_unihash, self.server, str(data)))
715
716 if data is None:
717 bb.warn("Server unable to handle unihash report")
718 return False
719
720 finalunihash = data['unihash']
721
722 if finalunihash == current_unihash:
723 hashequiv_logger.verbose('Task %s unihash %s unchanged by server' % (tid, finalunihash))
724 elif finalunihash == wanted_unihash:
725 hashequiv_logger.verbose('Task %s unihash changed %s -> %s as wanted' % (tid, current_unihash, finalunihash))
726 self.set_unihash(tid, finalunihash)
727 return True
728 else:
729 # TODO: What to do here?
730 hashequiv_logger.verbose('Task %s unihash reported as unwanted hash %s' % (tid, finalunihash))
731
Andrew Geisslerc926e172021-05-07 16:11:35 -0500732 except ConnectionError as e:
Andrew Geissler82c905d2020-04-13 13:39:40 -0500733 bb.warn('Error contacting Hash Equivalence Server %s: %s' % (self.server, str(e)))
734
735 return False
Brad Bishop08902b02019-08-20 09:16:51 -0400736
737#
738# Dummy class used for bitbake-selftest
739#
740class SignatureGeneratorTestEquivHash(SignatureGeneratorUniHashMixIn, SignatureGeneratorBasicHash):
741 name = "TestEquivHash"
742 def init_rundepcheck(self, data):
743 super().init_rundepcheck(data)
Brad Bishopa34c0302019-09-23 22:34:48 -0400744 self.server = data.getVar('BB_HASHSERVE')
Brad Bishop08902b02019-08-20 09:16:51 -0400745 self.method = "sstate_output_hash"
746
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500747def dump_this_task(outfile, d):
748 import bb.parse
Andrew Geissler517393d2023-01-13 08:55:19 -0600749 mcfn = d.getVar("BB_FILENAME")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500750 task = "do_" + d.getVar("BB_CURRENTTASK")
Andrew Geissler517393d2023-01-13 08:55:19 -0600751 referencestamp = bb.parse.siggen.stampfile_base(mcfn)
752 bb.parse.siggen.dump_sigtask(mcfn, task, outfile, "customfile:" + referencestamp)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500753
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500754def init_colors(enable_color):
755 """Initialise colour dict for passing to compare_sigfiles()"""
756 # First set up the colours
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800757 colors = {'color_title': '\033[1m',
758 'color_default': '\033[0m',
759 'color_add': '\033[0;32m',
760 'color_remove': '\033[0;31m',
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500761 }
762 # Leave all keys present but clear the values
763 if not enable_color:
764 for k in colors.keys():
765 colors[k] = ''
766 return colors
767
768def worddiff_str(oldstr, newstr, colors=None):
769 if not colors:
770 colors = init_colors(False)
771 diff = simplediff.diff(oldstr.split(' '), newstr.split(' '))
772 ret = []
773 for change, value in diff:
774 value = ' '.join(value)
775 if change == '=':
776 ret.append(value)
777 elif change == '+':
778 item = '{color_add}{{+{value}+}}{color_default}'.format(value=value, **colors)
779 ret.append(item)
780 elif change == '-':
781 item = '{color_remove}[-{value}-]{color_default}'.format(value=value, **colors)
782 ret.append(item)
783 whitespace_note = ''
784 if oldstr != newstr and ' '.join(oldstr.split()) == ' '.join(newstr.split()):
785 whitespace_note = ' (whitespace changed)'
786 return '"%s"%s' % (' '.join(ret), whitespace_note)
787
788def list_inline_diff(oldlist, newlist, colors=None):
789 if not colors:
790 colors = init_colors(False)
791 diff = simplediff.diff(oldlist, newlist)
792 ret = []
793 for change, value in diff:
794 value = ' '.join(value)
795 if change == '=':
796 ret.append("'%s'" % value)
797 elif change == '+':
798 item = '{color_add}+{value}{color_default}'.format(value=value, **colors)
799 ret.append(item)
800 elif change == '-':
801 item = '{color_remove}-{value}{color_default}'.format(value=value, **colors)
802 ret.append(item)
803 return '[%s]' % (', '.join(ret))
804
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000805# Handled renamed fields
806def handle_renames(data):
807 if 'basewhitelist' in data:
808 data['basehash_ignore_vars'] = data['basewhitelist']
809 del data['basewhitelist']
810 if 'taskwhitelist' in data:
811 data['taskhash_ignore_tasks'] = data['taskwhitelist']
812 del data['taskwhitelist']
813
814
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500815def compare_sigfiles(a, b, recursecb=None, color=False, collapsed=False):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500816 output = []
817
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500818 colors = init_colors(color)
819 def color_format(formatstr, **values):
820 """
821 Return colour formatted string.
822 NOTE: call with the format string, not an already formatted string
823 containing values (otherwise you could have trouble with { and }
824 characters)
825 """
826 if not formatstr.endswith('{color_default}'):
827 formatstr += '{color_default}'
828 # In newer python 3 versions you can pass both of these directly,
829 # but we only require 3.4 at the moment
830 formatparams = {}
831 formatparams.update(colors)
832 formatparams.update(values)
833 return formatstr.format(**formatparams)
834
Andrew Geisslereff27472021-10-29 15:35:00 -0500835 with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f:
836 a_data = json.load(f, object_hook=SetDecoder)
837 with bb.compress.zstd.open(b, "rt", encoding="utf-8", num_threads=1) as f:
838 b_data = json.load(f, object_hook=SetDecoder)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500839
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000840 for data in [a_data, b_data]:
841 handle_renames(data)
842
843 def dict_diff(a, b, ignored_vars=set()):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500844 sa = set(a.keys())
845 sb = set(b.keys())
846 common = sa & sb
847 changed = set()
848 for i in common:
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000849 if a[i] != b[i] and i not in ignored_vars:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500850 changed.add(i)
851 added = sb - sa
852 removed = sa - sb
853 return changed, added, removed
854
855 def file_checksums_diff(a, b):
856 from collections import Counter
Andrew Geisslereff27472021-10-29 15:35:00 -0500857
858 # Convert lists back to tuples
859 a = [(f[0], f[1]) for f in a]
860 b = [(f[0], f[1]) for f in b]
861
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500862 # Compare lists, ensuring we can handle duplicate filenames if they exist
863 removedcount = Counter(a)
864 removedcount.subtract(b)
865 addedcount = Counter(b)
866 addedcount.subtract(a)
867 added = []
868 for x in b:
869 if addedcount[x] > 0:
870 addedcount[x] -= 1
871 added.append(x)
872 removed = []
873 changed = []
874 for x in a:
875 if removedcount[x] > 0:
876 removedcount[x] -= 1
877 for y in added:
878 if y[0] == x[0]:
879 changed.append((x[0], x[1], y[1]))
880 added.remove(y)
881 break
882 else:
883 removed.append(x)
884 added = [x[0] for x in added]
885 removed = [x[0] for x in removed]
886 return changed, added, removed
887
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000888 if 'basehash_ignore_vars' in a_data and a_data['basehash_ignore_vars'] != b_data['basehash_ignore_vars']:
889 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']))
890 if a_data['basehash_ignore_vars'] and b_data['basehash_ignore_vars']:
891 output.append("changed items: %s" % a_data['basehash_ignore_vars'].symmetric_difference(b_data['basehash_ignore_vars']))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500892
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000893 if 'taskhash_ignore_tasks' in a_data and a_data['taskhash_ignore_tasks'] != b_data['taskhash_ignore_tasks']:
894 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']))
895 if a_data['taskhash_ignore_tasks'] and b_data['taskhash_ignore_tasks']:
896 output.append("changed items: %s" % a_data['taskhash_ignore_tasks'].symmetric_difference(b_data['taskhash_ignore_tasks']))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500897
898 if a_data['taskdeps'] != b_data['taskdeps']:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500899 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 Williamsc124f4f2015-09-15 14:41:29 -0500900
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500901 if a_data['basehash'] != b_data['basehash'] and not collapsed:
902 output.append(color_format("{color_title}basehash changed{color_default} from %s to %s") % (a_data['basehash'], b_data['basehash']))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500903
Andrew Geissler7e0e3c02022-02-25 20:34:39 +0000904 changed, added, removed = dict_diff(a_data['gendeps'], b_data['gendeps'], a_data['basehash_ignore_vars'] & b_data['basehash_ignore_vars'])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500905 if changed:
Patrick Williams93c203f2021-10-06 16:15:23 -0500906 for dep in sorted(changed):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500907 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 Williamsc124f4f2015-09-15 14:41:29 -0500908 if a_data['gendeps'][dep] and b_data['gendeps'][dep]:
909 output.append("changed items: %s" % a_data['gendeps'][dep].symmetric_difference(b_data['gendeps'][dep]))
910 if added:
Patrick Williams93c203f2021-10-06 16:15:23 -0500911 for dep in sorted(added):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500912 output.append(color_format("{color_title}Dependency on variable %s was added") % (dep))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500913 if removed:
Patrick Williams93c203f2021-10-06 16:15:23 -0500914 for dep in sorted(removed):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500915 output.append(color_format("{color_title}Dependency on Variable %s was removed") % (dep))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500916
917
918 changed, added, removed = dict_diff(a_data['varvals'], b_data['varvals'])
919 if changed:
Patrick Williams93c203f2021-10-06 16:15:23 -0500920 for dep in sorted(changed):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500921 oldval = a_data['varvals'][dep]
922 newval = b_data['varvals'][dep]
923 if newval and oldval and ('\n' in oldval or '\n' in newval):
924 diff = difflib.unified_diff(oldval.splitlines(), newval.splitlines(), lineterm='')
925 # Cut off the first two lines, since we aren't interested in
926 # the old/new filename (they are blank anyway in this case)
927 difflines = list(diff)[2:]
928 if color:
929 # Add colour to diff output
930 for i, line in enumerate(difflines):
931 if line.startswith('+'):
932 line = color_format('{color_add}{line}', line=line)
933 difflines[i] = line
934 elif line.startswith('-'):
935 line = color_format('{color_remove}{line}', line=line)
936 difflines[i] = line
937 output.append(color_format("{color_title}Variable {var} value changed:{color_default}\n{diff}", var=dep, diff='\n'.join(difflines)))
938 elif newval and oldval and (' ' in oldval or ' ' in newval):
939 output.append(color_format("{color_title}Variable {var} value changed:{color_default}\n{diff}", var=dep, diff=worddiff_str(oldval, newval, colors)))
940 else:
941 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 Williamsc124f4f2015-09-15 14:41:29 -0500942
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600943 if not 'file_checksum_values' in a_data:
Andrew Geisslereff27472021-10-29 15:35:00 -0500944 a_data['file_checksum_values'] = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600945 if not 'file_checksum_values' in b_data:
Andrew Geisslereff27472021-10-29 15:35:00 -0500946 b_data['file_checksum_values'] = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600947
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500948 changed, added, removed = file_checksums_diff(a_data['file_checksum_values'], b_data['file_checksum_values'])
949 if changed:
950 for f, old, new in changed:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500951 output.append(color_format("{color_title}Checksum for file %s changed{color_default} from %s to %s") % (f, old, new))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500952 if added:
953 for f in added:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500954 output.append(color_format("{color_title}Dependency on checksum of file %s was added") % (f))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500955 if removed:
956 for f in removed:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500957 output.append(color_format("{color_title}Dependency on checksum of file %s was removed") % (f))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500958
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600959 if not 'runtaskdeps' in a_data:
960 a_data['runtaskdeps'] = {}
961 if not 'runtaskdeps' in b_data:
962 b_data['runtaskdeps'] = {}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500963
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500964 if not collapsed:
965 if len(a_data['runtaskdeps']) != len(b_data['runtaskdeps']):
966 changed = ["Number of task dependencies changed"]
967 else:
968 changed = []
969 for idx, task in enumerate(a_data['runtaskdeps']):
970 a = a_data['runtaskdeps'][idx]
971 b = b_data['runtaskdeps'][idx]
972 if a_data['runtaskhashes'][a] != b_data['runtaskhashes'][b] and not collapsed:
Patrick Williams2a254922023-08-11 09:48:11 -0500973 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 Williamsc124f4f2015-09-15 14:41:29 -0500974
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500975 if changed:
Patrick Williams2a254922023-08-11 09:48:11 -0500976 clean_a = a_data['runtaskdeps']
977 clean_b = b_data['runtaskdeps']
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500978 if clean_a != clean_b:
979 output.append(color_format("{color_title}runtaskdeps changed:{color_default}\n%s") % list_inline_diff(clean_a, clean_b, colors))
980 else:
981 output.append(color_format("{color_title}runtaskdeps changed:"))
982 output.append("\n".join(changed))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500983
984
985 if 'runtaskhashes' in a_data and 'runtaskhashes' in b_data:
Patrick Williams2a254922023-08-11 09:48:11 -0500986 a = a_data['runtaskhashes']
987 b = b_data['runtaskhashes']
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500988 changed, added, removed = dict_diff(a, b)
989 if added:
Patrick Williams93c203f2021-10-06 16:15:23 -0500990 for dep in sorted(added):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500991 bdep_found = False
992 if removed:
993 for bdep in removed:
994 if b[dep] == a[bdep]:
995 #output.append("Dependency on task %s was replaced by %s with same hash" % (dep, bdep))
996 bdep_found = True
997 if not bdep_found:
Patrick Williams03907ee2022-05-01 06:28:52 -0500998 output.append(color_format("{color_title}Dependency on task %s was added{color_default} with hash %s") % (dep, b[dep]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500999 if removed:
Patrick Williams93c203f2021-10-06 16:15:23 -05001000 for dep in sorted(removed):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001001 adep_found = False
1002 if added:
1003 for adep in added:
1004 if b[adep] == a[dep]:
1005 #output.append("Dependency on task %s was replaced by %s with same hash" % (adep, dep))
1006 adep_found = True
1007 if not adep_found:
Patrick Williams03907ee2022-05-01 06:28:52 -05001008 output.append(color_format("{color_title}Dependency on task %s was removed{color_default} with hash %s") % (dep, a[dep]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001009 if changed:
Patrick Williams93c203f2021-10-06 16:15:23 -05001010 for dep in sorted(changed):
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001011 if not collapsed:
Patrick Williams03907ee2022-05-01 06:28:52 -05001012 output.append(color_format("{color_title}Hash for task dependency %s changed{color_default} from %s to %s") % (dep, a[dep], b[dep]))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001013 if callable(recursecb):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001014 recout = recursecb(dep, a[dep], b[dep])
1015 if recout:
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001016 if collapsed:
1017 output.extend(recout)
1018 else:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001019 # If a dependent hash changed, might as well print the line above and then defer to the changes in
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001020 # that hash since in all likelyhood, they're the same changes this task also saw.
1021 output = [output[-1]] + recout
Andrew Geisslerd5838332022-05-27 11:33:10 -05001022 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001023
1024 a_taint = a_data.get('taint', None)
1025 b_taint = b_data.get('taint', None)
1026 if a_taint != b_taint:
Brad Bishop96ff1982019-08-19 13:50:42 -04001027 if a_taint and a_taint.startswith('nostamp:'):
Brad Bishopc342db32019-05-15 21:57:59 -04001028 a_taint = a_taint.replace('nostamp:', 'nostamp(uuid4):')
Brad Bishop96ff1982019-08-19 13:50:42 -04001029 if b_taint and b_taint.startswith('nostamp:'):
Brad Bishopc342db32019-05-15 21:57:59 -04001030 b_taint = b_taint.replace('nostamp:', 'nostamp(uuid4):')
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001031 output.append(color_format("{color_title}Taint (by forced/invalidated task) changed{color_default} from %s to %s") % (a_taint, b_taint))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001032
1033 return output
1034
1035
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001036def calc_basehash(sigdata):
1037 task = sigdata['task']
1038 basedata = sigdata['varvals'][task]
1039
1040 if basedata is None:
1041 basedata = ''
1042
1043 alldeps = sigdata['taskdeps']
Andrew Geissler517393d2023-01-13 08:55:19 -06001044 for dep in sorted(alldeps):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001045 basedata = basedata + dep
1046 val = sigdata['varvals'][dep]
1047 if val is not None:
1048 basedata = basedata + str(val)
1049
Brad Bishop19323692019-04-05 15:28:33 -04001050 return hashlib.sha256(basedata.encode("utf-8")).hexdigest()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001051
1052def calc_taskhash(sigdata):
1053 data = sigdata['basehash']
1054
1055 for dep in sigdata['runtaskdeps']:
1056 data = data + sigdata['runtaskhashes'][dep]
1057
1058 for c in sigdata['file_checksum_values']:
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001059 if c[1]:
Andrew Geissler595f6302022-01-24 19:11:47 +00001060 if "./" in c[0]:
1061 data = data + c[0]
Brad Bishop37a0e4d2017-12-04 01:01:44 -05001062 data = data + c[1]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001063
1064 if 'taint' in sigdata:
1065 if 'nostamp:' in sigdata['taint']:
1066 data = data + sigdata['taint'][8:]
1067 else:
1068 data = data + sigdata['taint']
1069
Brad Bishop19323692019-04-05 15:28:33 -04001070 return hashlib.sha256(data.encode("utf-8")).hexdigest()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001071
1072
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001073def dump_sigfile(a):
1074 output = []
1075
Andrew Geisslereff27472021-10-29 15:35:00 -05001076 with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f:
1077 a_data = json.load(f, object_hook=SetDecoder)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001078
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001079 handle_renames(a_data)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001080
Andrew Geissler7e0e3c02022-02-25 20:34:39 +00001081 output.append("basehash_ignore_vars: %s" % (sorted(a_data['basehash_ignore_vars'])))
1082
1083 output.append("taskhash_ignore_tasks: %s" % (sorted(a_data['taskhash_ignore_tasks'] or [])))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001084
1085 output.append("Task dependencies: %s" % (sorted(a_data['taskdeps'])))
1086
1087 output.append("basehash: %s" % (a_data['basehash']))
1088
Andrew Geissler595f6302022-01-24 19:11:47 +00001089 for dep in sorted(a_data['gendeps']):
1090 output.append("List of dependencies for variable %s is %s" % (dep, sorted(a_data['gendeps'][dep])))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001091
Andrew Geissler595f6302022-01-24 19:11:47 +00001092 for dep in sorted(a_data['varvals']):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001093 output.append("Variable %s value is %s" % (dep, a_data['varvals'][dep]))
1094
1095 if 'runtaskdeps' in a_data:
Andrew Geissler595f6302022-01-24 19:11:47 +00001096 output.append("Tasks this task depends on: %s" % (sorted(a_data['runtaskdeps'])))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001097
1098 if 'file_checksum_values' in a_data:
Andrew Geissler595f6302022-01-24 19:11:47 +00001099 output.append("This task depends on the checksums of files: %s" % (sorted(a_data['file_checksum_values'])))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001100
1101 if 'runtaskhashes' in a_data:
Andrew Geissler595f6302022-01-24 19:11:47 +00001102 for dep in sorted(a_data['runtaskhashes']):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001103 output.append("Hash for dependent task %s is %s" % (dep, a_data['runtaskhashes'][dep]))
1104
1105 if 'taint' in a_data:
Brad Bishopc342db32019-05-15 21:57:59 -04001106 if a_data['taint'].startswith('nostamp:'):
1107 msg = a_data['taint'].replace('nostamp:', 'nostamp(uuid4):')
1108 else:
1109 msg = a_data['taint']
1110 output.append("Tainted (by forced/invalidated task): %s" % msg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001111
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001112 if 'task' in a_data:
1113 computed_basehash = calc_basehash(a_data)
1114 output.append("Computed base hash is %s and from file %s" % (computed_basehash, a_data['basehash']))
1115 else:
1116 output.append("Unable to compute base hash")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001117
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001118 computed_taskhash = calc_taskhash(a_data)
1119 output.append("Computed task hash is %s" % computed_taskhash)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001120
1121 return output