commit: 381b319cdee541dccf0180774acb3952ee60b281 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> AuthorDate: Fri Aug 30 16:08:38 2019 +0000 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> 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 <whissi <AT> 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}"