summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2012-05-11 14:22:01 +0000
committerMike Frysinger <vapier@gentoo.org>2012-05-11 14:22:01 +0000
commitd97797f4878b3c10a19228c91123abbde4b27fbe (patch)
tree141cecf681c844b9d794a3049f069359aadfa819 /eclass
parentRevert homepage (it is back to original now) (diff)
downloadgentoo-2-d97797f4878b3c10a19228c91123abbde4b27fbe.tar.gz
gentoo-2-d97797f4878b3c10a19228c91123abbde4b27fbe.tar.bz2
gentoo-2-d97797f4878b3c10a19228c91123abbde4b27fbe.zip
support extended makeflag syntax and not just -j#
Diffstat (limited to 'eclass')
-rw-r--r--eclass/eutils.eclass15
-rwxr-xr-xeclass/tests/eutils:makeopts_jobs.sh36
2 files changed, 46 insertions, 5 deletions
diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index ea8448717476..c88ef3541d2a 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -1,6 +1,6 @@
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.391 2012/04/20 19:35:37 vapier Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.392 2012/05/11 14:22:01 vapier Exp $
# @ECLASS: eutils.eclass
# @MAINTAINER:
@@ -1314,14 +1314,19 @@ usex() { use "$1" && echo "${2-yes}$4" || echo "${3-no}$5" ; } #382963
# @USAGE: [${MAKEOPTS}]
# @DESCRIPTION:
# Searches the arguments (defaults to ${MAKEOPTS}) and extracts the jobs number
-# specified therein. i.e. if the user has MAKEOPTS=-j9, this will show "9".
+# specified therein. Useful for running non-make tools in parallel too.
+# i.e. if the user has MAKEOPTS=-j9, this will show "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. Useful for running non-make tools in parallel too.
+# uses. Since there's no way to represent infinity, we return 999 if the user
+# has -j without a number.
makeopts_jobs() {
[[ $# -eq 0 ]] && set -- ${MAKEOPTS}
- local x jobs
- for x ; do [[ ${x} == -j* ]] && jobs=${x#-j} ; done
+ # 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:]](-j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \
+ -e 's:.*[[:space:]](-j|--jobs)[[:space:]].*:999:p')
echo ${jobs:-1}
}
diff --git a/eclass/tests/eutils:makeopts_jobs.sh b/eclass/tests/eutils:makeopts_jobs.sh
new file mode 100755
index 000000000000..bd9f696cc91a
--- /dev/null
+++ b/eclass/tests/eutils:makeopts_jobs.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+
+source tests-common.sh
+
+inherit eutils
+
+test-makeopts_jobs() {
+ local exp=$1; shift
+ tbegin "makeopts_jobs($*) == ${exp}"
+ local act=$(makeopts_jobs "$@")
+ [[ ${act} == "${exp}" ]]
+ tend $? "Got back: ${act}"
+}
+
+tests=(
+ 999 "-j"
+ 999 "--jobs"
+ 1 ""
+ 1 "-l9 -w"
+ 1 "-l9 -w-j4"
+ 1 "-l9--jobs=3"
+ 1 "-l9--jobs=8"
+ 2 "-j2"
+ 3 "-j 3"
+ 4 "-l3 -j 4 -w"
+ 5 "--jobs=5"
+ 6 "--jobs 6"
+ 7 "-l3 --jobs 7 -w"
+ 4 "-j1 -j 2 --jobs 3 --jobs=4"
+ 8 " -j 8 "
+)
+for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do
+ test-makeopts_jobs "${tests[i]}" "${tests[i+1]}"
+done
+
+texit