|
5 | 5 |
|
6 | 6 | output_dir=$(mktemp -d)
|
7 | 7 | top_of_tree=$(git rev-parse --show-toplevel)
|
| 8 | +declare -a job_pids |
| 9 | + |
| 10 | +# Guess at number of CPUs (could be probed, but portable requires work). |
| 11 | +jobs_max=8 |
| 12 | + |
| 13 | +# Check bash version to see if `wait -n` is supported. This allows waiting on first of any |
| 14 | +# process specified as an argument to wait to exit rather than waiting for all the processes |
| 15 | +# specified to exit. (ie batch vs stream). |
| 16 | +bash_major=$(echo $BASH_VERSION | sed -e 's/\..*/0000/') |
| 17 | +bash_minor=$(echo $BASH_VERSION | sed -e 's/^[^.]*\.//' -e 's/\..*//') |
| 18 | +bash_linear=$(($bash_major + $bash_minor)) |
| 19 | +if [ ${bash_linear} -ge 50001 ]; then |
| 20 | + wait_args="-n" |
| 21 | +fi |
8 | 22 |
|
9 | 23 | cd "${top_of_tree}"
|
10 | 24 | for i in $(find . -name '*.h' -o -name '*.c++'); do
|
| 25 | + if [ ${#job_pids[*]} -eq ${jobs_max} ]; then |
| 26 | + # macOS inparticular is stuck on an older version of bash and does not support `wait -n` |
| 27 | + # here so child processes will run as batch waiting for all to complete there. |
| 28 | + wait ${wait_args} "${job_pids[@]}" |
| 29 | + for job_pid in "${job_pids[@]}"; do |
| 30 | + if ! kill -0 ${job_pid} 2>/dev/null ; then |
| 31 | + unset job_pids[${job_pid}] |
| 32 | + fi |
| 33 | + done |
| 34 | + fi |
11 | 35 | j=${output_dir}/$(echo $i | sed -e 's@^\./@@' -e s@/@_@g)
|
12 |
| - echo Scanning $i =\> $j |
13 |
| - clangd --check=$i 1>$j 2>&1 |
| 36 | + echo -n Scanning $i =\> $j |
| 37 | + clangd --check=$i 1>$j 2>&1 & |
| 38 | + echo " [$!]" |
| 39 | + job_pids[$!]=$! |
14 | 40 | done
|
| 41 | + |
| 42 | +echo "Checking for broken includes." |
| 43 | +grep "not found" ${output_dir}/* |
| 44 | + |
| 45 | +cat <<EOF |
| 46 | +
|
| 47 | +You may also want to inspect the output files for other issues. |
| 48 | +
|
| 49 | +Please update compile_flags.txt to resolve any issues found. |
| 50 | +EOF |
0 commit comments