]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use finalize_ephemeral_source_mounts() for package managers as well
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 12 Jan 2024 14:41:22 +0000 (15:41 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 12 Jan 2024 14:41:22 +0000 (15:41 +0100)
Otherwise we'll still  create mountpoints in the actual source
directories when using nested build sources.

mkosi/installer/apt.py
mkosi/installer/dnf.py
mkosi/installer/pacman.py
mkosi/installer/zypper.py
mkosi/mounts.py

index 1d523018a109bcdc70ebe54d82eeb4e515c76ba8..3ef991cad0486dba59932cf6f64786bda4c019d9 100644 (file)
@@ -3,7 +3,7 @@ import textwrap
 from collections.abc import Sequence
 
 from mkosi.context import Context
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
 from mkosi.run import find_binary, run
 from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
 from mkosi.types import PathString
@@ -101,23 +101,24 @@ def invoke_apt(
     apivfs: bool = True,
     mounts: Sequence[PathString] = (),
 ) -> None:
-    run(
-        apt_cmd(context, command) + [operation, *sort_packages(packages)],
-        sandbox=(
-            context.sandbox(
-                network=True,
-                options=[
-                    "--bind", context.root, context.root,
-                    "--bind", context.cache_dir / "lib/apt", context.cache_dir / "lib/apt",
-                    "--bind", context.cache_dir / "cache/apt", context.cache_dir / "cache/apt",
-                    "--ro-bind", context.workspace / "apt.conf", context.workspace / "apt.conf",
-                    *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
-                    *finalize_crypto_mounts(tools=context.config.tools()),
-                    *finalize_source_mounts(context.config),
-                    *mounts,
-                    "--chdir", "/work/src",
-                ],
-            ) + (apivfs_cmd(context.root) if apivfs else [])
-        ),
-        env=context.config.environment,
-    )
+    with finalize_ephemeral_source_mounts(context.config) as sources:
+        run(
+            apt_cmd(context, command) + [operation, *sort_packages(packages)],
+            sandbox=(
+                context.sandbox(
+                    network=True,
+                    options=[
+                        "--bind", context.root, context.root,
+                        "--bind", context.cache_dir / "lib/apt", context.cache_dir / "lib/apt",
+                        "--bind", context.cache_dir / "cache/apt", context.cache_dir / "cache/apt",
+                        "--ro-bind", context.workspace / "apt.conf", context.workspace / "apt.conf",
+                        *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+                        *finalize_crypto_mounts(tools=context.config.tools()),
+                        *sources,
+                        *mounts,
+                        "--chdir", "/work/src",
+                    ],
+                ) + (apivfs_cmd(context.root) if apivfs else [])
+            ),
+            env=context.config.environment,
+        )
index bfadff12a594b15ace631eb5d3b611b840ba6276..7c7278257ae0d1847eb0fbd4132d8e6435150164 100644 (file)
@@ -5,7 +5,7 @@ from pathlib import Path
 
 from mkosi.context import Context
 from mkosi.installer.rpm import RpmRepository, fixup_rpmdb_location, setup_rpm
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
 from mkosi.run import find_binary, run
 from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
 from mkosi.types import PathString
@@ -125,28 +125,29 @@ def dnf_cmd(context: Context) -> list[PathString]:
 
 
 def invoke_dnf(context: Context, command: str, packages: Iterable[str], apivfs: bool = True) -> None:
-    run(
-        dnf_cmd(context) + [command, *sort_packages(packages)],
-        sandbox=(
-            context.sandbox(
-                network=True,
-                options=[
-                    "--bind", context.root, context.root,
-                    "--bind",
-                    context.cache_dir / "cache" / dnf_subdir(context),
-                    context.cache_dir / "cache" / dnf_subdir(context),
-                    "--bind",
-                    context.cache_dir / "lib" / dnf_subdir(context),
-                    context.cache_dir / "lib" / dnf_subdir(context),
-                    *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
-                    *finalize_crypto_mounts(tools=context.config.tools()),
-                    *finalize_source_mounts(context.config),
-                    "--chdir", "/work/src",
-                ],
-            ) + (apivfs_cmd(context.root) if apivfs else [])
-        ),
-        env=context.config.environment,
-    )
+    with finalize_ephemeral_source_mounts(context.config) as sources:
+        run(
+            dnf_cmd(context) + [command, *sort_packages(packages)],
+            sandbox=(
+                context.sandbox(
+                    network=True,
+                    options=[
+                        "--bind", context.root, context.root,
+                        "--bind",
+                        context.cache_dir / "cache" / dnf_subdir(context),
+                        context.cache_dir / "cache" / dnf_subdir(context),
+                        "--bind",
+                        context.cache_dir / "lib" / dnf_subdir(context),
+                        context.cache_dir / "lib" / dnf_subdir(context),
+                        *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+                        *finalize_crypto_mounts(tools=context.config.tools()),
+                        *sources,
+                        "--chdir", "/work/src",
+                    ],
+                ) + (apivfs_cmd(context.root) if apivfs else [])
+            ),
+            env=context.config.environment,
+        )
 
     fixup_rpmdb_location(context)
 
index f2e086f3e6a595f611649d89bed0bcd5ca358f76..e43d0d0bd8f08181fbb37794d9a73e15ad9b4f24 100644 (file)
@@ -4,7 +4,7 @@ from collections.abc import Iterable, Sequence
 from typing import NamedTuple
 
 from mkosi.context import Context
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
 from mkosi.run import run
 from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
 from mkosi.types import PathString
@@ -90,20 +90,21 @@ def invoke_pacman(
     packages: Sequence[str] = (),
     apivfs: bool = True,
 ) -> None:
-    run(
-        pacman_cmd(context) + [operation, *options, *sort_packages(packages)],
-        sandbox=(
-            context.sandbox(
-                network=True,
-                options=[
-                    "--bind", context.root, context.root,
-                    "--bind", context.cache_dir / "cache/pacman/pkg", context.cache_dir / "cache/pacman/pkg",
-                    *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
-                    *finalize_crypto_mounts(tools=context.config.tools()),
-                    *finalize_source_mounts(context.config),
-                    "--chdir", "/work/src",
-                ],
-            ) + (apivfs_cmd(context.root) if apivfs else [])
-        ),
-        env=context.config.environment,
-    )
+    with finalize_ephemeral_source_mounts(context.config) as sources:
+        run(
+            pacman_cmd(context) + [operation, *options, *sort_packages(packages)],
+            sandbox=(
+                context.sandbox(
+                    network=True,
+                    options=[
+                        "--bind", context.root, context.root,
+                        "--bind", context.cache_dir / "cache/pacman/pkg", context.cache_dir / "cache/pacman/pkg",
+                        *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+                        *finalize_crypto_mounts(tools=context.config.tools()),
+                        *sources,
+                        "--chdir", "/work/src",
+                    ],
+                ) + (apivfs_cmd(context.root) if apivfs else [])
+            ),
+            env=context.config.environment,
+        )
index af8080c6d24f8adc77a8f4d090be79bacb49c1f4..a710e0e11f0ca5f2f56c64e378ec2eb522cd5471 100644 (file)
@@ -5,7 +5,7 @@ from collections.abc import Sequence
 from mkosi.config import yes_no
 from mkosi.context import Context
 from mkosi.installer.rpm import RpmRepository, fixup_rpmdb_location, setup_rpm
-from mkosi.mounts import finalize_source_mounts
+from mkosi.mounts import finalize_ephemeral_source_mounts
 from mkosi.run import run
 from mkosi.sandbox import apivfs_cmd, finalize_crypto_mounts
 from mkosi.types import PathString
@@ -78,22 +78,23 @@ def invoke_zypper(
     options: Sequence[str] = (),
     apivfs: bool = True,
 ) -> None:
-    run(
-        zypper_cmd(context) + [verb, *options, *sort_packages(packages)],
-        sandbox=(
-            context.sandbox(
-                network=True,
-                options=[
-                    "--bind", context.root, context.root,
-                    "--bind", context.cache_dir / "cache/zypp", context.cache_dir / "cache/zypp",
-                    *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
-                    *finalize_crypto_mounts(tools=context.config.tools()),
-                    *finalize_source_mounts(context.config),
-                    "--chdir", "/work/src",
-                ],
-            ) + (apivfs_cmd(context.root) if apivfs else [])
-        ),
-        env=context.config.environment,
-    )
+    with finalize_ephemeral_source_mounts(context.config) as sources:
+        run(
+            zypper_cmd(context) + [verb, *options, *sort_packages(packages)],
+            sandbox=(
+                context.sandbox(
+                    network=True,
+                    options=[
+                        "--bind", context.root, context.root,
+                        "--bind", context.cache_dir / "cache/zypp", context.cache_dir / "cache/zypp",
+                        *(["--ro-bind", m, m] if (m := context.config.local_mirror) else []),
+                        *finalize_crypto_mounts(tools=context.config.tools()),
+                        *sources,
+                        "--chdir", "/work/src",
+                    ],
+                ) + (apivfs_cmd(context.root) if apivfs else [])
+            ),
+            env=context.config.environment,
+        )
 
     fixup_rpmdb_location(context)
index 4ccb179f9d546542ec78381afc8b87711fdc9751..dfd8c4e067f15e659cc5e81df4628fe340c6fa70 100644 (file)
@@ -122,16 +122,6 @@ def mount_overlay(
             delete_whiteout_files(upperdir)
 
 
-def finalize_source_mounts(config: Config) -> list[PathString]:
-    mounts = {t.with_prefix(Path("/work/src")) for t in config.build_sources}
-
-    options: list[PathString] = ["--dir", "/work/src"]
-    for src, target in sorted(mounts, key=lambda s: s[1]):
-        options += ["--ro-bind", src, target]
-
-    return options
-
-
 @contextlib.contextmanager
 def finalize_ephemeral_source_mounts(config: Config) -> Iterator[list[PathString]]:
     with contextlib.ExitStack() as stack: