From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 822D71388BF for ; Fri, 8 Jan 2016 05:15:12 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 57BC621C008; Fri, 8 Jan 2016 05:15:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 751FB21C006 for ; Fri, 8 Jan 2016 05:15:02 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id B5D47340A5C for ; Fri, 8 Jan 2016 05:15:01 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4A6DEE54 for ; Fri, 8 Jan 2016 05:14:56 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <1452230076.f76b96e65d19fe90d0b8fec5b8f41f27cb2401c3.mgorny@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/, eclass/tests/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/scons-utils.eclass eclass/tests/scons-utils.sh X-VCS-Directories: eclass/ eclass/tests/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: f76b96e65d19fe90d0b8fec5b8f41f27cb2401c3 X-VCS-Branch: master Date: Fri, 8 Jan 2016 05:14:56 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 2271e5aa-d408-4e95-bc04-92e5fb236659 X-Archives-Hash: 7d07f41e289c9d651595b82247e0c929 commit: f76b96e65d19fe90d0b8fec5b8f41f27cb2401c3 Author: Michał Górny gentoo org> AuthorDate: Fri Jan 1 15:40:34 2016 +0000 Commit: Michał Górny gentoo org> CommitDate: Fri Jan 8 05:14:36 2016 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f76b96e6 scons-utils.eclass: Use nproc when --jobs is used without an argument Try to guess the number of processors when --jobs is passed without an argument. We can't use a high number equivalent to GNU make behavior (no limit) since SCons does not have an equivalent of --load-avg option. Still, this is better than assuming some random, fixed number. eclass/scons-utils.eclass | 30 ++++++++++++++++++++++++++++-- eclass/tests/scons-utils.sh | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/eclass/scons-utils.eclass b/eclass/scons-utils.eclass index 3185282..89618f9 100644 --- a/eclass/scons-utils.eclass +++ b/eclass/scons-utils.eclass @@ -149,6 +149,32 @@ escons() { return ${ret} } +# @FUNCTION: _scons_get_default_jobs +# @INTERNAL +# @DESCRIPTION: +# Output the default number of jobs, used if -j is used without +# argument. Tries to figure out the number of logical CPUs, falling +# back to hardcoded constant. +_scons_get_default_jobs() { + local nproc + + if type -P nproc &>/dev/null; then + # GNU + nproc=$(nproc) + elif type -P python &>/dev/null; then + # fallback to python2.6+ + # note: this may fail (raise NotImplementedError) + nproc=$(python -c 'import multiprocessing; print(multiprocessing.cpu_count());' 2>/dev/null) + fi + + if [[ ${nproc} ]]; then + echo $(( nproc + 1 )) + else + # random default + echo 5 + fi +} + # @FUNCTION: _scons_clean_makeopts # @INTERNAL # @USAGE: [makeflags] [...] @@ -192,7 +218,7 @@ _scons_clean_makeopts() { shift else # no value means no limit, let's pass a random int - new_makeopts+=( ${1}=5 ) + new_makeopts+=( ${1}=$(_scons_get_default_jobs) ) fi ;; # strip other long options @@ -215,7 +241,7 @@ _scons_clean_makeopts() { new_optstr+="j ${2}" shift else - new_optstr+="j 5" + new_optstr+="j $(_scons_get_default_jobs)" fi ;; # otherwise, everything after -j is treated as an arg diff --git a/eclass/tests/scons-utils.sh b/eclass/tests/scons-utils.sh index 6355c54..fcb5125 100755 --- a/eclass/tests/scons-utils.sh +++ b/eclass/tests/scons-utils.sh @@ -28,7 +28,7 @@ test-scons_clean_makeopts() { } # jobcount expected for non-specified state -jc=5 +jc=$(_scons_get_default_jobs) # failed test counter failed=0