Skip to content
File

Blob: tools/unix/clangd-check.sh

bash51 lines
1#!/bin/bash
2 
3# A script to scans workerd sources with clangd to look for issues
4# that make affect language services.
5 
6output_dir=$(mktemp -d)
7top_of_tree=$(git rev-parse --show-toplevel)
8declare -a job_pids
9 
10# Guess at number of CPUs (could be probed, but portable requires work).
11jobs_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).
16bash_major=$(echo $BASH_VERSION | sed -e 's/\..*/0000/')
17bash_minor=$(echo $BASH_VERSION | sed -e 's/^[^.]*\.//' -e 's/\..*//')
18bash_linear=$(($bash_major + $bash_minor))
19if [ ${bash_linear} -ge 50001 ]; then
20 wait_args="-n"
21fi
22 
23cd "${top_of_tree}"
24for 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
35 j=${output_dir}/$(echo $i | sed -e 's@^\./@@' -e s@/@_@g)
36 echo -n Scanning $i =\> $j
37 clangd --check=$i 1>$j 2>&1 &
38 echo " [$!]"
39 job_pids[$!]=$!
40done
41 
42echo "Checking for broken includes."
43grep "not found" ${output_dir}/*
44 
45cat <<EOF
46
47You may also want to inspect the output files for other issues.
48
49Please update compile_flags.txt to resolve any issues found.
50EOF