Skip to content

Commit

Permalink
multiprocessing.eclass: Fix handling multiple short options (e.g. -kj)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mgorny committed Dec 18, 2016
1 parent ca375fd commit 639d76a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions eclass/multiprocessing.eclass
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand All @@ -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}
}
Expand Down
3 changes: 3 additions & 0 deletions eclass/tests/multiprocessing_makeopts_jobs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand Down
3 changes: 3 additions & 0 deletions eclass/tests/multiprocessing_makeopts_loadavg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
Expand Down

0 comments on commit 639d76a

Please sign in to comment.