]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't run depmod unless needed 1855/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Sep 2023 12:32:29 +0000 (14:32 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 1 Sep 2023 14:03:56 +0000 (16:03 +0200)
For distro kernels, depmod is already executed by the package
manager, so let's make sure we don't rerun it unless needed.

To make this work, we have to run depmod and modinfo from inside the
image, as running modinfo from the host on files generated by depmod
from the image can lead to all sorts of compatibility issues so we opt
to run both depmod and modinfo from inside the image.

mkosi/__init__.py
mkosi/kmod.py
mkosi/run.py

index 5686d8b27d7ad1cc12ea6f7199598a262c33ae2f..910aedefe2bfa397fef4c621db5754f05ff7066d 100644 (file)
@@ -1462,7 +1462,19 @@ def run_depmod(state: MkosiState) -> None:
     if state.config.bootable == ConfigFeature.disabled:
         return
 
+    outputs = (
+        "modules.dep",
+        "modules.dep.bin",
+        "modules.symbols",
+        "modules.symbols.bin",
+    )
+
+    filters = state.config.kernel_modules_include or state.config.kernel_modules_exclude
+
     for kver, _ in gen_kernel_images(state):
+        if not filters and all((state.root / "usr/lib/modules" / kver / o).exists() for o in outputs):
+            continue
+
         process_kernel_modules(
             state.root, kver,
             state.config.kernel_modules_include,
@@ -1470,7 +1482,7 @@ def run_depmod(state: MkosiState) -> None:
         )
 
         with complete_step(f"Running depmod for {kver}"):
-            run(["depmod", "--all", "--basedir", state.root, kver])
+            bwrap(chroot_cmd(state.root) + ["depmod", "--all", kver])
 
 
 def run_sysusers(state: MkosiState) -> None:
index cdf138be73745b38c430b675e399a94bc59ddfba..1522358e10e28534aec43f9632e7ac85a4fa314c 100644 (file)
@@ -8,7 +8,7 @@ from collections.abc import Iterator, Sequence
 from pathlib import Path
 
 from mkosi.log import complete_step, log_step
-from mkosi.run import run
+from mkosi.run import bwrap, chroot_cmd
 
 
 def filter_kernel_modules(root: Path, kver: str, include: Sequence[str], exclude: Sequence[str]) -> list[Path]:
@@ -58,8 +58,8 @@ def resolve_module_dependencies(root: Path, kver: str, modules: Sequence[str]) -
     # We could run modinfo once for each module but that's slow. Luckily we can pass multiple modules to
     # modinfo and it'll process them all in a single go. We get the modinfo for all modules to build two maps
     # that map the path of the module to its module dependencies and its firmware dependencies respectively.
-    info = run(["modinfo", "--basedir", root, "--set-version", kver, "--null", *nametofile.keys(), *builtin],
-               stdout=subprocess.PIPE).stdout
+    info = bwrap(chroot_cmd(root) + ["modinfo", "--set-version", kver, "--null", *nametofile.keys(), *builtin],
+                 stdout=subprocess.PIPE).stdout
 
     log_step("Calculating required kernel modules and firmware")
 
index 7345253d86338ee6331fbf218705c4ecc0d8ffff..a94c944d8af7c8240e56534fd08a5f58926c4137 100644 (file)
@@ -278,6 +278,7 @@ def bwrap(
     scripts: Mapping[str, Sequence[PathString]] = {},
     env: Mapping[str, str] = {},
     stdin: _FILE = None,
+    stdout: _FILE = None,
     input: Optional[str] = None,
 ) -> CompletedProcess:
     cmdline: list[PathString] = [
@@ -335,7 +336,7 @@ def bwrap(
         ]
 
         try:
-            result = run([*cmdline, *cmd], env=env, log=False, stdin=stdin, input=input)
+            result = run([*cmdline, *cmd], env=env, log=False, stdin=stdin, stdout=stdout, input=input)
         except subprocess.CalledProcessError as e:
             if log:
                 logging.error(f"\"{shlex.join(os.fspath(s) for s in cmd)}\" returned non-zero exit code {e.returncode}.")