Skip to content

Commit

Permalink
bitbake: siggen: Change file format of siginfo files to use zstd comp…
Browse files Browse the repository at this point in the history
…ressed 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: b530e42ef01b9531c67fb260884fb89d096687a8)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
  • Loading branch information
rpurdie committed Oct 13, 2021
1 parent 1212dff commit 821d108
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions bitbake/lib/bb/siggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import bb.data
import difflib
import simplediff
import json
import bb.compress.zstd
from bb.checksum import FileChecksumCache
from bb import runqueue
import hashserv
Expand All @@ -19,6 +21,12 @@
logger = logging.getLogger('BitBake.SigGen')
hashequiv_logger = logging.getLogger('BitBake.SigGen.HashEquiv')

class SetEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, set):
return list(sorted(obj))
return json.JSONEncoder.default(self, obj)

def init(d):
siggens = [obj for obj in globals().values()
if type(obj) is type and issubclass(obj, SignatureGenerator)]
Expand Down Expand Up @@ -398,9 +406,9 @@ def dump_sigtask(self, fn, task, stampbase, runtime):

fd, tmpfile = tempfile.mkstemp(dir=os.path.dirname(sigfile), prefix="sigtask.")
try:
with os.fdopen(fd, "wb") as stream:
p = pickle.dump(data, stream, -1)
stream.flush()
with bb.compress.zstd.open(fd, "wt", encoding="utf-8", num_threads=1) as f:
json.dump(data, f, sort_keys=True, separators=(",", ":"), cls=SetEncoder)
f.flush()
os.chmod(tmpfile, 0o664)
bb.utils.rename(tmpfile, sigfile)
except (OSError, IOError) as err:
Expand Down Expand Up @@ -794,12 +802,10 @@ def color_format(formatstr, **values):
formatparams.update(values)
return formatstr.format(**formatparams)

with open(a, 'rb') as f:
p1 = pickle.Unpickler(f)
a_data = p1.load()
with open(b, 'rb') as f:
p2 = pickle.Unpickler(f)
b_data = p2.load()
with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f:
a_data = json.load(f)
with bb.compress.zstd.open(b, "rt", encoding="utf-8", num_threads=1) as f:
b_data = json.load(f)

def dict_diff(a, b, whitelist=set()):
sa = set(a.keys())
Expand Down Expand Up @@ -1031,9 +1037,8 @@ def calc_taskhash(sigdata):
def dump_sigfile(a):
output = []

with open(a, 'rb') as f:
p1 = pickle.Unpickler(f)
a_data = p1.load()
with bb.compress.zstd.open(a, "rt", encoding="utf-8", num_threads=1) as f:
a_data = json.load(f)

output.append("basewhitelist: %s" % (a_data['basewhitelist']))

Expand Down

0 comments on commit 821d108

Please sign in to comment.