commit:     096ff8a27b1b70e1306a9522b020753ab057fb56
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Sun Sep 29 23:14:05 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Sun Sep 29 23:14:05 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=096ff8a2

gkbuild.sh: Add possibility to disable distcc usage per gkbuild

This commit will add support for custom variable

  DISABLE_DISTCC

which can be used in gkbuilds to disable distcc usage when
set to "yes".

This is needed because we don't have package.env mechanism
to disable features per package.

Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 gen_funcs.sh              | 27 +++++++++++++++++++++++++++
 worker_modules/gkbuild.sh | 28 ++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/gen_funcs.sh b/gen_funcs.sh
index 1d4a91d..cfe53b9 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -1871,6 +1871,33 @@ make_bootdir_writable() {
        fi
 }
 
+# @FUNCTION: get_nproc
+# @USAGE: [${fallback:-1}]
+# @DESCRIPTION:
+# Attempt to figure out the number of processing units available.
+# If the value can not be determined, prints the provided fallback
+# instead. If no fallback is provided, defaults to 1.
+get_nproc() {
+       local nproc
+
+       # GNU
+       if type -P nproc &>/dev/null; then
+               nproc=$(nproc)
+       fi
+
+       # fallback to python2.6+
+       # note: this may fail (raise NotImplementedError)
+       if [[ -z ${nproc} ]] && type -P python &>/dev/null; then
+               nproc=$(python -c 'import multiprocessing; 
print(multiprocessing.cpu_count());' 2>/dev/null)
+       fi
+
+       if [[ -n ${nproc} ]]; then
+               echo "${nproc}"
+       else
+               echo "${1:-1}"
+       fi
+}
+
 # @FUNCTION: makeopts_jobs
 # @USAGE: [${MAKEOPTS}] [${inf:-999}]
 # @DESCRIPTION:

diff --git a/worker_modules/gkbuild.sh b/worker_modules/gkbuild.sh
index cb2f385..2039c85 100644
--- a/worker_modules/gkbuild.sh
+++ b/worker_modules/gkbuild.sh
@@ -6,6 +6,32 @@ __module_main() {
        _gkbuild_main
 }
 
+_disable_distcc() {
+       if [[ -z "${DISABLE_DISTCC}" ]] || ! isTrue "${DISABLE_DISTCC}"
+       then
+               return
+       fi
+
+       if [[ "$(tc-getCC)" != *distcc* ]] && [[ "$(tc-getCXX)" != *distcc* ]]
+       then
+               return
+       fi
+
+       print_warning 3 "distcc usage for ${P} is known to cause problems; 
Limiting to localhost ..."
+       export DISTCC_HOSTS=localhost
+
+       # We must ensure that parallel jobs aren't set higher than
+       # available processing units which would kill the system now
+       # that we limited distcc usage to localhost
+       local MAKEOPTS_USER=$(makeopts_jobs)
+       local MAKEOPTS_MAX=$(get_nproc)
+       if [[ ${MAKEOPTS_USER} -gt ${MAKEOPTS_MAX} ]]
+       then
+               print_warning 3 "MAKEOPTS for ${P} adjusted to 
-j${MAKEOPTS_MAX} due to disabled distcc support ..."
+               export MAKEOPTS="-j${MAKEOPTS_MAX}"
+       fi
+}
+
 # Remove occurrences of strings from variable given in $1
 # Strings removed are matched as globs, so for example
 # '-O*' would remove -O1, -O2 etc.
@@ -68,6 +94,8 @@ _gkbuild_main() {
                fi
        done
 
+       _disable_distcc
+
        local current_phase=
        for current_phase in ${all_phases}
        do

Reply via email to