Simplify kernel directory logic

Having too many variables is confusing, so use the ones already provided
by upstream. linux-info.eclass uses KERNEL_DIR (if set) as the kernel
sources directory and sets KV_DIR to that for use elsewhere. If
KERNEL_DIR is unset, it checks the /usr/src/linux symlink. While we
could rely on the symlink, we want to be sure that coreos-modules and
coreos-kernel are built against the matching kernel version.

KV_OUT_DIR is the kernel output directory. It is automatically set by
linux-info.eclass, and it will never leave it empty.

Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
This commit is contained in:
James Le Cuirot 2025-12-04 18:37:50 +00:00
parent 14b60cbd6a
commit b5e9560fba
No known key found for this signature in database
GPG Key ID: 1226415D00DD3137
4 changed files with 14 additions and 33 deletions

View File

@ -7,24 +7,6 @@
# Revision of the source ebuild, e.g. -r1. default is "" # Revision of the source ebuild, e.g. -r1. default is ""
: ${COREOS_SOURCE_REVISION:=} : ${COREOS_SOURCE_REVISION:=}
COREOS_SOURCE_VERSION="${PV}${COREOS_SOURCE_REVISION}"
# $COREOS_KERNEL_SOURCE_NAME is the kernel source name to be used for
# $KERNEL_DIR, e.g. linux-4.19.0-coreos. This comes from upstream, so
# Flatcar should not change it.
#
# On the other hand, $COREOS_SOURCE_NAME is the kernel name to be used for
# $KV_OUT_DIR in individual coreos-kernel*.ebuild files. That one needs to
# have a flatcar-specific name. We cannot define another variable like
# $FLATCAR_SOURCE_NAME, because it will then be rewritten by upstream changes
# that set $COREOS_SOURCE_NAME by default. In the Gentoo world, the ebuild
# for each new version has a totally new file name. So it's hard to replace
# a new $COREOS_SOURCE_NAME variable for every new ebuild.
# $COREOS_SOURCE_NAME should be a name without a revision suffix (e.g. "-r1"),
# because $KV_FULL would not include such a suffix.
COREOS_KERNEL_SOURCE_NAME="linux-${PV/_rc/-rc}-coreos${COREOS_SOURCE_REVISION}"
COREOS_SOURCE_NAME="linux-${PV/_rc/-rc}-flatcar"
[[ ${EAPI} != [78] ]] && die "Only EAPI 7 and 8 are supported" [[ ${EAPI} != [78] ]] && die "Only EAPI 7 and 8 are supported"
inherit linux-info toolchain-funcs inherit linux-info toolchain-funcs
@ -36,7 +18,7 @@ SRC_URI=""
IUSE="" IUSE=""
BDEPEND="dev-util/pahole" BDEPEND="dev-util/pahole"
DEPEND="=sys-kernel/coreos-sources-${COREOS_SOURCE_VERSION}" DEPEND="=sys-kernel/coreos-sources-${PV}${COREOS_SOURCE_REVISION}"
# Do not analyze or strip installed files # Do not analyze or strip installed files
RESTRICT="binchecks strip" RESTRICT="binchecks strip"
@ -44,10 +26,8 @@ RESTRICT="binchecks strip"
# The build tools are OK and shouldn't trip up multilib-strict. # The build tools are OK and shouldn't trip up multilib-strict.
QA_MULTILIB_PATHS="usr/lib/modules/.*/build/scripts/kconfig/.*" QA_MULTILIB_PATHS="usr/lib/modules/.*/build/scripts/kconfig/.*"
# Use source installed by coreos-sources # Force linux-info to detect version-matched source installed by coreos-sources
# KERNEL_DIR must find the kernel source tree under /usr/src/linux-*-coreos, KERNEL_DIR="${ESYSROOT}/usr/src/linux-${PV/_rc/-rc}-coreos${COREOS_SOURCE_REVISION}"
# not /usr/src/linux-*-flatcar, which does not exist at all.
KERNEL_DIR="${SYSROOT}/usr/src/${COREOS_KERNEL_SOURCE_NAME}"
# Search for an apropriate config in ${FILESDIR}. The config should reflect # Search for an apropriate config in ${FILESDIR}. The config should reflect
# the kernel version but partial matching is allowed if the config is # the kernel version but partial matching is allowed if the config is
@ -117,7 +97,7 @@ kmake() {
if gcc-specs-pie; then if gcc-specs-pie; then
kernel_cflags="-nopie -fstack-check=no ${kernel_cflags}" kernel_cflags="-nopie -fstack-check=no ${kernel_cflags}"
fi fi
emake "--directory=${KERNEL_DIR}" \ emake "--directory=${KV_DIR}" \
ARCH="${kernel_arch}" \ ARCH="${kernel_arch}" \
CROSS_COMPILE="${CHOST}-" \ CROSS_COMPILE="${CHOST}-" \
KBUILD_OUTPUT="${S}/build" \ KBUILD_OUTPUT="${S}/build" \
@ -219,9 +199,9 @@ setup_keys() {
coreos-kernel_pkg_pretend() { coreos-kernel_pkg_pretend() {
[[ "${MERGE_TYPE}" == binary ]] && return [[ "${MERGE_TYPE}" == binary ]] && return
if [[ -f "${KERNEL_DIR}/.config" || -d "${KERNEL_DIR}/include/config" ]] if [[ -f "${KV_DIR}/.config" || -d "${KV_DIR}/include/config" ]]
then then
die "Source is not clean! Run make mrproper in ${KERNEL_DIR}" die "Source is not clean! Run make mrproper in ${KV_DIR}"
fi fi
} }
@ -229,7 +209,7 @@ coreos-kernel_pkg_setup() {
[[ "${MERGE_TYPE}" == binary ]] && return [[ "${MERGE_TYPE}" == binary ]] && return
# tc-arch-kernel requires a call to get_version from linux-info.eclass # tc-arch-kernel requires a call to get_version from linux-info.eclass
get_version || die "Failed to detect kernel version in ${KERNEL_DIR}" get_version || die "Failed to detect kernel version in ${KV_DIR}"
} }
coreos-kernel_src_unpack() { coreos-kernel_src_unpack() {

View File

@ -56,14 +56,10 @@ DEPEND="
" "
src_prepare() { src_prepare() {
# Fail early if we didn't detect the build installed by coreos-modules
[[ -n "${KV_OUT_DIR}" ]] || die "Failed to detect modules build tree"
default default
# KV_OUT_DIR points to the minimal build tree installed by coreos-modules # KV_OUT_DIR points to the minimal build tree installed by coreos-modules
# Pull in the config and public module signing key # Pull in the config and public module signing key
KV_OUT_DIR="${ESYSROOT}/lib/modules/${COREOS_SOURCE_NAME#linux-}/build"
cp -v "${KV_OUT_DIR}/.config" build/ || die cp -v "${KV_OUT_DIR}/.config" build/ || die
validate_sig_key validate_sig_key

View File

@ -51,7 +51,7 @@ src_install() {
# Replace the broken /lib/modules/${KV_FULL}/build symlink with a copy of # Replace the broken /lib/modules/${KV_FULL}/build symlink with a copy of
# the files needed to build out-of-tree modules. # the files needed to build out-of-tree modules.
rm "${ED}/usr/${build}" || die rm "${ED}/usr/${build}" || die
kmake run-command KBUILD_RUN_COMMAND="${KERNEL_DIR}/scripts/package/install-extmod-build ${ED}/usr/${build}" kmake run-command KBUILD_RUN_COMMAND="${KV_DIR}/scripts/package/install-extmod-build ${ED}/usr/${build}"
# Install the original config because the above doesn't. # Install the original config because the above doesn't.
insinto "/usr/${build}" insinto "/usr/${build}"

View File

@ -11,9 +11,14 @@ ETYPE="sources"
K_BASE_VER="5.15" K_BASE_VER="5.15"
inherit kernel-2 inherit kernel-2
EXTRAVERSION="-flatcar"
detect_version detect_version
# Replace the -coreos suffix with -flatcar. Don't simply reset the whole
# variable because it may have additional numbers before the suffix. This
# doesn't affect the sources directory, which is still suffixed with -coreos,
# but it does affect the Makefile that is used in the build.
EXTRAVERSION="${EXTRAVERSION/-coreos/-flatcar}"
DESCRIPTION="Full sources for the CoreOS Linux kernel" DESCRIPTION="Full sources for the CoreOS Linux kernel"
HOMEPAGE="http://www.kernel.org" HOMEPAGE="http://www.kernel.org"
if [[ "${PV%%_rc*}" != "${PV}" ]]; then if [[ "${PV%%_rc*}" != "${PV}" ]]; then