eclass/linux-info: Sync with Gentoo

It's from Gentoo commit bd03dc08515969a9ce74ca1304c8374cb7a88416.
This commit is contained in:
Krzesimir Nowak 2022-08-23 16:43:05 +02:00
parent af44411e90
commit 5a9282cce5

View File

@ -29,13 +29,22 @@
# A Couple of env vars are available to effect usage of this eclass # A Couple of env vars are available to effect usage of this eclass
# These are as follows: # These are as follows:
# @ECLASS-VARIABLE: KERNEL_DIR
# @ECLASS_VARIABLE: CHECKCONFIG_DONOTHING
# @USER_VARIABLE
# @DEFAULT_UNSET
# @DESCRIPTION:
# Do not error out in check_extra_config if CONFIG settings are not met.
# This is a user flag and should under _no circumstances_ be set in the ebuild.
: ${CHECKCONFIG_DONOTHING:=""}
# @ECLASS_VARIABLE: KERNEL_DIR
# @DESCRIPTION: # @DESCRIPTION:
# A string containing the directory of the target kernel sources. The default value is # A string containing the directory of the target kernel sources. The default value is
# "/usr/src/linux" # "/usr/src/linux"
KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}" KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
# @ECLASS-VARIABLE: CONFIG_CHECK # @ECLASS_VARIABLE: CONFIG_CHECK
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# A string containing a list of .config options to check for before # A string containing a list of .config options to check for before
@ -58,7 +67,7 @@ KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
# This is to allow usage of binary kernels, and minimal systems without kernel # This is to allow usage of binary kernels, and minimal systems without kernel
# sources. # sources.
# @ECLASS-VARIABLE: ERROR_<CFG> # @ECLASS_VARIABLE: ERROR_<CFG>
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# A string containing the error message to display when the check against CONFIG_CHECK # A string containing the error message to display when the check against CONFIG_CHECK
@ -71,7 +80,7 @@ KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
# CONFIG_CHECK="~CFG" with WARNING_<CFG>="Warning Message" calls ewarn without dieing # CONFIG_CHECK="~CFG" with WARNING_<CFG>="Warning Message" calls ewarn without dieing
# @ECLASS-VARIABLE: KBUILD_OUTPUT # @ECLASS_VARIABLE: KBUILD_OUTPUT
# @DEFAULT_UNSET # @DEFAULT_UNSET
# @DESCRIPTION: # @DESCRIPTION:
# A string passed on commandline, or set from the kernel makefile. It contains the directory # A string passed on commandline, or set from the kernel makefile. It contains the directory
@ -80,7 +89,7 @@ KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
# There are also a couple of variables which are set by this, and shouldn't be # There are also a couple of variables which are set by this, and shouldn't be
# set by hand. These are as follows: # set by hand. These are as follows:
# @ECLASS-VARIABLE: KERNEL_MAKEFILE # @ECLASS_VARIABLE: KERNEL_MAKEFILE
# @INTERNAL # @INTERNAL
# @DESCRIPTION: # @DESCRIPTION:
# According to upstream documentation, by default, when make looks for the makefile, it tries # According to upstream documentation, by default, when make looks for the makefile, it tries
@ -89,48 +98,58 @@ KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
# See https://www.gnu.org/software/make/manual/make.html # See https://www.gnu.org/software/make/manual/make.html
: ${KERNEL_MAKEFILE:=""} : ${KERNEL_MAKEFILE:=""}
# @ECLASS-VARIABLE: KV_FULL # @ECLASS_VARIABLE: KV_FULL
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# A read-only variable. It's a string containing the full kernel version. ie: 2.6.9-gentoo-johnm-r1 # A read-only variable. It's a string containing the full kernel version. ie: 2.6.9-gentoo-johnm-r1
# @ECLASS-VARIABLE: KV_MAJOR # @ECLASS_VARIABLE: KV_MAJOR
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# A read-only variable. It's an integer containing the kernel major version. ie: 2 # A read-only variable. It's an integer containing the kernel major version. ie: 2
# @ECLASS-VARIABLE: KV_MINOR # @ECLASS_VARIABLE: KV_MINOR
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# A read-only variable. It's an integer containing the kernel minor version. ie: 6 # A read-only variable. It's an integer containing the kernel minor version. ie: 6
# @ECLASS-VARIABLE: KV_PATCH # @ECLASS_VARIABLE: KV_PATCH
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# A read-only variable. It's an integer containing the kernel patch version. ie: 9 # A read-only variable. It's an integer containing the kernel patch version. ie: 9
# @ECLASS-VARIABLE: KV_EXTRA # @ECLASS_VARIABLE: KV_EXTRA
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# A read-only variable. It's a string containing the kernel EXTRAVERSION. ie: -gentoo # A read-only variable. It's a string containing the kernel EXTRAVERSION. ie: -gentoo
# @ECLASS-VARIABLE: KV_LOCAL # @ECLASS_VARIABLE: KV_LOCAL
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# A read-only variable. It's a string containing the kernel LOCALVERSION concatenation. ie: -johnm # A read-only variable. It's a string containing the kernel LOCALVERSION concatenation. ie: -johnm
# @ECLASS-VARIABLE: KV_DIR # @ECLASS_VARIABLE: KV_DIR
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# A read-only variable. It's a string containing the kernel source directory, will be null if # A read-only variable. It's a string containing the kernel source directory, will be null if
# KERNEL_DIR is invalid. # KERNEL_DIR is invalid.
# @ECLASS-VARIABLE: KV_OUT_DIR # @ECLASS_VARIABLE: KV_OUT_DIR
# @OUTPUT_VARIABLE # @OUTPUT_VARIABLE
# @DESCRIPTION: # @DESCRIPTION:
# 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
# @USER_VARIABLE
# @DEFAULT_UNSET
# @DESCRIPTION:
# Do not check for kernel sources or a running kernel version
# Main use-case is for chroots
# This is a user flag and should under _no circumstances_ be set in the ebuild.
: ${SKIP_KERNEL_CHECK:=""}
# And to ensure all the weirdness with crosscompile # And to ensure all the weirdness with crosscompile
inherit toolchain-funcs inherit toolchain-funcs
[[ ${EAPI:-0} == [0123456] ]] && inherit eapi7-ver [[ ${EAPI:-0} == [0123456] ]] && inherit eapi7-ver
@ -148,15 +167,15 @@ esac
# @DESCRIPTION: # @DESCRIPTION:
# Set the env ARCH to match what the kernel expects. # Set the env ARCH to match what the kernel expects.
set_arch_to_kernel() { export ARCH=$(tc-arch-kernel); } set_arch_to_kernel() { export ARCH=$(tc-arch-kernel); }
# @FUNCTION: set_arch_to_portage
# @DESCRIPTION:
# Set the env ARCH to match what portage expects.
set_arch_to_portage() { export ARCH=$(tc-arch); }
# qeinfo "Message" # @FUNCTION: set_arch_to_pkgmgr
# ------------------- # @DESCRIPTION:
# qeinfo is a quiet einfo call when EBUILD_PHASE # Set the env ARCH to match what the package manager expects.
# should not have visible output. set_arch_to_pkgmgr() { export ARCH=$(tc-arch); }
# @FUNCTION: qout
# @DESCRIPTION:
# 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}
@ -170,8 +189,21 @@ qout() {
[ -n "${outputmsg}" ] && ${type} "${outputmsg}" [ -n "${outputmsg}" ] && ${type} "${outputmsg}"
} }
# @FUNCTION: qeinfo
# @DESCRIPTION:
# qeinfo is a quiet einfo call when EBUILD_PHASE should not have visible output.
qeinfo() { qout einfo "${@}" ; } qeinfo() { qout einfo "${@}" ; }
# @FUNCTION: qewarn
# @DESCRIPTION:
# qewarn is a quiet ewarn call when EBUILD_PHASE
# should not have visible output.
qewarn() { qout ewarn "${@}" ; } qewarn() { qout ewarn "${@}" ; }
# @FUNCTION: qeerror
# @DESCRIPTION:
# qeerror is a quiet error call when EBUILD_PHASE
# should not have visible output.
qeerror() { qout eerror "${@}" ; } qeerror() { qout eerror "${@}" ; }
# File Functions # File Functions
@ -244,7 +276,7 @@ getfilevar_noexec() {
fi fi
} }
# @ECLASS-VARIABLE: _LINUX_CONFIG_EXISTS_DONE # @ECLASS_VARIABLE: _LINUX_CONFIG_EXISTS_DONE
# @INTERNAL # @INTERNAL
# @DESCRIPTION: # @DESCRIPTION:
# This is only set if one of the linux_config_*exists functions has been called. # This is only set if one of the linux_config_*exists functions has been called.
@ -253,6 +285,10 @@ getfilevar_noexec() {
# config is available at all. # config is available at all.
_LINUX_CONFIG_EXISTS_DONE= _LINUX_CONFIG_EXISTS_DONE=
# @FUNCTION: linux_config_qa_check
# @INTERNAL
# @DESCRIPTION:
# 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
@ -313,6 +349,9 @@ 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
if ! use kernel_linux; then if ! use kernel_linux; then
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
fi fi
@ -335,6 +374,7 @@ require_configured_kernel() {
# If linux_config_exists returns false, the results of this are UNDEFINED. You # If linux_config_exists returns false, the results of this are UNDEFINED. You
# MUST call linux_config_exists first. # MUST call linux_config_exists first.
linux_chkconfig_present() { linux_chkconfig_present() {
[[ -n ${SKIP_KERNEL_CHECK} ]] && return
linux_config_qa_check linux_chkconfig_present linux_config_qa_check linux_chkconfig_present
[[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == [my] ]] [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == [my] ]]
} }
@ -347,6 +387,7 @@ linux_chkconfig_present() {
# If linux_config_exists returns false, the results of this are UNDEFINED. You # If linux_config_exists returns false, the results of this are UNDEFINED. You
# MUST call linux_config_exists first. # MUST call linux_config_exists first.
linux_chkconfig_module() { linux_chkconfig_module() {
[[ -n ${SKIP_KERNEL_CHECK} ]] && return
linux_config_qa_check linux_chkconfig_module linux_config_qa_check linux_chkconfig_module
[[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == m ]] [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == m ]]
} }
@ -359,6 +400,7 @@ linux_chkconfig_module() {
# If linux_config_exists returns false, the results of this are UNDEFINED. You # If linux_config_exists returns false, the results of this are UNDEFINED. You
# MUST call linux_config_exists first. # MUST call linux_config_exists first.
linux_chkconfig_builtin() { linux_chkconfig_builtin() {
[[ -n ${SKIP_KERNEL_CHECK} ]] && return
linux_config_qa_check linux_chkconfig_builtin linux_config_qa_check linux_chkconfig_builtin
[[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == y ]] [[ $(getfilevar_noexec "CONFIG_$1" "$(linux_config_path)") == y ]]
} }
@ -371,6 +413,7 @@ linux_chkconfig_builtin() {
# If linux_config_exists returns false, the results of this are UNDEFINED. You # If linux_config_exists returns false, the results of this are UNDEFINED. You
# MUST call linux_config_exists first. # MUST call linux_config_exists first.
linux_chkconfig_string() { linux_chkconfig_string() {
[[ -n ${SKIP_KERNEL_CHECK} ]] && return
linux_config_qa_check linux_chkconfig_string linux_config_qa_check linux_chkconfig_string
getfilevar_noexec "CONFIG_$1" "$(linux_config_path)" getfilevar_noexec "CONFIG_$1" "$(linux_config_path)"
} }
@ -422,26 +465,9 @@ kernel_is() {
"${1:-${KV_MAJOR:-0}}.${2:-${KV_MINOR:-0}}.${3:-${KV_PATCH:-0}}" "${1:-${KV_MAJOR:-0}}.${2:-${KV_MINOR:-0}}.${3:-${KV_PATCH:-0}}"
} }
get_localversion() { # @FUNCTION: get_makefile_extract_function
local lv_list i x # @INTERNAL
# @DESCRIPTION:
local shopt_save=$(shopt -p nullglob)
shopt -s nullglob
local files=( ${1}/localversion* )
${shopt_save}
# ignore files with ~ in it.
for i in "${files[@]}"; do
[[ -n ${i//*~*} ]] && lv_list="${lv_list} ${i}"
done
for i in ${lv_list}; do
x="${x}$(<${i})"
done
x=${x/ /}
echo ${x}
}
# Check if the Makefile is valid for direct parsing. # Check if the Makefile is valid for direct parsing.
# Check status results: # Check status results:
# - PASS, use 'getfilevar' to extract values # - PASS, use 'getfilevar' to extract values
@ -450,6 +476,7 @@ get_localversion() {
# - make is not present # - make is not present
# - corruption exists in the kernel makefile # - corruption exists in the kernel makefile
get_makefile_extract_function() { get_makefile_extract_function() {
[[ -n ${SKIP_KERNEL_CHECK} ]] && return
local a='' b='' mkfunc='getfilevar' local a='' b='' mkfunc='getfilevar'
a="$(getfilevar VERSION ${KERNEL_MAKEFILE})" a="$(getfilevar VERSION ${KERNEL_MAKEFILE})"
b="$(getfilevar_noexec VERSION ${KERNEL_MAKEFILE})" b="$(getfilevar_noexec VERSION ${KERNEL_MAKEFILE})"
@ -457,7 +484,10 @@ get_makefile_extract_function() {
echo "${mkfunc}" echo "${mkfunc}"
} }
# internal variable, so we know to only print the warning once # @ECLASS_VARIABLE: get_version_warning_done
# @INTERNAL
# @DESCRIPTION:
# Internal variable, so we know to only print the warning once.
get_version_warning_done= get_version_warning_done=
# @FUNCTION: get_version # @FUNCTION: get_version
@ -477,6 +507,8 @@ get_version() {
local tmplocal local tmplocal
[[ -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
@ -685,6 +717,9 @@ check_kernel_built() {
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
require_configured_kernel require_configured_kernel
local versionh_path local versionh_path
@ -781,7 +816,7 @@ check_extra_config() {
require_configured_kernel require_configured_kernel
fi fi
einfo "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
@ -857,6 +892,7 @@ check_extra_config() {
done done
if [[ ${hard_errors_count} -gt 0 ]]; then if [[ ${hard_errors_count} -gt 0 ]]; then
eend 1
eerror "Please check to make sure these options are set correctly." eerror "Please check to make sure these options are set correctly."
eerror "Failure to do so may cause unexpected problems." eerror "Failure to do so may cause unexpected problems."
eerror "Once you have satisfied these options, please try merging" eerror "Once you have satisfied these options, please try merging"
@ -864,6 +900,7 @@ check_extra_config() {
export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}" export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
die "Incorrect kernel configuration options" die "Incorrect kernel configuration options"
elif [[ ${soft_errors_count} -gt 0 ]]; then elif [[ ${soft_errors_count} -gt 0 ]]; then
eend 1
ewarn "Please check to make sure these options are set correctly." ewarn "Please check to make sure these options are set correctly."
ewarn "Failure to do so may cause unexpected problems." ewarn "Failure to do so may cause unexpected problems."
else else
@ -872,6 +909,9 @@ check_extra_config() {
export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}" export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
} }
# @FUNCTION: check_zlibinflate
# @DESCRIPTION:
# Function to make sure a ZLIB_INFLATE configuration has the required symbols.
check_zlibinflate() { check_zlibinflate() {
if ! use kernel_linux; then if ! use kernel_linux; then
die "${FUNCNAME}() called on non-Linux system, please fix the ebuild" die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
@ -955,7 +995,7 @@ linux-info_pkg_setup() {
linux-info_get_any_version linux-info_get_any_version
[ -n "${CONFIG_CHECK}" ] && check_extra_config; [[ -n "${CONFIG_CHECK}" && -z ${CHECKCONFIG_DONOTHING} ]] && check_extra_config;
} }
# @FUNCTION: kernel_get_makefile # @FUNCTION: kernel_get_makefile