eclass/multiprocessing: Sync with Gentoo

It's from Gentoo commit a00223eb88742885325b8863ba080e7d94202d8f.
This commit is contained in:
Krzesimir Nowak 2022-03-22 15:24:54 +01:00
parent 34d8a39a01
commit 02bcf326ab

View File

@ -1,15 +1,13 @@
# Copyright 1999-2021 Gentoo Authors # Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
# Flatcar: Support EAPI 0 and 4.
# @ECLASS: multiprocessing.eclass # @ECLASS: multiprocessing.eclass
# @MAINTAINER: # @MAINTAINER:
# base-system@gentoo.org # base-system@gentoo.org
# @AUTHOR: # @AUTHOR:
# Brian Harring <ferringb@gentoo.org> # Brian Harring <ferringb@gentoo.org>
# Mike Frysinger <vapier@gentoo.org> # Mike Frysinger <vapier@gentoo.org>
# @SUPPORTED_EAPIS: 0 4 5 6 7 8 # @SUPPORTED_EAPIS: 5 6 7 8
# @BLURB: multiprocessing helper functions # @BLURB: multiprocessing helper functions
# @DESCRIPTION: # @DESCRIPTION:
# The multiprocessing eclass contains a suite of utility functions # The multiprocessing eclass contains a suite of utility functions
@ -27,7 +25,7 @@
# @CODE # @CODE
case ${EAPI:-0} in case ${EAPI:-0} in
[045678]) ;; [5678]) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac esac
@ -67,22 +65,21 @@ get_nproc() {
} }
# @FUNCTION: makeopts_jobs # @FUNCTION: makeopts_jobs
# @USAGE: [${MAKEOPTS}] [${inf:-999}] # @USAGE: [${MAKEOPTS}] [${inf:-$(( $(get_nproc) + 1 ))}]
# @DESCRIPTION: # @DESCRIPTION:
# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number # Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number
# specified therein. Useful for running non-make tools in parallel too. # 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 # 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 # 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 # -j flag, then "1" is shown as that is the default `make` uses. If the flags
# no way to represent infinity, we return ${inf} (defaults to 999) if the user # specify -j without a number, ${inf} is returned (defaults to nproc).
# has -j without a number.
makeopts_jobs() { makeopts_jobs() {
[[ $# -eq 0 ]] && set -- "${MAKEOPTS}" [[ $# -eq 0 ]] && set -- "${MAKEOPTS}"
# This assumes the first .* will be more greedy than the second .* # This assumes the first .* will be more greedy than the second .*
# since POSIX doesn't specify a non-greedy match (i.e. ".*?"). # since POSIX doesn't specify a non-greedy match (i.e. ".*?").
local jobs=$(echo " $* " | sed -r -n \ 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:]])[[:space:]]*([0-9]+).*:\2:p' \
-e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-999}:p") -e "s:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:${2:-$(( $(get_nproc) + 1 ))}:p")
echo ${jobs:-1} echo ${jobs:-1}
} }