www-client/google-chrome-beta: automated update (84.0.4147.30)
[gentoo.git] / eclass / linux-info.eclass
index 035b722e2d6dfecef7e5f6ab522cf1ca891a01c0..405ef5571e1c917b0927b8050be0d4b303296588 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2016 Gentoo Foundation
+# Copyright 1999-2018 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 # @ECLASS: linux-info.eclass
 # KBUILD_OUTPUT is used. This should be used for referencing .config.
 
 # And to ensure all the weirdness with crosscompile
-inherit toolchain-funcs versionator
+inherit toolchain-funcs
+[[ ${EAPI:-0} == [0123456] ]] && inherit eapi7-ver
 
 EXPORT_FUNCTIONS pkg_setup
 
+IUSE="kernel_linux"
+
 # Overwritable environment Var's
 # ---------------------------------------
-KERNEL_DIR="${KERNEL_DIR:-${ROOT}usr/src/linux}"
+KERNEL_DIR="${KERNEL_DIR:-${ROOT%/}/usr/src/linux}"
 
 
 # Bug fixes
@@ -156,7 +159,7 @@ qeerror() { qout eerror "${@}" ; }
 # ---------------------------------------
 
 # @FUNCTION: getfilevar
-# @USAGE: variable configfile
+# @USAGE: <variable> <configfile>
 # @RETURN: the value of the variable
 # @DESCRIPTION:
 # It detects the value of the variable defined in the file configfile. This is
@@ -192,7 +195,7 @@ getfilevar() {
 }
 
 # @FUNCTION: getfilevar_noexec
-# @USAGE: variable configfile
+# @USAGE: <variable> <configfile>
 # @RETURN: the value of the variable
 # @DESCRIPTION:
 # It detects the value of the variable defined in the file configfile.
@@ -238,6 +241,10 @@ linux_config_qa_check() {
                ewarn "QA: You called $f before any linux_config_exists!"
                ewarn "QA: The return value of $f will NOT guaranteed later!"
        fi
+
+       if ! use kernel_linux; then
+               die "$f called on non-Linux system, please fix the ebuild"
+       fi
 }
 
 # @FUNCTION: linux_config_src_exists
