From: Daan De Meyer Date: Wed, 26 Feb 2025 11:08:55 +0000 (+0100) Subject: Save all images to history JSON X-Git-Tag: v26~348^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be9e147f10cb01ced10a164cb528f3d34eea86c8;p=thirdparty%2Fmkosi.git Save all images to history JSON Preparation for the upcoming commit where we'll need all the images instead of just the main one when reading the history. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 8a4607265..66d41b8c2 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -5224,7 +5224,14 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: if last.history: Path(".mkosi-private/history").mkdir(parents=True, exist_ok=True) - Path(".mkosi-private/history/latest.json").write_text(last.to_json()) + Path(".mkosi-private/history/latest.json").write_text( + json.dumps( + {"Images": [config.to_dict() for config in images]}, + cls=JsonEncoder, + indent=4, + sort_keys=True, + ) + ) if args.verb == Verb.build: return diff --git a/mkosi/config.py b/mkosi/config.py index bb1734afa..7fd2f7076 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -4717,8 +4717,11 @@ def parse_config( if have_history(args): try: - prev = Config.from_json(Path(".mkosi-private/history/latest.json").read_text()) - except ValueError: + *subimages, prev = [ + Config.from_json(j) + for j in json.loads(Path(".mkosi-private/history/latest.json").read_text())["Images"] + ] + except (KeyError, ValueError): die( "Unable to parse history from .mkosi-private/history/latest.json", hint="Build with -f to generate a new history file from scratch", @@ -4744,6 +4747,7 @@ def parse_config( context.only_sections = ("Include", "Runtime", "Host") else: context.only_sections = tuple(only_sections) + subimages = [] prev = None context.parse_new_includes() @@ -4765,7 +4769,7 @@ def parse_config( setattr(config, s.dest, context.finalize_value(s)) if prev: - return args, (Config.from_namespace(config),) + return args, (*subimages, Config.from_namespace(config)) images = []