]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make $BUILDDIR accessible to various scripts
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 12 Jul 2024 12:17:02 +0000 (14:17 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 12 Jul 2024 12:44:14 +0000 (14:44 +0200)
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.

mkosi/__init__.py
mkosi/resources/mkosi.md

index 4fe6c10470e82b04c7c4c749b61c3341a77ca14b..03061aa30d95660ce1950da1300c82c75c658e9a 100644 (file)
@@ -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"],
index 72c229a7b2f95b06b544871c1b39e19efe090b3f..1ac42d11a4886f2bb6da80f8b38be0257946b155 100644 (file)
@@ -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`    |             |        |           | ✓       |            |            |              |         |