From: Daan De Meyer Date: Wed, 11 Oct 2023 11:33:00 +0000 (+0200) Subject: Mount volatile overlay when running build scripts X-Git-Tag: v19~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f043a50b93be2569045f72a550878a059ab38b5;p=thirdparty%2Fmkosi.git Mount volatile overlay when running build scripts 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 09936308c..73df7ec70 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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,