From 3ee5c86da3773deb091e24b98ad592c5d19274fb Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Wed, 6 Dec 2023 22:44:22 +0000 Subject: bitbake: toaster-eventreplay: Remove ordering assumptions Currently the script assumes the variarables are dumped at the start of the file which is hard to arrange safely in the bitbake code and no longer a true assumption. Rewrite the code so that it can cope with different ordering and event files containing multiple builds. (Bitbake rev: a833a403a8f7c05008108f3ec1710c211cfa9ec2) Signed-off-by: Richard Purdie --- bitbake/bin/toaster-eventreplay | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'bitbake/bin/toaster-eventreplay') diff --git a/bitbake/bin/toaster-eventreplay b/bitbake/bin/toaster-eventreplay index 404b61f516..f137c71d5c 100755 --- a/bitbake/bin/toaster-eventreplay +++ b/bitbake/bin/toaster-eventreplay @@ -45,7 +45,13 @@ class EventPlayer: if not line: return try: - event_str = json.loads(line)['vars'].encode('utf-8') + decodedline = json.loads(line) + if 'allvariables' in decodedline: + self.variables = decodedline['allvariables'] + return + if not 'vars' in decodedline: + raise ValueError + event_str = decodedline['vars'].encode('utf-8') event = pickle.loads(codecs.decode(event_str, 'base64')) event_name = "%s.%s" % (event.__module__, event.__class__.__name__) if event_name not in self.eventmask: @@ -99,8 +105,16 @@ class EventPlayer: def main(argv): with open(argv[-1]) as eventfile: # load variables from the first line - variables = json.loads(eventfile.readline().strip())['allvariables'] - + variables = None + while line := eventfile.readline().strip(): + try: + variables = json.loads(line)['allvariables'] + break + except (KeyError, json.JSONDecodeError): + continue + if not variables: + sys.exit("Cannot find allvariables entry in event log file %s" % argv[-1]) + eventfile.seek(0) params = namedtuple('ConfigParams', ['observe_only'])(True) player = EventPlayer(eventfile, variables) -- cgit v1.2.3-54-g00ecf