multiprocess.eclass: makeopts_{jobs,loadavg}: fix implicit handling of $MAKEOPTS...
authorMike Frysinger <vapier@gentoo.org>
Thu, 9 Feb 2017 18:15:13 +0000 (13:15 -0500)
committerMike Frysinger <vapier@gentoo.org>
Thu, 9 Feb 2017 18:16:07 +0000 (13:16 -0500)
We missed quoting on ${MAKEOPTS} to set it as the first arg which meant
we might load invalid values into the second arg which is the "infinite"
scenario.

eclass/multiprocessing.eclass
eclass/tests/multiprocessing_makeopts_jobs.sh
eclass/tests/multiprocessing_makeopts_loadavg.sh

index 67f7e2d65b42f8910405e828e2940f90353f7f7a..73d852410b91021b9fd4bd723a5ef0011cd777de 100644 (file)
@@ -96,7 +96,7 @@ get_nproc() {
 # 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}
+       [[ $# -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 \
@@ -117,7 +117,7 @@ makeopts_jobs() {
 # If no limit is specified or --load-average is used without a number, ${inf}
 # (defaults to 999) is returned.
 makeopts_loadavg() {
-       [[ $# -eq 0 ]] && set -- ${MAKEOPTS}
+       [[ $# -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 lavg=$(echo " $* " | sed -r -n \
index ef477277ab3b6e10d91a0c39e81160f45e967ce4..cc4f91b69436b4c801fcfce9865a35c6d1be9ef5 100755 (executable)
@@ -10,14 +10,20 @@ inherit multiprocessing
 test-makeopts_jobs() {
        local exp=$1; shift
        tbegin "makeopts_jobs($1${2+; inf=${2}}) == ${exp}"
-       local act=$(makeopts_jobs "$@")
-       [[ ${act} == "${exp}" ]]
-       tend $? "Got back: ${act}"
+       local indirect=$(MAKEOPTS="$*" makeopts_jobs)
+       local direct=$(makeopts_jobs "$@")
+       if [[ "${direct}" != "${indirect}" ]] ; then
+               tend 1 "Mismatch between MAKEOPTS/cli: '${indirect}' != '${direct}'"
+       else
+               [[ ${direct} == "${exp}" ]]
+               tend $? "Got back: ${act}"
+       fi
 }
 
 tests=(
        999 "-j"
        999 "--jobs"
+       999 "-j -l9"
        1 ""
        1 "-l9 -w"
        1 "-l9 -w-j4"
index 6b976beb1aef3596f5b7da4997314a9161c5b8f8..ffa679d13e29ff40de4ecbde6d411d467b9a873c 100755 (executable)
@@ -10,9 +10,14 @@ inherit multiprocessing
 test-makeopts_loadavg() {
        local exp=$1; shift
        tbegin "makeopts_loadavg($1${2+; inf=${2}}) == ${exp}"
-       local act=$(makeopts_loadavg "$@")
-       [[ ${act} == "${exp}" ]]
-       tend $? "Got back: ${act}"
+       local indirect=$(MAKEOPTS="$*" makeopts_loadavg)
+       local direct=$(makeopts_loadavg "$@")
+       if [[ "${direct}" != "${indirect}" ]] ; then
+               tend 1 "Mismatch between MAKEOPTS/cli: '${indirect}' != '${direct}'"
+       else
+               [[ ${direct} == "${exp}" ]]
+               tend $? "Got back: ${act}"
+       fi
 }
 
 tests=(