wmakeLnIncludeAll: Added -j option for parallel operation

This commit is contained in:
Henry Weller
2016-07-03 22:22:00 +01:00
parent 47b6000c36
commit 17bec8aab2

View File

@ -39,10 +39,15 @@ usage() {
while [ "$#" -ge 1 ]; do echo "$1"; shift; done while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE cat<<USAGE
Usage: $Script [dir1 .. dirN] Usage: $Script [OPTION] [dir1 .. dirN]
Find directories with a 'Make/files' that contains a 'LIB =' directive options:
and execute 'wmakeLnInclude -update' for each one -j Compile using all local cores/hyperthreads
-jN or -j N Compile using N cores/hyperthreads
-h | -help Print the usage
Find directories with a 'Make/files' that contains a 'LIB =' directive
and execute 'wmakeLnInclude -update' for each one
USAGE USAGE
exit 1 exit 1
@ -54,6 +59,7 @@ USAGE
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
findName=lnInclude findName=lnInclude
nCores=0
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
@ -61,6 +67,18 @@ do
-h | -help) # Provide immediate help -h | -help) # Provide immediate help
usage usage
;; ;;
# Parallel execution on WM_NCOMPPROCS cores
-j)
nCores=$WM_NCOMPPROCS
test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \
&& shift && nCores=$1
echo "$Script: enabled on $nCores cores"
;;
# Parallel compilation on specified number of cores
-j*)
nCores=${1#-j}
echo "$Script: enabled on $nCores cores"
;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$*'"
;; ;;
@ -68,9 +86,13 @@ do
break break
;; ;;
esac esac
shift
done done
FAIL=0
echo "$Script: starting wmakeLnInclude processes"
# Default to searching from CWD # Default to searching from CWD
[ "$#" -gt 0 ] || set -- . [ "$#" -gt 0 ] || set -- .
@ -93,7 +115,20 @@ do
then then
if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1 if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1
then then
# If running in parallel start wmakeLnInclude on nCores
# and more as the cores become free
if [ "$nCores" -gt 0 ]
then
joblist=($(jobs -p))
while (( ${#joblist[*]} > $nCores ))
do
sleep 0.01
joblist=($(jobs -p))
done
wmakeLnInclude -update $topDir &
else
wmakeLnInclude -update $topDir wmakeLnInclude -update $topDir
fi
elif [ -d "$topDir/lnInclude" ] elif [ -d "$topDir/lnInclude" ]
then then
echo "removing spurious $topDir/lnInclude" echo "removing spurious $topDir/lnInclude"
@ -103,6 +138,22 @@ do
done done
done done
# If running in parallel wait until all wmakeLnInclude jobs are complete
if [ "$nCores" -gt 0 ]
then
for job in $(jobs -p)
do
echo $job
wait $job || let "FAIL+=1"
done
if [ "$FAIL" == "0" ];
then
echo "$Script: completed wmakeLnInclude processes"
else
echo "$Script: failed ($FAIL)"
fi
fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Cleanup local variables and functions # Cleanup local variables and functions