]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Have filter_kernel_modules() return a list of module names 3598/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 18 Mar 2025 15:00:06 +0000 (16:00 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 18 Mar 2025 15:31:37 +0000 (16:31 +0100)
The only caller of this function only needs the list of module names,
not the full paths so let's just return the list of module names.

mkosi/kmod.py

index a66f98f2e25e44d3b318edac20affa119273ebf9..256c30bc48fa6d2d4181b399467c2cb487f43936 100644 (file)
@@ -81,7 +81,7 @@ def filter_kernel_modules(
     *,
     include: Iterable[str],
     exclude: Iterable[str],
-) -> list[Path]:
+) -> list[str]:
     logging.debug(f"Kernel modules include: {' '.join(include)}")
     logging.debug(f"Kernel modules exclude: {' '.join(exclude)}")
 
@@ -127,7 +127,7 @@ def filter_kernel_modules(
 
     logging.debug(f"Including {len(modules)}/{n_modules} kernel modules.")
 
-    return sorted(modules)
+    return sorted(module_path_to_name(m) for m in modules)
 
 
 def filter_firmware(
@@ -323,15 +323,22 @@ def gen_required_kernel_modules(
     # installed we have to take the slow path to make sure we don't copy firmware into the initrd that is not
     # depended on by any kernel modules.
     if modules_include or modules_exclude or (context.root / firmwared).glob("*"):
-        modules = filter_kernel_modules(context.root, kver, include=modules_include, exclude=modules_exclude)
-        names = [module_path_to_name(m) for m in modules]
-        mods, firmware = resolve_module_dependencies(context, kver, names)
+        modules, firmware = resolve_module_dependencies(
+            context,
+            kver,
+            modules=filter_kernel_modules(
+                context.root,
+                kver,
+                include=modules_include,
+                exclude=modules_exclude,
+            ),
+        )
     else:
         logging.debug(
             "No modules excluded and no firmware installed, using kernel modules generation fast path"
         )
         with chdir(context.root):
-            mods = set(modulesd.rglob("*.ko*"))
+            modules = set(modulesd.rglob("*.ko*"))
         firmware = set()
 
     # Include or exclude firmware explicitly configured
@@ -350,17 +357,17 @@ def gen_required_kernel_modules(
         itertools.chain(
             {
                 p.relative_to(context.root)
-                for f in mods | firmware
+                for f in modules | firmware
                 for p in parents_below(context.root / f, context.root / "usr/lib")
             },
-            mods,
+            modules,
             firmware,
             (p.relative_to(context.root) for p in (context.root / modulesd).glob("modules*")),
         )
     )
 
     if (modulesd / "vdso").exists():
-        if not mods:
+        if not modules:
             yield from (
                 p.relative_to(context.root)
                 for p in parents_below(context.root / modulesd / "vdso", context.root / "usr/lib")