@@ -246,7 +253,7 @@ linux_config_qa_check() {
 # It returns true if .config exists in a build directory otherwise false
 linux_config_src_exists() {
        export _LINUX_CONFIG_EXISTS_DONE=1
-       [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
+       use kernel_linux && [[ -n ${KV_OUT_DIR} && -s ${KV_OUT_DIR}/.config ]]
 }
 
 # @FUNCTION: linux_config_bin_exists
@@ -255,7 +262,7 @@ linux_config_src_exists() {
 # It returns true if .config exists in /proc, otherwise false
 linux_config_bin_exists() {
        export _LINUX_CONFIG_EXISTS_DONE=1
-       [[ -s /proc/config.gz ]]
+       use kernel_linux && [[ -s /proc/config.gz ]]
 }
 
 # @FUNCTION: linux_config_exists
@@ -288,6 +295,10 @@ linux_config_path() {
 # This function verifies that the current kernel is configured (it checks against the existence of .config)
 # otherwise it dies.
 require_configured_kernel() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        if ! linux_config_src_exists; then
                qeerror "Could not find a usable .config in the kernel source directory."
                qeerror "Please ensure that ${KERNEL_DIR} points to a configured set of Linux sources."
@@ -295,10 +306,11 @@ require_configured_kernel() {
                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}"
        fi
+       get_version || die "Unable to determine configured kernel version"
 }
 
 # @FUNCTION: linux_chkconfig_present
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: true or false
 # @DESCRIPTION:
 # It checks that CONFIG_<option>=y or CONFIG_<option>=m is present in the current kernel .config
@@ -310,7 +322,7 @@ linux_chkconfig_present() {
 }
 
 # @FUNCTION: linux_chkconfig_module
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: true or false
 # @DESCRIPTION:
 # It checks that CONFIG_<option>=m is present in the current kernel .config
@@ -322,7 +334,7 @@ linux_chkconfig_module() {
 }
 
 # @FUNCTION: linux_chkconfig_builtin
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: true or false
 # @DESCRIPTION:
 # It checks that CONFIG_<option>=y is present in the current kernel .config
@@ -334,7 +346,7 @@ linux_chkconfig_builtin() {
 }
 
 # @FUNCTION: linux_chkconfig_string
-# @USAGE: option
+# @USAGE: <option>
 # @RETURN: CONFIG_<option>
 # @DESCRIPTION:
 # It prints the CONFIG_<option> value of the current kernel .config (it requires a configured kernel).
@@ -349,7 +361,7 @@ linux_chkconfig_string() {
 # ---------------------------------------
 
 # @FUNCTION: kernel_is
-# @USAGE: [-lt -gt -le -ge -eq] major_number [minor_number patch_number]
+# @USAGE: [-lt -gt -le -ge -eq] <major_number> [minor_number patch_number]
 # @RETURN: true or false
 # @DESCRIPTION:
 # It returns true when the current kernel version satisfies the comparison against the passed version.
@@ -366,6 +378,10 @@ linux_chkconfig_string() {
 
 # Note: duplicated in kernel-2.eclass
 kernel_is() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need to.
        linux-info_get_any_version
 
@@ -390,8 +406,13 @@ kernel_is() {
 get_localversion() {
        local lv_list i x
 
+       local shopt_save=$(shopt -p nullglob)
+       shopt -s nullglob
+       local files=( ${1}/localversion* )
+       ${shopt_save}
+
        # ignore files with ~ in it.
-       for i in $(ls ${1}/localversion* 2>/dev/null); do
+       for i in "${files[@]}"; do
                [[ -n ${i//*~*} ]] && lv_list="${lv_list} ${i}"
        done
 
@@ -431,6 +452,10 @@ get_version_warning_done=
 # KBUILD_OUTPUT (in a decreasing priority list, we look for the env var, makefile var or the
 # symlink /lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build).
 get_version() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        local tmplocal
 
        # no need to execute this twice assuming KV_FULL is populated.
@@ -523,20 +548,6 @@ get_version() {
                return 1
        fi
 
-       # 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.
-       # This *WILL* break if the user is using localversions, but we assume it was
-       # caught before this if they are.
-       if [[ -z ${OUTPUT_DIR} ]] ; then
-               # Try to locate a kernel that is most relevant for us.
-               for OUTPUT_DIR in "${SYSROOT}" "${ROOT}" "" ; do
-                       OUTPUT_DIR+="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}/build"
-                       if [[ -e ${OUTPUT_DIR} ]] ; then
-                               break
-                       fi
-               done
-       fi
-
        [ -d "${OUTPUT_DIR}" ] && KV_OUT_DIR="${OUTPUT_DIR}"
        if [ -n "${KV_OUT_DIR}" ];
        then
@@ -570,6 +581,20 @@ get_version() {
                KV_LOCAL=$tmplocal
        fi
 
+       # 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.
+       # This *WILL* break if the user is using localversions, but we assume it was
+       # caught before this if they are.
+       if [[ -z ${OUTPUT_DIR} ]] ; then
+               # Try to locate a kernel that is most relevant for us.
+               for OUTPUT_DIR in "${SYSROOT}" "${ROOT%/}" "" ; do
+                       OUTPUT_DIR+="/lib/modules/${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}/build"
+                       if [[ -e ${OUTPUT_DIR} ]] ; then
+                               break
+                       fi
+               done
+       fi
+
        # And we should set KV_FULL to the full expanded version
        KV_FULL="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}${KV_EXTRA}${KV_LOCAL}"
 
@@ -584,21 +609,25 @@ get_version() {
 # It gets the version of the current running kernel and the result is the same as get_version() if the
 # function can find the sources.
 get_running_version() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        KV_FULL=$(uname -r)
 
-       if [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
-               KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
-               KBUILD_OUTPUT=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
+       if [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile && -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
+               KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
+               KBUILD_OUTPUT=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
                unset KV_FULL
                get_version
                return $?
-       elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/source/Makefile ]]; then
-               KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/source)
+       elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/source/Makefile ]]; then
+               KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/source)
                unset KV_FULL
                get_version
                return $?
-       elif [[ -f ${ROOT}/lib/modules/${KV_FULL}/build/Makefile ]]; then
-               KERNEL_DIR=$(readlink -f ${ROOT}/lib/modules/${KV_FULL}/build)
+       elif [[ -f ${ROOT%/}/lib/modules/${KV_FULL}/build/Makefile ]]; then
+               KERNEL_DIR=$(readlink -f ${ROOT%/}/lib/modules/${KV_FULL}/build)
                unset KV_FULL
                get_version
                return $?
@@ -606,9 +635,9 @@ get_running_version() {
                # This handles a variety of weird kernel versions.  Make sure to update
                # tests/linux-info_get_running_version.sh if you want to change this.
                local kv_full=${KV_FULL//[-+_]*}
-               KV_MAJOR=$(get_version_component_range 1 ${kv_full})
-               KV_MINOR=$(get_version_component_range 2 ${kv_full})
-               KV_PATCH=$(get_version_component_range 3 ${kv_full})
+               KV_MAJOR=$(ver_cut 1 ${kv_full})
+               KV_MINOR=$(ver_cut 2 ${kv_full})
+               KV_PATCH=$(ver_cut 3 ${kv_full})
                KV_EXTRA="${KV_FULL#${KV_MAJOR}.${KV_MINOR}${KV_PATCH:+.${KV_PATCH}}}"
                : ${KV_PATCH:=0}
        fi
@@ -623,10 +652,15 @@ get_running_version() {
 # This attempts to find the version of the sources, and otherwise falls back to
 # the version of the running kernel.
 linux-info_get_any_version() {
-       get_version
-       if [[ $? -ne 0 ]]; then
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
+       if ! get_version; then
                ewarn "Unable to calculate Linux Kernel version for build, attempting to use running version"
-               get_running_version
+               if ! get_running_version; then
+                       die "Unable to determine any Linux Kernel version, please report a bug"
+               fi
        fi
 }
 
@@ -638,9 +672,12 @@ linux-info_get_any_version() {
 # @DESCRIPTION:
 # This function verifies that the current kernel sources have been already prepared otherwise it dies.
 check_kernel_built() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need to
        require_configured_kernel
-       get_version
 
        local versionh_path
        if kernel_is -ge 3 7; then
@@ -668,9 +705,12 @@ check_kernel_built() {
 # @DESCRIPTION:
 # This function verifies that the current kernel support modules (it checks CONFIG_MODULES=y) otherwise it dies.
 check_modules_supported() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need too.
        require_configured_kernel
-       get_version
 
        if ! linux_chkconfig_builtin "MODULES"; then
                eerror "These sources do not support loading external modules."
@@ -683,8 +723,10 @@ check_modules_supported() {
 # @FUNCTION: check_extra_config
 # @DESCRIPTION:
 # It checks the kernel config options specified by CONFIG_CHECK. It dies only when a required config option (i.e.
-# the prefix ~ is not used) doesn't satisfy the directive.
+# the prefix ~ is not used) doesn't satisfy the directive. Ignored on non-Linux systems.
 check_extra_config() {
+       use kernel_linux || return
+
        local config negate die error reworkmodulenames
        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
@@ -771,7 +813,7 @@ check_extra_config() {
                        linux_chkconfig_present ${config} || error=1
                fi
 
-               if [[ ${error} > 0 ]]; then
+               if [[ ${error} -gt 0 ]]; then
                        local report_func="eerror" local_error
                        local_error="ERROR_${config}"
                        local_error="${!local_error}"
@@ -806,14 +848,14 @@ check_extra_config() {
                fi
        done
 
-       if [[ ${hard_errors_count} > 0 ]]; then
+       if [[ ${hard_errors_count} -gt 0 ]]; then
                eerror "Please check to make sure these options are set correctly."
                eerror "Failure to do so may cause unexpected problems."
                eerror "Once you have satisfied these options, please try merging"
                eerror "this package again."
                export LINUX_CONFIG_EXISTS_DONE="${old_LINUX_CONFIG_EXISTS_DONE}"
                die "Incorrect kernel configuration options"
-       elif [[ ${soft_errors_count} > 0 ]]; then
+       elif [[ ${soft_errors_count} -gt 0 ]]; then
                ewarn "Please check to make sure these options are set correctly."
                ewarn "Failure to do so may cause unexpected problems."
        else
@@ -823,9 +865,12 @@ check_extra_config() {
 }
 
 check_zlibinflate() {
+       if ! use kernel_linux; then
+               die "${FUNCNAME}() called on non-Linux system, please fix the ebuild"
+       fi
+
        # if we haven't determined the version yet, we need to
        require_configured_kernel
-       get_version
 
        # although I restructured this code - I really really really dont support it!
 
@@ -843,13 +888,11 @@ check_zlibinflate() {
 
        ebegin "checking ZLIB_INFLATE"
        linux_chkconfig_builtin CONFIG_ZLIB_INFLATE
-       eend $?
-       [ "$?" != 0 ] && die
+       eend $? || die
 
        ebegin "checking ZLIB_DEFLATE"
        linux_chkconfig_builtin CONFIG_ZLIB_DEFLATE
-       eend $?
-       [ "$?" != 0 ] && die
+       eend $? || die
 
        local LINENO_START
        local LINENO_END
@@ -900,6 +943,8 @@ check_zlibinflate() {
 # Force a get_version() call when inherited from linux-mod.eclass and then check if the kernel is configured
 # to support the options specified in CONFIG_CHECK (if not null)
 linux-info_pkg_setup() {
+       use kernel_linux || return
+
        linux-info_get_any_version
 
        if kernel_is 2 4; then
@@ -914,7 +959,6 @@ linux-info_pkg_setup() {
                        ewarn "Also be aware that bugreports about gcc-4 not working"
                        ewarn "with linux-2.4 based ebuilds will be closed as INVALID!"
                        echo
-                       epause 10
                fi
        fi