Re-implement the wait $PID codepath because macos needs it.
This commit is contained in:
parent
9bca2b1515
commit
dd56ea0864
@ -6,6 +6,32 @@ source scripts/portability.sh
|
||||
|
||||
# Shell functions called by the build
|
||||
|
||||
DASHN=-n
|
||||
true & wait -n 2>/dev/null || { wait; unset DASHN; }
|
||||
ratelimit()
|
||||
{
|
||||
if [ "$#" -eq 0 ]
|
||||
then
|
||||
[ -z "$DASHN" ] && PIDS="$PIDS$! "
|
||||
[ $((++COUNT)) -lt $CPUS ] && return 0
|
||||
fi
|
||||
((--COUNT))
|
||||
if [ -n "$DASHN" ]
|
||||
then
|
||||
wait -n
|
||||
DONE=$(($DONE+$?))
|
||||
else
|
||||
# MacOS uses an ancient version of bash which hasn't got "wait -n", and
|
||||
# wait without arguments always returns 0 instead of process exit code.
|
||||
# This keeps $CPUS less busy when jobs finish out of order.
|
||||
wait ${PIDS%% *}
|
||||
DONE=$(($DONE+$?))
|
||||
PIDS=${PIDS#* }
|
||||
fi
|
||||
|
||||
return $DONE
|
||||
}
|
||||
|
||||
# Respond to V= by echoing command lines as well as running them
|
||||
do_loudly()
|
||||
{
|
||||
@ -275,16 +301,13 @@ do
|
||||
|
||||
do_loudly $BUILD -c $i -o $OUT &
|
||||
|
||||
# ratelimit to $CPUS many parallel jobs, detecting errors
|
||||
[ $((++COUNT)) -ge $CPUS ] && { wait $DASHN; DONE=$?; : $((--COUNT)); }
|
||||
[ $DONE -ne 0 ] && break
|
||||
ratelimit || break
|
||||
done
|
||||
|
||||
# wait for all background jobs, detecting errors
|
||||
while [ $((COUNT--)) -gt 0 ]
|
||||
while [ "$COUNT" -gt 0 ]
|
||||
do
|
||||
wait $DASHN;
|
||||
DONE=$((DONE+$?))
|
||||
ratelimit done
|
||||
done
|
||||
[ $DONE -ne 0 ] && exit 1
|
||||
|
||||
|
@ -41,9 +41,6 @@ fi
|
||||
# Probe number of available processors, and add one.
|
||||
: ${CPUS:=$(($(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null)+1))}
|
||||
|
||||
# Centos 7 bug workaround, EOL June 30 2024. TODO
|
||||
DASHN=-n; wait -n 2>/dev/null; [ $? -eq 2 ] && unset DASHN
|
||||
|
||||
# If the build is using gnu tools, make them behave less randomly.
|
||||
export LANG=c
|
||||
export LC_ALL=C
|
||||
|
Loading…
Reference in New Issue
Block a user