]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Save all images to history JSON
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 26 Feb 2025 11:08:55 +0000 (12:08 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 26 Feb 2025 11:08:55 +0000 (12:08 +0100)
Preparation for the upcoming commit where we'll need all the images
instead of just the main one when reading the history.

mkosi/__init__.py
mkosi/config.py

index 8a4607265c8680b6fdac9a5b014b749605efe60a..66d41b8c2ded93dd179589ca518031b43aed107c 100644 (file)
@@ -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
index bb1734afaefae4fc4f49e03a4d86fa61fe2927e5..7fd2f707656f764ac22c335bcc22619e049d72a6 100644 (file)
@@ -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 = []