commit:     2073571d34ad5efcd6d4ec4db0914e774ca69a19
Author:     Andrew Ammerlaan <andrewammerlaan <AT> gentoo <DOT> org>
AuthorDate: Mon Aug  5 19:13:28 2024 +0000
Commit:     Andrew Ammerlaan <andrewammerlaan <AT> gentoo <DOT> org>
CommitDate: Wed Aug  7 08:58:39 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2073571d

kernel-install.eclass: use dist-kernel_get_module_suffix to find compression

Adjusts kernel-install_compress_modules to use the new function
dist-kernel_get_module_suffix. This makes no functional difference
at the moment since gentoo-kernel-bin is the only consumer and it has
XZ compression in the config. Still this makes it possible to compile
alternate prebuilt kernels with alternate module compression support, and may
in the future help to support gzip and zstd module compression in
gentoo-kernel-bin.

Signed-off-by: Andrew Ammerlaan <andrewammerlaan <AT> gentoo.org>

 eclass/kernel-install.eclass | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index 15b7cf739bc3..c64dd673084b 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -766,13 +766,35 @@ kernel-install_compress_modules() {
 
        if use modules-compress; then
                einfo "Compressing kernel modules ..."
-               # xz options taken from scripts/Makefile.modinst
-               # we don't do 'xz -T' because it applies multithreading per 
file,
-               # so it works only for big files, and we have lots of small 
files
-               # instead
-               find "${ED}/lib" -name '*.ko' -print0 |
-                       xargs -0 -P "$(makeopts_jobs)" -n 128 \
-                               xz --check=crc32 --lzma2=dict=1MiB
+               if [[ -z ${KV_FULL} ]]; then
+                       KV_FULL=${PV}${KV_LOCALVERSION}
+               fi
+               local suffix=$(dist-kernel_get_module_suffix 
"${ED}/usr/src/linux-${KV_FULL}")
+               local compress=()
+               # Options taken from linux-mod-r1.eclass.
+               # We don't instruct the compressor to parallelize because it 
applies
+               # multithreading per file, so it works only for big files, and 
we have
+               # lots of small files instead.
+               case ${suffix} in
+                       .ko)
+                               return
+                               ;;
+                       .ko.gz)
+                               compress+=( gzip )
+                               ;;
+                       .ko.xz)
+                               compress+=( xz --check=crc32 --lzma2=dict=1MiB )
+                               ;;
+                       .ko.zst)
+                               compress+=( zstd -q --rm )
+                               ;;
+                       *)
+                               die "Unknown compressor: ${suffix}"
+                               ;;
+               esac
+
+               find "${ED}/lib/modules/${KV_FULL}" -name '*.ko' -print0 |
+                       xargs -0 -P "$(makeopts_jobs)" -n 128 "${compress[@]}"
                assert "Compressing kernel modules failed"
        fi
 }

Reply via email to