commit:     5d417624a82991d4786b59dff1213e10ee641a12
Author:     Nowa Ammerlaan <nowa <AT> gentoo <DOT> org>
AuthorDate: Wed Feb  4 16:02:34 2026 +0000
Commit:     Nowa Ammerlaan <nowa <AT> gentoo <DOT> org>
CommitDate: Thu Feb  5 08:10:46 2026 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5d417624

kernel-{build,install}.eclass: harmonise use of compressor

Use the same compressor for modules and initramfs throughout install
and test phases. To accomplish this we introduce a new function to
get the compressor with all arguments based on the kernel config.

With this change only one single compressor is required to build
the kernel regardless of USE configuration. The used compressor is
selectable via /etc/kernel/config.d as usual.

Signed-off-by: Nowa Ammerlaan <nowa <AT> gentoo.org>
Part-of: https://github.com/gentoo/gentoo/pull/45640

 eclass/dist-kernel-utils.eclass | 39 ++++++++++++++++++++++++++++++++++++++-
 eclass/kernel-build.eclass      |  5 +++--
 eclass/kernel-install.eclass    | 41 +++++++----------------------------------
 3 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/eclass/dist-kernel-utils.eclass b/eclass/dist-kernel-utils.eclass
index 975efd2d63c8..1ebf17092b35 100644
--- a/eclass/dist-kernel-utils.eclass
+++ b/eclass/dist-kernel-utils.eclass
@@ -1,4 +1,4 @@
-# Copyright 2020-2025 Gentoo Authors
+# Copyright 2020-2026 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: dist-kernel-utils.eclass
@@ -215,6 +215,43 @@ dist-kernel_PV_to_KV() {
        echo "${kv}"
 }
 
+# @FUNCTION: dist-kernel_get_compressor
+# @USAGE: <kernel_config>
+# @DESCRIPTION:
+# Returns the compressor with arguments for compressing kernel modules
+# based on the CONFIG_MODULES_COMPESS_* setting in the kernel config.
+dist-kernel_get_compressor() {
+       debug-print-function ${FUNCNAME} "$@"
+
+       [[ ${#} -eq 1 ]] || die "${FUNCNAME}: invalid arguments"
+
+       local suffix=$(dist-kernel_get_module_suffix "${1}")
+       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
+
+       echo "${compress[@]}"
+}
+
 # @FUNCTION: dist-kernel_get_module_suffix
 # @USAGE: <kernel_config>
 # @DESCRIPTION:

diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 9a1eb8bbb91f..e636133b2cac 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -335,7 +335,8 @@ kernel-build_src_test() {
 
        kernel-install_test "${KV_FULL}" \
                "${WORKDIR}/build/$(dist-kernel_get_image_path)" \
-               "${T}/lib/modules/${KV_FULL}"
+               "${T}/lib/modules/${KV_FULL}" \
+               "${WORKDIR}/modprep/.config"
 }
 
 # @FUNCTION: kernel-build_src_install
@@ -524,7 +525,7 @@ kernel-build_src_install() {
                                --kmoddir "${ED}/lib/modules/${KV_FULL}"
                                --kver "${KV_FULL}"
                                --verbose
-                               --compress="xz -9e --check=crc32"
+                               --compress="$(dist-kernel_get_compressor 
"${ED}/usr/src/linux-${KV_FULL}/.config")"
                                --no-hostonly
                                --no-hostonly-cmdline
                                --no-hostonly-i18n

diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index cb0c5318fd59..5f113bf71f19 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -403,18 +403,19 @@ kernel-install_create_qemu_image() {
 }
 
 # @FUNCTION: kernel-install_test
-# @USAGE: <version> <image> <modules>
+# @USAGE: <version> <image> <modules> <config>
 # @DESCRIPTION:
 # Test that the kernel can successfully boot a minimal system image
 # in qemu.  <version> is the kernel version, <image> path to the image,
-# <modules> path to module tree.
+# <modules> path to module tree, <config> path to the kernel config.
 kernel-install_test() {
        debug-print-function ${FUNCNAME} "$@"
 
-       [[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments"
+       [[ ${#} -eq 4 ]] || die "${FUNCNAME}: invalid arguments"
        local version=${1}
        local image=${2}
        local modules=${3}
+       local config=${4}
 
        local qemu_arch=$(kernel-install_get_qemu_arch)
 
@@ -435,12 +436,6 @@ kernel-install_test() {
        > "${T}"/empty-file || die
        mkdir -p "${T}"/empty-directory || die
 
-       local compress="gzip"
-       if [[ ${KERNEL_IUSE_GENERIC_UKI} ]] && use generic-uki; then
-               # Test with same compression method as the generic initrd
-               compress="xz -9e --check=crc32"
-       fi
-
        dracut \
                --conf "${T}"/empty-file \
                --confdir "${T}"/empty-directory \
@@ -450,7 +445,7 @@ kernel-install_test() {
                --omit "${omit_mods[*]}" \
                --nostrip \
                --no-early-microcode \
-               --compress="${compress}" \
+               --compress="$(dist-kernel_get_compressor "${config}")" \
                "${T}/initrd" "${version}" || die
 
        kernel-install_create_qemu_image "${T}/fs.img"
@@ -842,32 +837,10 @@ kernel-install_compress_modules() {
                if [[ -z ${KV_FULL} ]]; then
                        KV_FULL=${PV}${KV_LOCALVERSION}
                fi
-               local suffix=$(dist-kernel_get_module_suffix 
"${ED}/usr/src/linux-${KV_FULL}/.config")
-               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[@]}"
+                       xargs -0 -P "$(makeopts_jobs)" -n 128 \
+                               $(dist-kernel_get_compressor 
"${ED}/usr/src/linux-${KV_FULL}/.config")
                assert "Compressing kernel modules failed"
 
                # Module paths have changed, run depmod

Reply via email to