Improve the regular expressions to handle parameters consisting of
multiple short options (such as -kj). It should be noted that the code
is not perfect but should handle all common (valid) cases; it could e.g.
incorrectly process a short option followed by string arg such as
'-Wfoo.j' although having this in MAKEOPTS is extremely unlikely.
---
 eclass/multiprocessing.eclass                    | 8 ++++----
 eclass/tests/multiprocessing_makeopts_jobs.sh    | 3 +++
 eclass/tests/multiprocessing_makeopts_loadavg.sh | 3 +++
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass
index 06e004aa1669..5a5fe9acb56a 100644
--- a/eclass/multiprocessing.eclass
+++ b/eclass/multiprocessing.eclass
@@ -67,8 +67,8 @@ makeopts_jobs() {
        # 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')
+               -e 
's:.*[[:space:]](-[a-z]*j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p' \
+               -e 's:.*[[:space:]](-[a-z]*j|--jobs)[[:space:]].*:999:p')
        echo ${jobs:-1}
 }
 
@@ -86,8 +86,8 @@ makeopts_loadavg() {
        # 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 \
-               -e 
's:.*[[:space:]](-l|--(load-average|max-load)[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+).*:\3:p'
 \
-               -e 
's:.*[[:space:]](-l|--(load-average|max-load))[[:space:]].*:999:p')
+               -e 
's:.*[[:space:]](-[a-z]*l|--(load-average|max-load)[=[:space:]])[[:space:]]*([0-9]+|[0-9]+\.[0-9]+).*:\3:p'
 \
+               -e 
's:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:999:p')
        # Default to 999 since the default is to not use a load limit.
        echo ${lavg:-999}
 }
diff --git a/eclass/tests/multiprocessing_makeopts_jobs.sh 
b/eclass/tests/multiprocessing_makeopts_jobs.sh
index 017d491156a0..a1e43c8b91d7 100755
--- a/eclass/tests/multiprocessing_makeopts_jobs.sh
+++ b/eclass/tests/multiprocessing_makeopts_jobs.sh
@@ -31,6 +31,9 @@ tests=(
        7 "-l3 --jobs 7 -w"
        4 "-j1 -j 2 --jobs 3 --jobs=4"
        8 "     -j                              8     "
+       999 "-kj"
+       4 "-kj4"
+       5 "-kj 5"
 )
 for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do
        test-makeopts_jobs "${tests[i]}" "${tests[i+1]}"
diff --git a/eclass/tests/multiprocessing_makeopts_loadavg.sh 
b/eclass/tests/multiprocessing_makeopts_loadavg.sh
index 12f9d01f9fcd..276b7e70d393 100755
--- a/eclass/tests/multiprocessing_makeopts_loadavg.sh
+++ b/eclass/tests/multiprocessing_makeopts_loadavg.sh
@@ -28,6 +28,9 @@ tests=(
        4 "-j1 -j 2 --load-average 3 --load-average=4"
        3 " --max-load=3 -x"
        8 "     -l                              8     "
+       999 "-kl"
+       4 "-kl4"
+       5 "-kl 5"
 )
 for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do
        test-makeopts_loadavg "${tests[i]}" "${tests[i+1]}"
-- 
2.11.0


Reply via email to