From: Daan De Meyer Date: Fri, 12 Jul 2024 12:17:02 +0000 (+0200) Subject: Make $BUILDDIR accessible to various scripts X-Git-Tag: v24~38^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=870d00d5e06b2b30e300c977e4d5cebe26d77a0f;p=thirdparty%2Fmkosi.git Make $BUILDDIR accessible to various scripts Let's allow scripts to access the build directory so that outputs produced by previous (sub)image builds can be accessed. Let's mount the build directory read-only so that these scripts can't actually write to it. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 4fe6c1047..03061aa30 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -552,6 +552,9 @@ def run_prepare_scripts(context: Context, build: bool) -> None: if context.config.profile: env["PROFILE"] = context.config.profile + if context.config.build_dir is not None: + env |= dict(BUILDDIR="/work/build") + with ( mount_build_overlay(context) if build else contextlib.nullcontext(), finalize_source_mounts(context.config, ephemeral=context.config.build_sources_ephemeral) as sources, @@ -592,6 +595,11 @@ def run_prepare_scripts(context: Context, build: bool) -> None: Mount(context.root, "/buildroot"), Mount(context.artifacts, "/work/artifacts"), Mount(context.packages, "/work/packages"), + *( + [Mount(context.config.build_dir, "/work/build", ro=True)] + if context.config.build_dir + else [] + ), *context.config.distribution.package_manager(context.config).mounts(context), ], options=["--dir", "/work/src", "--chdir", "/work/src"], @@ -716,6 +724,9 @@ def run_postinst_scripts(context: Context) -> None: if context.config.profile: env["PROFILE"] = context.config.profile + if context.config.build_dir is not None: + env |= dict(BUILDDIR="/work/build") + with ( finalize_source_mounts(context.config, ephemeral=context.config.build_sources_ephemeral) as sources, ): @@ -749,6 +760,11 @@ def run_postinst_scripts(context: Context) -> None: Mount(context.staging, "/work/out"), Mount(context.artifacts, "/work/artifacts"), Mount(context.packages, "/work/packages"), + *( + [Mount(context.config.build_dir, "/work/build", ro=True)] + if context.config.build_dir + else [] + ), *context.config.distribution.package_manager(context.config).mounts(context), ], options=["--dir", "/work/src", "--chdir", "/work/src"], @@ -785,6 +801,9 @@ def run_finalize_scripts(context: Context) -> None: if context.config.profile: env["PROFILE"] = context.config.profile + if context.config.build_dir is not None: + env |= dict(BUILDDIR="/work/build") + with finalize_source_mounts(context.config, ephemeral=context.config.build_sources_ephemeral) as sources: for script in context.config.finalize_scripts: chroot = chroot_cmd(resolve=context.config.with_network, work=True) @@ -816,6 +835,11 @@ def run_finalize_scripts(context: Context) -> None: Mount(context.staging, "/work/out"), Mount(context.artifacts, "/work/artifacts"), Mount(context.packages, "/work/packages"), + *( + [Mount(context.config.build_dir, "/work/build", ro=True)] + if context.config.build_dir + else [] + ), *context.config.distribution.package_manager(context.config).mounts(context), ], options=["--dir", "/work/src", "--chdir", "/work/src"], diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 72c229a7b..1ac42d11a 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -2194,7 +2194,7 @@ Consult this table for which script receives which environment variables: | `CHROOT_SCRIPT` | | | ✓ | ✓ | ✓ | ✓ | | | | `SRCDIR` | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | `CHROOT_SRCDIR` | | | ✓ | ✓ | ✓ | ✓ | | | -| `BUILDDIR` | | | | ✓ | | | | | +| `BUILDDIR` | | | ✓ | ✓ | ✓ | ✓ | | | | `CHROOT_BUILDDIR` | | | | ✓ | | | | | | `DESTDIR` | | | | ✓ | | | | | | `CHROOT_DESTDIR` | | | | ✓ | | | | |