diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-13 16:11:40 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-14 22:37:43 +0100 |
commit | 4c33a6e52be775265c871aa2d3b87ed23a0d48da (patch) | |
tree | 56c7987ca538f8a29f3860267e803bf3b5e65fc3 /bitbake | |
parent | d080eaa163620c29848f2311064dd919c051234c (diff) | |
download | poky-4c33a6e52be775265c871aa2d3b87ed23a0d48da.tar.gz |
bitbake: siggen: Change file format of siginfo files to use zstd compressed json
Since OE is about to change to zstd compression of sstate, it would make it
timely to convert the siginfo files from pickle which isn't reproducible
to json which is both reproducible and also human readable. At the same time
add zstd compression. This makes the siginfo files smaller, reprodubicle
and easier to debug.
Backwards compatibility mixing the two formats hasn't been supported since
in reality if sstate changes at the same time, files will be in one format
or the new one but comparing mixed formats won't make much sense.
Since json doesn't support sets, we translate them into lists in the files
themselves. We only use sets in bitbake since it makes things easier in
the internal code, sorted lists are fine for the file format.
[YOCTO #13973]
(Bitbake rev: 22c18494c9072788e6e26eb73de70378ae5c5bf5)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/siggen.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/bitbake/lib/bb/siggen.py b/bitbake/lib/bb/siggen.py index 625a9cf3bb..f526792efd 100644 --- a/bitbake/lib/bb/siggen.py +++ b/bitbake/lib/bb/siggen.py | |||
@@ -11,6 +11,8 @@ import pickle | |||
11 | import bb.data | 11 | import bb.data |
12 | import difflib | 12 | import difflib |
13 | import simplediff | 13 | import simplediff |
14 | import json | ||
15 | import bb.compress.zstd | ||
14 | from bb.checksum import FileChecksumCache | 16 | from bb.checksum import FileChecksumCache |
15 | from bb import runqueue | 17 | from bb import runqueue |
16 | import hashserv | 18 | import hashserv |
@@ -19,6 +21,12 @@ import hashserv.client | |||
19 | logger = logging.getLogger('BitBake.SigGen') | 21 | logger = logging.getLogger('BitBake.SigGen') |
20 | hashequiv_logger = logging.getLogger('BitBake.SigGen.HashEquiv') | 22 | hashequiv_logger = logging.getLogger('BitBake.SigGen.HashEquiv') |
21 | 23 | ||
24 | class SetEncoder(json.JSONEncoder): | ||
25 | def default(self, obj): | ||
26 | if isinstance(obj, set): | ||
27 | return list(sorted(obj)) | ||
28 | return json.JSONEncoder.default(self, obj) | ||
29 | |||
22 | def init(d): | 30 | def init(d): |
23 | siggens = [obj for obj in globals().values() | 31 | siggens = [obj for obj in globals().values() |
24 | if type(obj) is type and issubclass(obj, SignatureGenerator)] | 32 | if type(obj) is type and issubclass(obj, SignatureGenerator)] |
@@ -398,9 +406,9 @@ class SignatureGeneratorBasic(SignatureGenerator): | |||
398 | 406 | ||
399 | fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.") | 407 | fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.") |
400 | try: | 408 | try: |
401 | with os.fdopen(fd, "wb") as stream: | 409 | with bb.compress.zstd.open(fd, "wt", encoding="utf-8", num_threads=1) as f: |
402 | p = pickle.dump(data, stream, -1) | 410 | json.dump(data, f, sort_keys=True, separators=(",", ":"), cls=SetEncoder) |
403 | stream.flush() | 411 | f.flush() |
404 | os.chmod(tmpfile, 0o664) | 412 | os.chmod(tmpfile, 0o664) |
405 | bb.utils.rename(tmpfile, sigfile) | 413 | bb.utils.rename(tmpfile, sigfile) |
406 | except (OSError, IOError) as err: | 414 | except (OSError, IOError) as err: |
@@ -794,12 +802,10 @@ def compare_sigfiles(a, b, recursecb=None, color=False, collapsed=False): | |||
794 | formatparams.update(values) | 802 | formatparams.update(values) |
795 | return formatstr.format(**formatparams) | 803 | return formatstr.format(**formatparams) |
796 | 804 | ||
797 | with open(a, 'rb') as f: | 805 | with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f: |
798 | p1 = pickle.Unpickler(f) | 806 | a_data = json.load(f) |
799 | a_data = p1.load() | 807 | with bb.compress.zstd.open(b, "rt", encoding="utf-8", num_threads=1) as f: |
800 | with open(b, 'rb') as f: | 808 | b_data = json.load(f) |
801 | p2 = pickle.Unpickler(f) | ||
802 | b_data = p2.load() | ||
803 | 809 | ||
804 | def dict_diff(a, b, whitelist=set()): | 810 | def dict_diff(a, b, whitelist=set()): |
805 | sa = set(a.keys()) | 811 | sa = set(a.keys()) |
@@ -1031,9 +1037,8 @@ def calc_taskhash(sigdata): | |||
1031 | def dump_sigfile(a): | 1037 | def dump_sigfile(a): |
1032 | output = [] | 1038 | output = [] |
1033 | 1039 | ||
1034 | with open(a, 'rb') as f: | 1040 | with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f: |
1035 | p1 = pickle.Unpickler(f) | 1041 | a_data = json.load(f) |
1036 | a_data = p1.load() | ||
1037 | 1042 | ||
1038 | output.append("basewhitelist: %s" % (a_data['basewhitelist'])) | 1043 | output.append("basewhitelist: %s" % (a_data['basewhitelist'])) |
1039 | 1044 | ||