summaryrefslogtreecommitdiffstats
path: root/scripts/lib/compatlayer/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/compatlayer/__init__.py')
-rw-r--r--scripts/lib/compatlayer/__init__.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/lib/compatlayer/__init__.py b/scripts/lib/compatlayer/__init__.py
index 451e1de950..7197e850e4 100644
--- a/scripts/lib/compatlayer/__init__.py
+++ b/scripts/lib/compatlayer/__init__.py
@@ -324,3 +324,69 @@ def get_depgraph(targets=['world'], failsafe=False):
324 if depgraph is None: 324 if depgraph is None:
325 raise RuntimeError('Could not retrieve the depgraph.') 325 raise RuntimeError('Could not retrieve the depgraph.')
326 return depgraph 326 return depgraph
327
328def compare_signatures(old_sigs, curr_sigs):
329 '''
330 Compares the result of two get_signatures() calls. Returns None if no
331 problems found, otherwise a string that can be used as additional
332 explanation in self.fail().
333 '''
334 # task -> (old signature, new signature)
335 sig_diff = {}
336 for task in old_sigs:
337 if task in curr_sigs and \
338 old_sigs[task] != curr_sigs[task]:
339 sig_diff[task] = (old_sigs[task], curr_sigs[task])
340
341 if not sig_diff:
342 return None
343
344 # Beware, depgraph uses task=<pn>.<taskname> whereas get_signatures()
345 # uses <pn>:<taskname>. Need to convert sometimes. The output follows
346 # the convention from get_signatures() because that seems closer to
347 # normal bitbake output.
348 def sig2graph(task):
349 pn, taskname = task.rsplit(':', 1)
350 return pn + '.' + taskname
351 def graph2sig(task):
352 pn, taskname = task.rsplit('.', 1)
353 return pn + ':' + taskname
354 depgraph = get_depgraph(failsafe=True)
355 depends = depgraph['tdepends']
356
357 # If a task A has a changed signature, but none of its
358 # dependencies, then we need to report it because it is
359 # the one which introduces a change. Any task depending on
360 # A (directly or indirectly) will also have a changed
361 # signature, but we don't need to report it. It might have
362 # its own changes, which will become apparent once the
363 # issues that we do report are fixed and the test gets run
364 # again.
365 sig_diff_filtered = []
366 for task, (old_sig, new_sig) in sig_diff.items():
367 deps_tainted = False
368 for dep in depends.get(sig2graph(task), ()):
369 if graph2sig(dep) in sig_diff:
370 deps_tainted = True
371 break
372 if not deps_tainted:
373 sig_diff_filtered.append((task, old_sig, new_sig))
374
375 msg = []
376 msg.append('%d signatures changed, initial differences (first hash before, second after):' %
377 len(sig_diff))
378 for diff in sorted(sig_diff_filtered):
379 recipe, taskname = diff[0].rsplit(':', 1)
380 cmd = 'bitbake-diffsigs --task %s %s --signature %s %s' % \
381 (recipe, taskname, diff[1], diff[2])
382 msg.append(' %s: %s -> %s' % diff)
383 msg.append(' %s' % cmd)
384 try:
385 output = check_command('Determining signature difference failed.',
386 cmd).decode('utf-8')
387 except RuntimeError as error:
388 output = str(error)
389 if output:
390 msg.extend([' ' + line for line in output.splitlines()])
391 msg.append('')
392 return '\n'.join(msg)