Skip to content

Commit

Permalink
dist-kernel-utils.eclass: Introduce eclass for helper functions
Browse files Browse the repository at this point in the history
Move some of the utility functions from kernel-install.eclass
into dist-kernel-utils.eclass, in order to permit using them without
having all kernel-install phases exported.  This will be used in order
to support rebuilding initramfs in sys-fs/zfs-kmod.

Since the eclasses are used only by dist-kernel project eclasses
and ebuilds, update the function prefix while moving them.

Signed-off-by: Michał Górny <[email protected]>
  • Loading branch information
mgorny committed Jan 13, 2021
1 parent e88d555 commit c71a27d
Show file tree
Hide file tree
Showing 22 changed files with 134 additions and 102 deletions.
96 changes: 96 additions & 0 deletions eclass/dist-kernel-utils.eclass
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: dist-kernel-utils.eclass
# @MAINTAINER:
# Distribution Kernel Project <[email protected]>
# @AUTHOR:
# Michał Górny <[email protected]>
# @SUPPORTED_EAPIS: 7
# @BLURB: Utility functions related to Distribution Kernels
# @DESCRIPTION:
# This eclass provides various utility functions related to Distribution
# Kernels.

if [[ ! ${_DIST_KERNEL_UTILS} ]]; then

case "${EAPI:-0}" in
0|1|2|3|4|5|6)
die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
;;
7)
;;
*)
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
;;
esac

# @FUNCTION: dist-kernel_build_initramfs
# @USAGE: <output> <version>
# @DESCRIPTION:
# Build an initramfs for the kernel. <output> specifies the absolute
# path where initramfs will be created, while <version> specifies
# the kernel version, used to find modules.
#
# Note: while this function uses dracut at the moment, other initramfs
# variants may be supported in the future.
dist-kernel_build_initramfs() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
local output=${1}
local version=${2}

ebegin "Building initramfs via dracut"
dracut --force "${output}" "${version}"
eend ${?} || die "Building initramfs failed"
}

# @FUNCTION: dist-kernel_get_image_path
# @DESCRIPTION:
# Get relative kernel image path specific to the current ${ARCH}.
dist-kernel_get_image_path() {
case ${ARCH} in
amd64|x86)
echo arch/x86/boot/bzImage
;;
arm64)
echo arch/arm64/boot/Image.gz
;;
arm)
echo arch/arm/boot/zImage
;;
ppc64)
# ./ is required because of ${image_path%/*}
# substitutions in the code
echo ./vmlinux
;;
*)
die "${FUNCNAME}: unsupported ARCH=${ARCH}"
;;
esac
}

# @FUNCTION: dist-kernel_install_kernel
# @USAGE: <version> <image> <system.map>
# @DESCRIPTION:
# Install kernel using installkernel tool. <version> specifies
# the kernel version, <image> full path to the image, <system.map>
# full path to System.map.
dist-kernel_install_kernel() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments"
local version=${1}
local image=${2}
local map=${3}

ebegin "Installing the kernel via installkernel"
# note: .config is taken relatively to System.map;
# initrd relatively to bzImage
installkernel "${version}" "${image}" "${map}"
eend ${?} || die "Installing the kernel failed"
}

_DIST_KERNEL_UTILS=1
fi
6 changes: 3 additions & 3 deletions eclass/kernel-build.eclass
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: kernel-build.eclass
Expand Down Expand Up @@ -117,7 +117,7 @@ kernel-build_src_test() {

local ver="${PV}${KV_LOCALVERSION}"
kernel-install_test "${ver}" \
"${WORKDIR}/build/$(kernel-install_get_image_path)" \
"${WORKDIR}/build/$(dist-kernel_get_image_path)" \
"${T}/lib/modules/${ver}"
}

Expand Down Expand Up @@ -173,7 +173,7 @@ kernel-build_src_install() {
# install the kernel and files needed for module builds
insinto "/usr/src/linux-${ver}"
doins build/{System.map,Module.symvers}
local image_path=$(kernel-install_get_image_path)
local image_path=$(dist-kernel_get_image_path)
cp -p "build/${image_path}" "${ED}/usr/src/linux-${ver}/${image_path}" || die

# building modules fails with 'vmlinux has no symtab?' if stripped
Expand Down
82 changes: 9 additions & 73 deletions eclass/kernel-install.eclass
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: kernel-install.eclass
Expand Down Expand Up @@ -40,7 +40,7 @@ case "${EAPI:-0}" in
;;
esac

inherit mount-boot toolchain-funcs
inherit dist-kernel-utils mount-boot toolchain-funcs

SLOT="${PV}"
IUSE="+initramfs test"
Expand Down Expand Up @@ -70,70 +70,6 @@ BDEPEND="
x86? ( app-emulation/qemu[qemu_softmmu_targets_i386] )
)"

# @FUNCTION: kernel-install_build_initramfs
# @USAGE: <output> <version>
# @DESCRIPTION:
# Build an initramfs for the kernel. <output> specifies the absolute
# path where initramfs will be created, while <version> specifies
# the kernel version, used to find modules.
kernel-install_build_initramfs() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -eq 2 ]] || die "${FUNCNAME}: invalid arguments"
local output=${1}
local version=${2}

