Skip to contentSkip to conversation

bitbake-diffsigs: fix walking the task dependencies and show better error

PATCH Martin Jansa 1 participant 1 message Feb 5, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

The bitbake-diffsigs issue was introduced in:
https://git.openembedded.org/openembedded-core/commit/?id=8721c52041e910bd4d8a9235b52f274f4f02c8a3
other parts of the code were adapted to new find_siginfo code long time ago, not sure why this one kept hiding.

Quoted 149 lines · Martin Jansa via lists.openembedded.org

* when comparing 2 tmp/stamps/*do_configure.sigdata* I got TypeError("filename must be a str or bytes object, or a file") but both files I was comparing were
Zstandard compressed data (v0.8+), Dictionary ID: None according to "file"

with TypeError catched to show which file it failed to open I got better error which shows it was trying to read
"do_prepare_recipe_sysroot.sigdata"
file now and after a while you might notice that it's not just the
expected
file, but a dict with 'path', 'sstate', 'time'.

Fix that in bitbake-diffsigs but keep the TypeError and add OSError in case it will eventually walk on file which isn't zstd compressed pipecompress throws CompressionError.

ERROR: Failed to open {'path':
'5.15.do_prepare_recipe_sysroot.sigdata.99b12a401341a0df7c3553cb00c87a7674295496bd5c25ed71764ee0d0fb8eb8', 'sstate': False, 'time': 1707136354.991718}: filename must be a str or
bytes object, or a file
Traceback (most recent call last):
File "bitbake/bin/bitbake-diffsigs", line 192, in <module>
output = bb.siggen.compare_sigfiles(options.sigdatafile1,
options.sigdatafile2, recursecb, color=color)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "bitbake/lib/bb/siggen.py", line 1039, in compare_sigfiles
recout = recursecb(dep, a[dep], b[dep])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "bitbake/bin/bitbake-diffsigs", line 102, in recursecb
out2 = bb.siggen.compare_sigfiles(hashfiles[hash1], hashfiles[hash2],
recursecb, color=color)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "bitbake/lib/bb/siggen.py", line 857, in compare_sigfiles
raise err
File "bitbake/lib/bb/siggen.py", line 853, in compare_sigfiles

    with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1)
as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "bitbake/lib/bb/compress/zstd.py", line 12, in open
return bb.compress._pipecompress.open_wrap(ZstdFile, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "bitbake/lib/bb/compress/_pipecompress.py", line 59, in open_wrap
raise TypeError("filename must be a str or bytes object, or a file")
TypeError: filename must be a str or bytes object, or a file

* if I replace zstd file with just plaintext it fails with:

  $ echo foo > foo
  $ echo foo > bar
  $ bitbake-diffsigs foo bar
  zstd: /*stdin*\: unsupported format
  ERROR: Process died with 1
  sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='foo'>

with this change it shows the name of the file which it failed to
uncompress:

  $ bitbake-diffsigs foo bar
  zstd: /*stdin*\: unsupported format
  ERROR: Failed to open sigdata file 'foo': Process died with 1
  ERROR: Process died with 1
  sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='foo'>
---
 bin/bitbake-diffsigs |  2 +-
 lib/bb/siggen.py     | 24 ++++++++++++++++++------
 2 files changed, 19 insertions(+), 7 deletions(-)
bin/bitbake-diffsigs +1 -1
index a8f49191b..8202c7862 100755
@@ -99,7 +99,7 @@ def recursecb(key, hash1, hash2):
     elif hash2 not in hashfiles:
         recout.append("Unable to find matching sigdata for %s with hash
 %s" % (key, hash2))
     else:
-        out2 = bb.siggen.compare_sigfiles(hashfiles[hash1],
 hashfiles[hash2], recursecb, color=color)
+        out2 = bb.siggen.compare_sigfiles(hashfiles[hash1]['path'],
 hashfiles[hash2]['path'], recursecb, color=color)

for change in out2:
for line in change.splitlines():
recout.append(' ' + line)

lib/bb/siggen.py +0 -0
index 5a584cadf..58854aee7 100644
@@ -849,10 +849,18 @@ def compare_sigfiles(a, b, recursecb=None,

color=False, collapsed=False):
formatparams.update(values)
return formatstr.format(**formatparams)

- with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1)
as f:

lib/bb/siggen.py +0 -2
-        a_data = json.load(f, object_hook=SetDecoder)
-    with bb.compress.zstd.open(b, "rt", encoding="utf-8", num_threads=1)

as f:

lib/bb/siggen.py +2 -1
-        b_data = json.load(f, object_hook=SetDecoder)
+    try:
+        with bb.compress.zstd.open(a, "rt", encoding="utf-8",

num_threads=1) as f:

lib/bb/siggen.py +6 -0
+            a_data = json.load(f, object_hook=SetDecoder)
+    except (TypeError, OSError) as err:
+        bb.error("Failed to open sigdata file '%s': %s" % (a, str(err)))
+        raise err
+    try:
+        with bb.compress.zstd.open(b, "rt", encoding="utf-8",

num_threads=1) as f:

lib/bb/siggen.py +4 -1
+            b_data = json.load(f, object_hook=SetDecoder)
+    except (TypeError, OSError) as err:
+        bb.error("Failed to open sigdata file '%s': %s" % (b, str(err)))
+        raise err
 
     for data in [a_data, b_data]:
         handle_renames(data)
@@ -1090,8 +1098,12 @@ def calc_taskhash(sigdata):
 def dump_sigfile(a):
     output = []
 
-    with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1)

as f:

lib/bb/siggen.py +2 -1
-        a_data = json.load(f, object_hook=SetDecoder)
+    try:
+        with bb.compress.zstd.open(a, "rt", encoding="utf-8",

num_threads=1) as f:

lib/bb/siggen.py +4 -1
+            a_data = json.load(f, object_hook=SetDecoder)
+    except (TypeError, OSError) as err:
+        bb.error("Failed to open sigdata file '%s': %s" % (a, str(err)))
+        raise err
 
     handle_renames(a_data)
 
--

2.43.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#15824):
https://lists.openembedded.org/g/bitbake-devel/message/15824
Mute This Topic: https://lists.openembedded.org/mt/104178376/3617156
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-