]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Mount volatile overlay when running build scripts
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 11 Oct 2023 11:33:00 +0000 (13:33 +0200)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Wed, 11 Oct 2023 12:28:04 +0000 (14:28 +0200)
When building multiple projects, it might be needed to make the
header files produced by an earlier build available to later builds.
Let's make this possible by not making the root directory read-only
but instead mounting a writable overlay on top of it so that all
changes made while running the build scripts are thrown away at the
end.

mkosi/__init__.py

index 09936308cb023f914f453760aab4bdedb1917c9f..73df7ec7043592bbda140681c309c52bd961b0b8 100644 (file)
@@ -298,6 +298,15 @@ def mount_build_overlay(state: MkosiState) -> contextlib.AbstractContextManager[
     return mount_overlay([state.root], state.workspace / "build-overlay", state.root)
 
 
+@contextlib.contextmanager
+def mount_volatile_overlay(state: MkosiState) -> Iterator[Path]:
+    with tempfile.TemporaryDirectory() as d:
+        Path(d).chmod(0o755)
+
+        with mount_overlay([state.root], Path(d), state.root) as p:
+            yield p
+
+
 def finalize_mounts(config: MkosiConfig) -> list[PathString]:
     sources = [
         (src, Path.cwd() / (str(target).lstrip("/") if target else "."))
@@ -395,7 +404,11 @@ def run_build_scripts(state: MkosiState) -> None:
             CHROOT_BUILDDIR="/work/build",
         )
 
-    with mount_build_overlay(state), mount_passwd(state.name, state.uid, state.gid, state.root):
+    with (
+        mount_build_overlay(state),\
+        mount_passwd(state.name, state.uid, state.gid, state.root),\
+        mount_volatile_overlay(state)\
+    ):
         for script in state.config.build_scripts:
             chroot = chroot_cmd(
                 state.root,