ebegin "Building initramfs via dracut"
dracut --force "${output}" "${version}"
eend ${?} || die "Building initramfs failed"
}

# @FUNCTION: kernel-install_get_image_path
# @DESCRIPTION:
# Get relative kernel image path specific to the current ${ARCH}.
kernel-install_get_image_path() {
case ${ARCH} in
amd64|x86)
echo arch/x86/boot/bzImage
;;
arm64)
echo arch/arm64/boot/Image.gz
;;
arm)
echo arch/arm/boot/zImage
;;
ppc64)
# ./ is required because of ${image_path%/*}
# substitutions in the code
echo ./vmlinux
;;
*)
die "${FUNCNAME}: unsupported ARCH=${ARCH}"
;;
esac
}

# @FUNCTION: kernel-install_install_kernel
# @USAGE: <version> <image> <system.map>
# @DESCRIPTION:
# Install kernel using installkernel tool. <version> specifies
# the kernel version, <image> full path to the image, <system.map>
# full path to System.map.
kernel-install_install_kernel() {
debug-print-function ${FUNCNAME} "${@}"

[[ ${#} -eq 3 ]] || die "${FUNCNAME}: invalid arguments"
local version=${1}
local image=${2}
local map=${3}

ebegin "Installing the kernel via installkernel"
# note: .config is taken relatively to System.map;
# initrd relatively to bzImage
installkernel "${version}" "${image}" "${map}"
eend ${?} || die "Installing the kernel failed"
}

# @FUNCTION: kernel-install_update_symlink
# @USAGE: <target> <version>
# @DESCRIPTION:
Expand Down Expand Up @@ -406,16 +342,16 @@ kernel-install_pkg_postinst() {
mount-boot_pkg_preinst

local ver="${PV}${KV_LOCALVERSION}"
local image_path=$(kernel-install_get_image_path)
local image_path=$(dist-kernel_get_image_path)
if use initramfs; then
# putting it alongside kernel image as 'initrd' makes
# kernel-install happier
kernel-install_build_initramfs \
dist-kernel_build_initramfs \
"${EROOT}/usr/src/linux-${ver}/${image_path%/*}/initrd" \
"${ver}"
fi

kernel-install_install_kernel "${ver}" \
dist-kernel_install_kernel "${ver}" \
"${EROOT}/usr/src/linux-${ver}/${image_path}" \
"${EROOT}/usr/src/linux-${ver}/System.map"
fi
Expand All @@ -441,7 +377,7 @@ kernel-install_pkg_postrm() {

if [[ -z ${ROOT} ]] && use initramfs; then
local ver="${PV}${KV_LOCALVERSION}"
local image_path=$(kernel-install_get_image_path)
local image_path=$(dist-kernel_get_image_path)
ebegin "Removing initramfs"
rm -f "${EROOT}/usr/src/linux-${ver}/${image_path%/*}/initrd" &&
find "${EROOT}/usr/src/linux-${ver}" -depth -type d -empty -delete
Expand All @@ -458,16 +394,16 @@ kernel-install_pkg_config() {
mount-boot_pkg_preinst

local ver="${PV}${KV_LOCALVERSION}"
local image_path=$(kernel-install_get_image_path)
local image_path=$(dist-kernel_get_image_path)
if use initramfs; then
# putting it alongside kernel image as 'initrd' makes
# kernel-install happier
kernel-install_build_initramfs \
dist-kernel_build_initramfs \
"${EROOT}/usr/src/linux-${ver}/${image_path%/*}/initrd" \
"${ver}"
fi

kernel-install_install_kernel "${ver}" \
dist-kernel_install_kernel "${ver}" \
"${EROOT}/usr/src/linux-${ver}/${image_path}" \
"${EROOT}/usr/src/linux-${ver}/System.map"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
Expand Down Expand Up @@ -33,7 +33,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
4 changes: 2 additions & 2 deletions sys-kernel/gentoo-kernel-bin/gentoo-kernel-bin-5.10.3.ebuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
Expand Down Expand Up @@ -37,7 +37,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
Expand Down Expand Up @@ -44,7 +44,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
Expand Down Expand Up @@ -48,7 +48,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
4 changes: 2 additions & 2 deletions sys-kernel/gentoo-kernel-bin/gentoo-kernel-bin-5.4.83.ebuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
Expand Down Expand Up @@ -44,7 +44,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 Gentoo Authors
# Copyright 2020-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7
Expand Down Expand Up @@ -48,7 +48,7 @@ src_unpack() {

src_test() {
kernel-install_test "${PV}" \
"${WORKDIR}/usr/src/linux-${PV}/$(kernel-install_get_image_path)" \
"${WORKDIR}/usr/src/linux-${PV}/$(dist-kernel_get_image_path)" \
"lib/modules/${PV}"
}

Expand Down
Loading

0 comments on commit c71a27d

Please sign in to comment.