linux-info.eclass: Die in most of public-ish APIs on non-Linux
authorMichał Górny <mgorny@gentoo.org>
Thu, 8 Mar 2018 16:24:12 +0000 (17:24 +0100)
committerMichał Górny <mgorny@gentoo.org>
Mon, 9 Jul 2018 16:54:47 +0000 (18:54 +0200)
Add appropriate 'die' calls in most of the seemingly public APIs
of the eclass that could be called by ebuilds and that are going to fail
horribly when used on non-Linux systems. This means that
e.g. 'kernel_is' calls need to be explicitly guarded in ebuilds, as we
can't really reasonably return 'true' or 'false' if there is no Linux
kernel in the first place.

eclass/linux-info.eclass

index 51be89dbcf3439a08f944df4cb9360b892d9770d..2ddc9e03e8908cf5512d27050af4cb0d14eb4b60 100644 (file)
@@ -240,6 +240,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
@@ -290,6 +294,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."
@@ -369,6 +377,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
 
@@ -439,6 +451,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.
@@ -592,6 +608,10 @@ 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
@@ -631,6 +651,10 @@ 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() {
+       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"
                if ! get_running_version; then
@@ -647,6 +671,10 @@ 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
 
@@ -676,6 +704,10 @@ 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
 
@@ -832,6 +864,10 @@ 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