eclass/linux-info: Sync with Gentoo

It's from Gentoo commit 917d3e5c87b8e6bd1a197d450b6e0304e4e75bf2.
This commit is contained in:
Flatcar Buildbot 2023-01-02 07:56:24 +00:00 committed by Krzesimir Nowak
parent 0fb8d40580
commit 05331e71db

View File

@ -140,13 +140,12 @@ KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
# A read-only variable. It's a string containing the kernel object directory, will be KV_DIR unless # A read-only variable. It's a string containing the kernel object directory, will be KV_DIR unless
# KBUILD_OUTPUT is used. This should be used for referencing .config. # KBUILD_OUTPUT is used. This should be used for referencing .config.
# @ECLASS_VARIABLE: SKIP_KERNEL_CHECK # @ECLASS_VARIABLE: SKIP_KERNEL_CHECK
# @USER_VARIABLE # @USER_VARIABLE
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# Do not check for kernel sources or a running kernel version # Do not check for kernel sources or a running kernel version.
# Main use-case is for chroots # Main use-case is for chroots.
# This is a user flag and should under _no circumstances_ be set in the ebuild. # This is a user flag and should under _no circumstances_ be set in the ebuild.
: ${SKIP_KERNEL_CHECK:=""} : ${SKIP_KERNEL_CHECK:=""}
@ -156,8 +155,7 @@ inherit toolchain-funcs
EXPORT_FUNCTIONS pkg_setup EXPORT_FUNCTIONS pkg_setup
# Bug fixes # bug #75034
# fix to bug #75034
case ${ARCH} in case ${ARCH} in
ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; ppc) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";; ppc64) BUILD_FIXES="${BUILD_FIXES} TOUT=${T}/.tmp_gas_check";;
@ -175,7 +173,7 @@ set_arch_to_pkgmgr() { export ARCH=$(tc-arch); }
# @FUNCTION: qout # @FUNCTION: qout
# @DESCRIPTION: # @DESCRIPTION:
# qout <einfo | ewarn | eerror> is a quiet call when EBUILD_PHASE should not have visible output. # qout <einfo | ewarn | eerror> is a quiet call when EBUILD_PHASE should not have visible output.
qout() { qout() {
local outputmsg type local outputmsg type
type=${1} type=${1}
@ -186,7 +184,7 @@ qout() {
clean) unset outputmsg;; clean) unset outputmsg;;
preinst) unset outputmsg;; preinst) unset outputmsg;;
esac esac
[ -n "${outputmsg}" ] && ${type} "${outputmsg}" [[ -n "${outputmsg}" ]] && ${type} "${outputmsg}"
} }
# @FUNCTION: qeinfo # @FUNCTION: qeinfo
@ -196,14 +194,12 @@ qeinfo() { qout einfo "${@}" ; }
# @FUNCTION: qewarn # @FUNCTION: qewarn
# @DESCRIPTION: # @DESCRIPTION:
# qewarn is a quiet ewarn call when EBUILD_PHASE # qewarn is a quiet ewarn call when EBUILD_PHASE should not have visible output.
# should not have visible output.
qewarn() { qout ewarn "${@}" ; } qewarn() { qout ewarn "${@}" ; }
# @FUNCTION: qeerror # @FUNCTION: qeerror
# @DESCRIPTION: # @DESCRIPTION:
# qeerror is a quiet error call when EBUILD_PHASE # qeerror is a quiet error call when EBUILD_PHASE should not have visible output.
# should not have visible output.
qeerror() { qout eerror "${@}" ; } qeerror() { qout eerror "${@}" ; }
# File Functions # File Functions
@ -213,18 +209,17 @@ qeerror() { qout eerror "${@}" ; }
# @USAGE: <variable> <configfile> # @USAGE: <variable> <configfile>
# @RETURN: the value of the variable # @RETURN: the value of the variable
# @DESCRIPTION: # @DESCRIPTION:
# It detects the value of the variable defined in the file configfile. This is # It detects the value of the variable defined in the file 'configfile'. This is
# done by including the configfile, and printing the variable with Make. # done by including the 'configfile', and printing the variable with Make.
# It WILL break if your makefile has missing dependencies! # It WILL break if your makefile has missing dependencies!
getfilevar() { getfilevar() {
local ERROR basefname basedname myARCH="${ARCH}" local ERROR basefname basedname myARCH="${ARCH}"
ERROR=0 ERROR=0
[ -z "${1}" ] && ERROR=1 [[ -z "${1}" ]] && ERROR=1
[ ! -f "${2}" ] && ERROR=1 [[ ! -f "${2}" ]] && ERROR=1
if [ "${ERROR}" = 1 ] if [[ "${ERROR}" = 1 ]]; then
then
echo -e "\n" echo -e "\n"
eerror "getfilevar requires 2 variables, with the second a valid file." eerror "getfilevar requires 2 variables, with the second a valid file."
eerror " getfilevar <VARIABLE> <CONFIGFILE>" eerror " getfilevar <VARIABLE> <CONFIGFILE>"
@ -250,7 +245,7 @@ getfilevar() {
# @USAGE: <variable> <configfile> # @USAGE: <variable> <configfile>
# @RETURN: the value of the variable # @RETURN: the value of the variable
# @DESCRIPTION: # @DESCRIPTION:
# It detects the value of the variable defined in the file configfile. # It detects the value of the variable defined in the file 'configfile'.
# This is done with sed matching an expression only. If the variable is defined, # This is done with sed matching an expression only. If the variable is defined,
# you will run into problems. See getfilevar for those cases. # you will run into problems. See getfilevar for those cases.
getfilevar_noexec() { getfilevar_noexec() {
@ -258,12 +253,11 @@ getfilevar_noexec() {
ERROR=0 ERROR=0
mycat='cat' mycat='cat'
[ -z "${1}" ] && ERROR=1 [[ -z "${1}" ]] && ERROR=1
[ ! -f "${2}" ] && ERROR=1 [[ ! -f "${2}" ]] && ERROR=1
[ "${2%.gz}" != "${2}" ] && mycat='zcat' [[ "${2%.gz}" != "${2}" ]] && mycat='zcat'
if [ "${ERROR}" = 1 ] if [[ "${ERROR}" = 1 ]]; then
then
echo -e "\n" echo -e "\n"
eerror "getfilevar_noexec requires 2 variables, with the second a valid file." eerror "getfilevar_noexec requires 2 variables, with the second a valid file."
eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>" eerror " getfilevar_noexec <VARIABLE> <CONFIGFILE>"
@ -293,7 +287,8 @@ _LINUX_CONFIG_EXISTS_DONE=
# Helper funciton which returns an error before the function argument is run if no config exists # Helper funciton which returns an error before the function argument is run if no config exists
linux_config_qa_check() { linux_config_qa_check() {
local f="$1" local f="$1"
if [ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]; then
if [[ -z "${_LINUX_CONFIG_EXISTS_DONE}" ]]; then
ewarn "QA: You called $f before any linux_config_exists!" ewarn "QA: You called $f before any linux_config_exists!"
ewarn "QA: The return value of $f will NOT guaranteed later!" ewarn "QA: The return value of $f will NOT guaranteed later!"
fi fi
@ -351,7 +346,6 @@ linux_config_path() {
# This function verifies that the current kernel is configured (it checks against the existence of .config) # This function verifies that the current kernel is configured (it checks against the existence of .config)
# otherwise it dies. # otherwise it dies.
require_configured_kernel() { require_configured_kernel() {
[[ -n ${SKIP_KERNEL_CHECK} ]] && return [[ -n ${SKIP_KERNEL_CHECK} ]] && return
if ! use kernel_linux; then if ! use kernel_linux; then
@ -365,6 +359,7 @@ require_configured_kernel() {
qeerror "it points to the necessary object directory so that it might find .config." qeerror "it points to the necessary object directory so that it might find .config."
die "Kernel not configured; no .config found in ${KV_OUT_DIR}" die "Kernel not configured; no .config found in ${KV_OUT_DIR}"
fi fi
get_version || die "Unable to determine configured kernel version" get_version || die "Unable to determine configured kernel version"
} }
@ -445,7 +440,7 @@ kernel_is() {
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
fi fi
# if we haven't determined the version yet, we need to. # If we haven't determined the version yet, we need to.
linux-info_get_any_version linux-info_get_any_version
# Now we can continue # Now we can continue
@ -459,7 +454,7 @@ kernel_is() {
eq) operator="-eq"; shift;; eq) operator="-eq"; shift;;
*) operator="-eq";; *) operator="-eq";;
esac esac
[[ $# -gt 3 ]] && die "Error in kernel-2_kernel_is(): too many parameters" [[ $# -gt 3 ]] && die "Error in ${ECLASS}_${FUNCNAME}(): too many parameters"
ver_test \ ver_test \
"${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \ "${KV_MAJOR:-0}.${KV_MINOR:-0}.${KV_PATCH:-0}" \
@ -511,26 +506,25 @@ get_version() {
[[ -n ${SKIP_KERNEL_CHECK} ]] && return [[ -n ${SKIP_KERNEL_CHECK} ]] && return
# no need to execute this twice assuming KV_FULL is populated. # No need to execute this twice assuming KV_FULL is populated.
# we can force by unsetting KV_FULL # We can force by unsetting KV_FULL.
[ -n "${KV_FULL}" ] && return 0 [[ -n "${KV_FULL}" ]] && return 0
# if we dont know KV_FULL, then we need too. # If we don't know KV_FULL, then we need to.
# make sure KV_DIR isnt set since we need to work it out via KERNEL_DIR # Make sure KV_DIR isn't set since we need to work it out via KERNEL_DIR.
unset KV_DIR unset KV_DIR
# KV_DIR will contain the full path to the sources directory we should use # KV_DIR will contain the full path to the sources directory we should use
[ -z "${get_version_warning_done}" ] && \ [[ -z "${get_version_warning_done}" ]] && \
qeinfo "Determining the location of the kernel source code" qeinfo "Determining the location of the kernel source code"
[ -d "${KERNEL_DIR}" ] && KV_DIR="${KERNEL_DIR}" [[ -d "${KERNEL_DIR}" ]] && KV_DIR="${KERNEL_DIR}"
if [ -z "${KV_DIR}" ] if [[ -z "${KV_DIR}" ]]; then
then if [[ -z "${get_version_warning_done}" ]]; then
if [ -z "${get_version_warning_done}" ]; then
get_version_warning_done=1 get_version_warning_done=1
qewarn "Unable to find kernel sources at ${KERNEL_DIR}" qewarn "Unable to find kernel sources at ${KERNEL_DIR}"
#qeinfo "This package requires Linux sources." #qeinfo "This package requires Linux sources."
if [ "${KERNEL_DIR}" == "/usr/src/linux" ] ; then if [[ "${KERNEL_DIR}" == "/usr/src/linux" ]] ; then
qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, " qeinfo "Please make sure that ${KERNEL_DIR} points at your running kernel, "
qeinfo "(or the kernel you wish to build against)." qeinfo "(or the kernel you wish to build against)."
qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location" qeinfo "Alternatively, set the KERNEL_DIR environment variable to the kernel sources location"
@ -542,22 +536,21 @@ get_version() {
fi fi
# See if the kernel dir is actually an output dir. #454294 # See if the kernel dir is actually an output dir. #454294
if [ -z "${KBUILD_OUTPUT}" -a -L "${KERNEL_DIR}/source" ]; then if [[ -z "${KBUILD_OUTPUT}" && -L "${KERNEL_DIR}/source" ]]; then
KBUILD_OUTPUT=${KERNEL_DIR} KBUILD_OUTPUT=${KERNEL_DIR}
KERNEL_DIR=$(readlink -f "${KERNEL_DIR}/source") KERNEL_DIR=$(readlink -f "${KERNEL_DIR}/source")
KV_DIR=${KERNEL_DIR} KV_DIR=${KERNEL_DIR}
fi fi
if [ -z "${get_version_warning_done}" ]; then if [[ -z "${get_version_warning_done}" ]]; then
qeinfo "Found kernel source directory:" qeinfo "Found kernel source directory:"
qeinfo " ${KV_DIR}" qeinfo " ${KV_DIR}"
fi fi
kernel_get_makefile kernel_get_makefile
if [[ ! -s ${KERNEL_MAKEFILE} ]] if [[ ! -s ${KERNEL_MAKEFILE} ]]; then
then if [[ -z "${get_version_warning_done}" ]]; then
if [ -z "${get_version_warning_done}" ]; then
get_version_warning_done=1 get_version_warning_done=1
qeerror "Could not find a Makefile in the kernel source directory." qeerror "Could not find a Makefile in the kernel source directory."
qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources" qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources"
@ -567,8 +560,9 @@ get_version() {
# OK so now we know our sources directory, but they might be using # OK so now we know our sources directory, but they might be using
# KBUILD_OUTPUT, and we need this for .config and localversions-* # KBUILD_OUTPUT, and we need this for .config and localversions-*
# so we better find it eh? # so we better find it, eh?
# do we pass KBUILD_OUTPUT on the CLI? #
# Do we pass KBUILD_OUTPUT on the CLI?
local OUTPUT_DIR=${KBUILD_OUTPUT} local OUTPUT_DIR=${KBUILD_OUTPUT}
if [[ -z ${OUTPUT_DIR} ]]; then if [[ -z ${OUTPUT_DIR} ]]; then
@ -579,7 +573,7 @@ get_version() {
OUTPUT_DIR=$(${mkfunc} KBUILD_OUTPUT "${KERNEL_MAKEFILE}") OUTPUT_DIR=$(${mkfunc} KBUILD_OUTPUT "${KERNEL_MAKEFILE}")
fi fi
# And contrary to existing functions I feel we shouldn't trust the # And contrary to existing functions, I feel we shouldn't trust the
# directory name to find version information as this seems insane. # directory name to find version information as this seems insane.
# So we parse ${KERNEL_MAKEFILE}. # So we parse ${KERNEL_MAKEFILE}.
KV_MAJOR=$(getfilevar VERSION "${KERNEL_MAKEFILE}") KV_MAJOR=$(getfilevar VERSION "${KERNEL_MAKEFILE}")
@ -587,9 +581,8 @@ get_version() {
KV_PATCH=$(getfilevar SUBLEVEL "${KERNEL_MAKEFILE}") KV_PATCH=$(getfilevar SUBLEVEL "${KERNEL_MAKEFILE}")
KV_EXTRA=$(getfilevar EXTRAVERSION "${KERNEL_MAKEFILE}") KV_EXTRA=$(getfilevar EXTRAVERSION "${KERNEL_MAKEFILE}")
if [ -z "${KV_MAJOR}" -o -z "${KV_MINOR}" -o -z "${KV_PATCH}" ] if [[ -z "${KV_MAJOR}" || -z "${KV_MINOR}" || -z "${KV_PATCH}" ]]; then
then if [[ -z "${get_version_warning_done}" ]]; then
if [ -z "${get_version_warning_done}" ]; then
get_version_warning_done=1 get_version_warning_done=1
qeerror "Could not detect kernel version." qeerror "Could not detect kernel version."
qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources." qeerror "Please ensure that ${KERNEL_DIR} points to a complete set of Linux sources."
@ -597,9 +590,8 @@ get_version() {
return 1 return 1
fi fi
[ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}" [[ -d "${OUTPUT_DIR}" ]] && KV_OUT_DIR="${OUTPUT_DIR}"
if [ -n "${KV_OUT_DIR}" ]; if [[ -n "${KV_OUT_DIR}" ]]; then
then
qeinfo "Found kernel object directory:" qeinfo "Found kernel object directory:"
qeinfo " ${KV_OUT_DIR}" qeinfo " ${KV_OUT_DIR}"
fi fi
@ -609,9 +601,9 @@ get_version() {
# Grab the kernel release from the output directory. # Grab the kernel release from the output directory.
# TODO: we MUST detect kernel.release being out of date, and 'return 1' from # TODO: we MUST detect kernel.release being out of date, and 'return 1' from
# this function. # this function.
if [ -s "${KV_OUT_DIR}"/include/config/kernel.release ]; then if [[ -s "${KV_OUT_DIR}"/include/config/kernel.release ]]; then
KV_LOCAL=$(<"${KV_OUT_DIR}"/include/config/kernel.release) KV_LOCAL=$(<"${KV_OUT_DIR}"/include/config/kernel.release)
elif [ -s "${KV_OUT_DIR}"/.kernelrelease ]; then elif [[ -s "${KV_OUT_DIR}"/.kernelrelease ]]; then
KV_LOCAL=$(<"${KV_OUT_DIR}"/.kernelrelease) KV_LOCAL=$(<"${KV_OUT_DIR}"/.kernelrelease)
else else
KV_LOCAL= KV_LOCAL=
@ -624,13 +616,13 @@ get_version() {
# Clear out KV_LOCAL in that case. # Clear out KV_LOCAL in that case.
# TODO: this does not detect a change in the localversion part between # TODO: this does not detect a change in the localversion part between
# kernel.release and the value that would be generated. # kernel.release and the value that would be generated.
if [ "$KV_LOCAL" = "$tmplocal" ]; then if [[ "${KV_LOCAL}" = "${tmplocal}" ]]; then
KV_LOCAL= KV_LOCAL=
else else
KV_LOCAL=$tmplocal KV_LOCAL=${tmplocal}
fi fi
# and in newer versions we can also pull LOCALVERSION if it is set. # and in newer versions, we can also pull LOCALVERSION if it is set.
# but before we do this, we need to find if we use a different object directory. # but before we do this, we need to find if we use a different object directory.
# This *WILL* break if the user is using localversions, but we assume it was # This *WILL* break if the user is using localversions, but we assume it was
# caught before this if they are. # caught before this if they are.
@ -718,7 +710,7 @@ check_kernel_built() {
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
fi fi
# if we haven't determined the version yet, we need to # If we haven't determined the version yet, we need to
[[ -n ${SKIP_KERNEL_CHECK} ]] && return [[ -n ${SKIP_KERNEL_CHECK} ]] && return
@ -731,8 +723,7 @@ check_kernel_built() {
versionh_path="include/linux/version.h" versionh_path="include/linux/version.h"
fi fi
if [ ! -f "${KV_OUT_DIR}/${versionh_path}" ] if [[ ! -f "${KV_OUT_DIR}/${versionh_path}" ]]; then
then
eerror "These sources have not yet been prepared." eerror "These sources have not yet been prepared."
eerror "We cannot build against an unprepared tree." eerror "We cannot build against an unprepared tree."
eerror "To resolve this, please type the following:" eerror "To resolve this, please type the following:"
@ -754,7 +745,7 @@ check_modules_supported() {
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
fi fi
# if we haven't determined the version yet, we need too. # If we haven't determined the version yet, we need to.
require_configured_kernel require_configured_kernel
if ! linux_chkconfig_builtin "MODULES"; then if ! linux_chkconfig_builtin "MODULES"; then
@ -774,12 +765,12 @@ check_extra_config() {
local config negate die error reworkmodulenames local config negate die error reworkmodulenames
local soft_errors_count=0 hard_errors_count=0 config_required=0 local soft_errors_count=0 hard_errors_count=0 config_required=0
# store the value of the QA check, because otherwise we won't catch usages # Store the value of the QA check, because otherwise we won't catch usages
# after if check_extra_config is called AND other direct calls are done # after if check_extra_config is called AND other direct calls are done
# later. # later.
local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}" local old_LINUX_CONFIG_EXISTS_DONE="${_LINUX_CONFIG_EXISTS_DONE}"
# if we haven't determined the version yet, we need to # If we haven't determined the version yet, we need to.
linux-info_get_any_version linux-info_get_any_version
# Determine if we really need a .config. The only time when we don't need # Determine if we really need a .config. The only time when we don't need
@ -820,9 +811,8 @@ check_extra_config() {
ebegin "Checking for suitable kernel configuration options" ebegin "Checking for suitable kernel configuration options"
for config in ${CONFIG_CHECK} for config in ${CONFIG_CHECK}; do
do # If we specify any fatal, ensure we honor them
# if we specify any fatal, ensure we honor them
die=1 die=1
error=0 error=0
negate=0 negate=0
@ -919,7 +909,7 @@ check_zlibinflate() {
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
fi fi
# if we haven't determined the version yet, we need to # If we haven't determined the version yet, we need to.
require_configured_kernel require_configured_kernel
# although I restructured this code - I really really really dont support it! # although I restructured this code - I really really really dont support it!
@ -951,15 +941,15 @@ check_zlibinflate() {
LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)" LINENO_END="$(grep -n 'CONFIG_ZLIB_INFLATE y' ${KV_DIR}/lib/Config.in | cut -d : -f 1)"
LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)" LINENO_START="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | grep -n 'if \[' | tail -n 1 | cut -d : -f 1)"
(( LINENO_AMOUNT = $LINENO_END - $LINENO_START )) (( LINENO_AMOUNT = ${LINENO_END} - ${LINENO_START} ))
(( LINENO_END = $LINENO_END - 1 )) (( LINENO_END = ${LINENO_END} - 1 ))
SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')" SYMBOLS="$(head -n $LINENO_END ${KV_DIR}/lib/Config.in | tail -n $LINENO_AMOUNT | sed -e 's/^.*\(CONFIG_[^\" ]*\).*/\1/g;')"
# okay, now we have a list of symbols # okay, now we have a list of symbols
# we need to check each one in turn, to see whether it is set or not # we need to check each one in turn, to see whether it is set or not
for x in $SYMBOLS ; do for x in ${SYMBOLS} ; do
if [ "${!x}" = "y" ]; then if [[ "${!x}" = "y" ]]; then
# we have a winner! # We have a winner!
einfo "${x} ensures zlib is linked into your kernel - excellent" einfo "${x} ensures zlib is linked into your kernel - excellent"
return 0 return 0
fi fi
@ -974,7 +964,7 @@ check_zlibinflate() {
eerror "Please ensure that you enable at least one of these options:" eerror "Please ensure that you enable at least one of these options:"
eerror eerror
for x in $SYMBOLS ; do for x in ${SYMBOLS} ; do
eerror " * $x" eerror " * $x"
done done
@ -997,7 +987,7 @@ linux-info_pkg_setup() {
linux-info_get_any_version linux-info_get_any_version
[[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config; [[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config
} }
# @FUNCTION: kernel_get_makefile # @FUNCTION: kernel_get_makefile