Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/genkernel:master commit in: /
Date: Fri, 30 Aug 2019 21:41:31
Message-Id: 1567181318.381b319cdee541dccf0180774acb3952ee60b281.whissi@gentoo
1 commit: 381b319cdee541dccf0180774acb3952ee60b281
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Fri Aug 30 16:08:38 2019 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Fri Aug 30 16:08:38 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=381b319c
7
8 gen_funcs.sh: Import makeopts_jobs function from multiprocessing eclass
9
10 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>
11
12 gen_funcs.sh | 20 ++++++++++++++++++++
13 1 file changed, 20 insertions(+)
14
15 diff --git a/gen_funcs.sh b/gen_funcs.sh
16 index 381c645..c3bcee6 100755
17 --- a/gen_funcs.sh
18 +++ b/gen_funcs.sh
19 @@ -1853,5 +1853,25 @@ make_bootdir_writable() {
20 fi
21 }
22
23 +# @FUNCTION: makeopts_jobs
24 +# @USAGE: [${MAKEOPTS}] [${inf:-999}]
25 +# @DESCRIPTION:
26 +# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number
27 +# specified therein. Useful for running non-make tools in parallel too.
28 +# i.e. if the user has MAKEOPTS=-j9, this will echo "9" -- we can't return the
29 +# number as bash normalizes it to [0, 255]. If the flags haven't specified a
30 +# -j flag, then "1" is shown as that is the default `make` uses. Since there's
31 +# no way to represent infinity, we return ${inf} (defaults to 999) if the user
32 +# has -j without a number.
33 +makeopts_jobs() {
34 + [[ $# -eq 0 ]] && set -- "${MAKEOPTS}"
35 + # This assumes the first .* will be more greedy than the second .*
36 + # since POSIX doesn't specify a non-greedy match (i.e. ".*?").
37 + local jobs=$(echo " $* " | sed -r -n \
38 + -e 's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \
39 + -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p")
40 + echo ${jobs:-1}
41 +}
42 +
43 unset GK_DEFAULT_IFS
44 declare -r GK_DEFAULT_IFS="${IFS}"