[PATCH] multiprocessing.eclass: make loadavg regex work for float values

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] multiprocessing.eclass: make loadavg regex work for float values

Mike Gilbert-2
Bug: https://bugs.gentoo.org/630626
---
 eclass/multiprocessing.eclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass
index 50368e35ea93..029201779957 100644
--- a/eclass/multiprocessing.eclass
+++ b/eclass/multiprocessing.eclass
@@ -120,7 +120,7 @@ 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:]](-[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:]])[[:space:]]*([0-9]+(\.[0-9]+)*).*:\3:p' \
  -e "s:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:${2:-999}:p")
  # Default to ${inf} since the default is to not use a load limit.
  echo ${lavg:-${2:-999}}
--
2.14.1


Reply | Threaded
Open this post in threaded view
|

[PATCH 1/2] multiprocessing.eclass: make loadavg regex work for float values

Mike Gilbert-2
Bug: https://bugs.gentoo.org/630626
---
v2: Reject "-l 2.3.4"

 eclass/multiprocessing.eclass | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/eclass/multiprocessing.eclass b/eclass/multiprocessing.eclass
index 50368e35ea93..b6e92976f73e 100644
--- a/eclass/multiprocessing.eclass
+++ b/eclass/multiprocessing.eclass
@@ -120,7 +120,7 @@ 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:]](-[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:]])[[:space:]]*([0-9]+(\.[0-9]+)?)[[:space:]].*:\3:p' \
  -e "s:.*[[:space:]](-[a-z]*l|--(load-average|max-load))[[:space:]].*:${2:-999}:p")
  # Default to ${inf} since the default is to not use a load limit.
  echo ${lavg:-${2:-999}}
--
2.14.1


Reply | Threaded
Open this post in threaded view
|

[PATCH 2/2] multiprocessing.eclass: add tests for float values

Mike Gilbert-2
Also fix the test function to output the correct var for failures.

Bug: https://bugs.gentoo.org/630626
---
 eclass/tests/multiprocessing_makeopts_loadavg.sh | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/eclass/tests/multiprocessing_makeopts_loadavg.sh b/eclass/tests/multiprocessing_makeopts_loadavg.sh
index a03bf0ca8799..d17d7734b9f2 100755
--- a/eclass/tests/multiprocessing_makeopts_loadavg.sh
+++ b/eclass/tests/multiprocessing_makeopts_loadavg.sh
@@ -15,7 +15,7 @@ test-makeopts_loadavg() {
  tend 1 "Mismatch between MAKEOPTS/cli: '${indirect}' != '${direct}'"
  else
  [[ ${direct} == "${exp}" ]]
- tend $? "Got back: ${act}"
+ tend $? "Got back: ${direct}"
  fi
 }
 
@@ -35,6 +35,8 @@ tests=(
  999 "-kl"
  4 "-kl4"
  5 "-kl 5"
+ 2.3 "-l 2.3"
+ 999 "-l 2.3.4"
 )
 for (( i = 0; i < ${#tests[@]}; i += 2 )) ; do
  test-makeopts_loadavg "${tests[i]}" "${tests[i+1]}"
--
2.14.1