From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CB7E9138335 for ; Fri, 30 Aug 2019 21:41:31 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C291EE07FE; Fri, 30 Aug 2019 21:41:30 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A28CCE07FE for ; Fri, 30 Aug 2019 21:41:30 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 950D334A719 for ; Fri, 30 Aug 2019 21:41:29 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 6D91D77F for ; Fri, 30 Aug 2019 21:41:27 +0000 (UTC) From: "Thomas Deutschmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Thomas Deutschmann" Message-ID: <1567181318.381b319cdee541dccf0180774acb3952ee60b281.whissi@gentoo> Subject: [gentoo-commits] proj/genkernel:master commit in: / X-VCS-Repository: proj/genkernel X-VCS-Files: gen_funcs.sh X-VCS-Directories: / X-VCS-Committer: whissi X-VCS-Committer-Name: Thomas Deutschmann X-VCS-Revision: 381b319cdee541dccf0180774acb3952ee60b281 X-VCS-Branch: master Date: Fri, 30 Aug 2019 21:41:27 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 135d2222-f13f-4306-989f-77b184100a86 X-Archives-Hash: 01653999ff5f30bc38b559646e7f2492 commit: 381b319cdee541dccf0180774acb3952ee60b281 Author: Thomas Deutschmann gentoo org> AuthorDate: Fri Aug 30 16:08:38 2019 +0000 Commit: Thomas Deutschmann gentoo org> CommitDate: Fri Aug 30 16:08:38 2019 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=381b319c gen_funcs.sh: Import makeopts_jobs function from multiprocessing eclass Signed-off-by: Thomas Deutschmann gentoo.org> gen_funcs.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gen_funcs.sh b/gen_funcs.sh index 381c645..c3bcee6 100755 --- a/gen_funcs.sh +++ b/gen_funcs.sh @@ -1853,5 +1853,25 @@ make_bootdir_writable() { fi } +# @FUNCTION: makeopts_jobs +# @USAGE: [${MAKEOPTS}] [${inf:-999}] +# @DESCRIPTION: +# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number +# specified therein. Useful for running non-make tools in parallel too. +# i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the +# number as bash normalizes it to [0, 255]. If the flags haven't specified a +# -j flag, then "1" is shown as that is the default `make` uses. Since there's +# no way to represent infinity, we return ${inf} (defaults to 999) if the user +# has -j without a number. +makeopts_jobs() { + [[ $# -eq 0 ]] && set -- "${MAKEOPTS}" + # This assumes the first .* will be more greedy than the second .* + # since POSIX doesn't specify a non-greedy match (i.e. ".*?"). + local jobs=$(echo " $* " | sed -r -n \ + -e 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \ + -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p") + echo ${jobs:-1} +} + unset GK_DEFAULT_IFS declare -r GK_DEFAULT_IFS="${IFS}"