]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Sort kernel modules directories by version and use the newest
authorJoerg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 23 Feb 2023 13:59:53 +0000 (14:59 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 23 Feb 2023 18:54:16 +0000 (19:54 +0100)
action.yaml
mkosi/__init__.py
mkosi/manifest.py

index 4d368bc84981c90a6adce85de8f6e7d6af62e479..18bf5c0967bb35634d530342bb1d0e9e8224a9e3 100644 (file)
@@ -42,10 +42,11 @@ runs:
       sudo apt-get install libfdisk-dev
       git clone https://github.com/systemd/systemd --depth=1
       meson systemd/build systemd -Drepart=true -Defi=true
-      ninja -C systemd/build systemd-nspawn systemd-repart bootctl ukify
+      ninja -C systemd/build systemd-nspawn systemd-repart bootctl ukify systemd-analyze
       sudo ln -svf $PWD/systemd/build/systemd-repart /usr/bin/systemd-repart
       sudo ln -svf $PWD/systemd/build/bootctl /usr/bin/bootctl
       sudo ln -svf $PWD/systemd/build/ukify /usr/bin/ukify
+      sudo ln -svf $PWD/systemd/build/systemd-analyze /usr/bin/systemd-analyze
       systemd-repart --version
       bootctl --version
       ukify --version
index db005dfb56c774b9886f47f47075cd3a02718920..f926c7891407507c397ad2c4b84a85659e99cef1 100644 (file)
@@ -64,7 +64,7 @@ from mkosi.log import (
     die,
     warn,
 )
-from mkosi.manifest import Manifest
+from mkosi.manifest import GenericVersion, Manifest
 from mkosi.mounts import dissect_and_mount, mount_overlay, scandir_recursive
 from mkosi.remove import unlink_try_hard
 from mkosi.run import (
@@ -769,10 +769,11 @@ def gen_kernel_images(state: MkosiState) -> Iterator[tuple[str, Path]]:
     if not state.root.joinpath("lib/modules").exists():
         return
 
-    for kver in state.root.joinpath("lib/modules").iterdir():
-        if not kver.is_dir():
-            continue
-
+    for kver in sorted(
+        (k for k in state.root.joinpath("lib/modules").iterdir() if k.is_dir()),
+        key=lambda k: GenericVersion(k.name),
+        reverse=True
+    ):
         kimg = state.installer.kernel_image(kver.name, state.config.architecture)
 
         yield kver.name, kimg
index 6ade9c99cc2752884f7bcb832267d2a0e4eb844a..cd8fb937d6636b727ff20ba9ae232a91a2b500ce 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
 import dataclasses
+import functools
 import json
 from datetime import datetime
 from pathlib import Path
@@ -280,3 +281,21 @@ class Manifest:
         for package in self.source_packages.values():
             print(f"\n{80*'-'}\n", file=out)
             out.write(package.report())
+
+
+@functools.total_ordering
+class GenericVersion:
+    def __init__(self, version: str):
+        self._version = version
+
+    def __eq__(self, other: object) -> bool:
+        if not isinstance(other, GenericVersion):
+            return False
+        cmd = ["systemd-analyze", "compare-versions", self._version, "eq", other._version]
+        return run(cmd, check=False).returncode == 0
+
+    def __lt__(self, other: object) -> bool:
+        if not isinstance(other, GenericVersion):
+            return False
+        cmd = ["systemd-analyze", "compare-versions", self._version, "lt", other._version]
+        return run(cmd, check=False).returncode == 0