diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-16 09:05:41 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-16 17:43:02 +0100 |
commit | 2d704842c0928f8dbe78fd081042aa7280af96be (patch) | |
tree | 937fb64d98fbd286e5768f7c70e7c3b48e864d32 | |
parent | fe8105cc06beca8240b76ea366a1eff5aa9c5412 (diff) | |
download | bitbake-2d704842c0928f8dbe78fd081042aa7280af96be.tar.gz |
siggen: Fix type conversion issues
The switch to using json has messed up the type handling as the code
does assume that set()s are present. Add a decoder to reconstruct
the set() objects. Also fix the change of tuples to lists for the
file checksums and fix an existing type bug where dicts insteads of
lists was used.
Drop some old siginfo format handling code which is now long since
obsolete.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | lib/bb/siggen.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/bb/siggen.py b/lib/bb/siggen.py index f526792ef..578ba5d66 100644 --- a/lib/bb/siggen.py +++ b/lib/bb/siggen.py @@ -24,9 +24,14 @@ hashequiv_logger = logging.getLogger('BitBake.SigGen.HashEquiv') class SetEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, set): - return list(sorted(obj)) + return dict(_set_object=list(sorted(obj))) return json.JSONEncoder.default(self, obj) +def SetDecoder(dct): + if '_set_object' in dct: + return set(dct['_set_object']) + return dct + def init(d): siggens = [obj for obj in globals().values() if type(obj) is type and issubclass(obj, SignatureGenerator)] @@ -803,9 +808,9 @@ def compare_sigfiles(a, b, recursecb=None, color=False, collapsed=False): return formatstr.format(**formatparams) with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f: - a_data = json.load(f) + a_data = json.load(f, object_hook=SetDecoder) with bb.compress.zstd.open(b, "rt", encoding="utf-8", num_threads=1) as f: - b_data = json.load(f) + b_data = json.load(f, object_hook=SetDecoder) def dict_diff(a, b, whitelist=set()): sa = set(a.keys()) @@ -821,11 +826,11 @@ def compare_sigfiles(a, b, recursecb=None, color=False, collapsed=False): def file_checksums_diff(a, b): from collections import Counter - # Handle old siginfo format - if isinstance(a, dict): - a = [(os.path.basename(f), cs) for f, cs in a.items()] - if isinstance(b, dict): - b = [(os.path.basename(f), cs) for f, cs in b.items()] + + # Convert lists back to tuples + a = [(f[0], f[1]) for f in a] + b = [(f[0], f[1]) for f in b] + # Compare lists, ensuring we can handle duplicate filenames if they exist removedcount = Counter(a) removedcount.subtract(b) @@ -908,9 +913,9 @@ def compare_sigfiles(a, b, recursecb=None, color=False, collapsed=False): 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)) if not 'file_checksum_values' in a_data: - a_data['file_checksum_values'] = {} + a_data['file_checksum_values'] = [] if not 'file_checksum_values' in b_data: - b_data['file_checksum_values'] = {} + b_data['file_checksum_values'] = [] changed, added, removed = file_checksums_diff(a_data['file_checksum_values'], b_data['file_checksum_values']) if changed: @@ -1038,7 +1043,7 @@ def dump_sigfile(a): output = [] with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f: - a_data = json.load(f) + a_data = json.load(f, object_hook=SetDecoder) output.append("basewhitelist: %s" % (a_data['basewhitelist'])) |