]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't do caching if we have base trees
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jul 2024 14:39:32 +0000 (16:39 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jul 2024 14:42:12 +0000 (16:42 +0200)
Instead of doing a complicated scheme with cache overlays which
aren't invalidated when the base tree changes, let's not do caching
when there are base trees. We assume that if there's a base tree
only a minimal amount of extra packages is installed that is sufficiently
fast without caching.

mkosi/__init__.py

index a9b8f024f10ff2a50617831b7d6e57fcc5a2c6a3..aa625c002c4d6fc968d9b5146acc9183e7a9d592 100644 (file)
@@ -330,20 +330,6 @@ def configure_autologin(context: Context) -> None:
                                     "--keep-baud 115200,57600,38400,9600 -")
 
 
-@contextlib.contextmanager
-def mount_cache_overlay(context: Context, cached: bool) -> Iterator[None]:
-    if not context.config.incremental or not context.config.base_trees or context.config.overlay or cached:
-        yield
-        return
-
-    d = context.workspace / "cache-overlay"
-    with umask(~0o755):
-        d.mkdir(exist_ok=True)
-
-    with mount_overlay([context.root], d, context.root):
-        yield
-
-
 @contextlib.contextmanager
 def mount_build_overlay(context: Context, volatile: bool = False) -> Iterator[Path]:
     d = context.workspace / "build-overlay"
@@ -3237,7 +3223,7 @@ def need_build_overlay(config: Config) -> bool:
 
 
 def save_cache(context: Context) -> None:
-    if not context.config.incremental or context.config.overlay:
+    if not context.config.incremental or context.config.base_trees or context.config.overlay:
         return
 
     final, build, manifest = cache_tree_paths(context.config)
@@ -3245,20 +3231,11 @@ def save_cache(context: Context) -> None:
     with complete_step("Installing cache copies"):
         rmtree(final, sandbox=context.sandbox)
 
-        # We only use the cache-overlay directory for caching if we have a base tree, otherwise we just
-        # cache the root directory.
-        if (context.workspace / "cache-overlay").exists():
-            move_tree(
-                context.workspace / "cache-overlay", final,
-                use_subvolumes=context.config.use_subvolumes,
-                sandbox=context.sandbox,
-            )
-        else:
-            move_tree(
-                context.root, final,
-                use_subvolumes=context.config.use_subvolumes,
-                sandbox=context.sandbox,
-            )
+        move_tree(
+            context.root, final,
+            use_subvolumes=context.config.use_subvolumes,
+            sandbox=context.sandbox,
+        )
 
         if need_build_overlay(context.config) and (context.workspace / "build-overlay").exists():
             rmtree(build, sandbox=context.sandbox)
@@ -3279,7 +3256,7 @@ def save_cache(context: Context) -> None:
 
 
 def have_cache(config: Config) -> bool:
-    if not config.incremental or config.overlay:
+    if not config.incremental or config.base_trees or config.overlay:
         return False
 
     final, build, manifest = cache_tree_paths(config)
@@ -3852,21 +3829,19 @@ def build_image(context: Context) -> None:
         install_base_trees(context)
         cached = reuse_cache(context)
 
-        with mount_cache_overlay(context, cached):
-            copy_repository_metadata(context)
+        copy_repository_metadata(context)
 
         context.config.distribution.setup(context)
         install_package_directories(context)
 
         if not cached:
-            with mount_cache_overlay(context, cached):
-                install_skeleton_trees(context)
-                install_distribution(context)
-                run_prepare_scripts(context, build=False)
-                install_build_packages(context)
-                run_prepare_scripts(context, build=True)
-                fixup_vmlinuz_location(context)
-                run_depmod(context, cache=True)
+            install_skeleton_trees(context)
+            install_distribution(context)
+            run_prepare_scripts(context, build=False)
+            install_build_packages(context)
+            run_prepare_scripts(context, build=True)
+            fixup_vmlinuz_location(context)
+            run_depmod(context, cache=True)
 
             save_cache(context)
             reuse_cache(context)